probleme with code for AVR

Status
Not open for further replies.

_SquiD_

Advanced Member level 4
Joined
Jul 30, 2008
Messages
114
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Activity points
2,035
hi there,

I want to compile this code for ATMEGA 8515 with MikroC pro for avr:

Code:
har dat[10];                          // buffer for receving/sending messages
char i,j;

sbit  rs485_rxtx_pin  at PORTD.B1;           // set transcieve pin   // PD0
sbit  rs485_rxtx_pin_direction at DDRD.B1;   // set transcieve pin direction

// Interrupt routine
void interrupt() org IVT_ADDR_USART_RXC {
  RS485Master_Receive(dat);
}

void main(){
  long cnt = 0;
  PORTA  = 0;                          // clear PORTA
  PORTB  = 0;                          // clear PORTB
  PORTC  = 0;                          // clear PORTC

  DDRA   = 0xFF;                       // set PORTA as output
  DDRB   = 0xFF;                       // set PORTB as output
  DDRC   = 0xFF;                       // set PORTB as output

  // Pass pointers to UART functions of used UART module
 UART_Wr_Ptr = UART1_Write;
 UART_Rd_Ptr = UART1_Read;
 UART_Rdy_Ptr = UART1_Data_Ready;
   UART_TX_Idle_Ptr = UART1_TX_Idle;

  UART1_Init(9600);                    // initialize UART1 module
  Delay_ms(100);

  RS485Master_Init();                  // initialize MCU as Master
  dat[0] = 0xAA;
  dat[1] = 0xF0;
  dat[2] = 0x0F;
  dat[4] = 0;                          // ensure that message received flag is 0
  dat[5] = 0;                          // ensure that error flag is 0
  dat[6] = 0;

  RS485Master_Send(dat,1,160);

  SREG_I_bit  = 1;                     // enable global interrupt
  RXCIE_bit   = 1;                     // enable interrupt on UART receive

  while (1){
                                       // upon completed valid message receiving
                                       //   data[4] is set to 255
    cnt++;
    if (dat[5])  {                     // if an error detected, signal it
      PORTC = dat[5];                  //   by setting PORTC
    }
    if (dat[4]) {                      // if message received successfully
      cnt = 0;
      dat[4] = 0;                      // clear message received flag
      j = dat[3];
      for (i = 1; i <= dat[3]; i++) {  // show data on PORTB
        PORTB = dat[i-1];
      }                                // increment received dat[0]
      dat[0] = dat[0]+1;               // send back to slave
      Delay_ms(1);
      RS485Master_Send(dat,1,160);

    }

    if (cnt > 100000) {                // if in 100000 poll-cycles the answer
      PORTA++;                         //   was not detected, signal
      cnt = 0;                         //   failure of send-message
      RS485Master_Send(dat,1,160);
      if (PORTA > 10){                 // if sending failed 10 times
        PORTA = 0;
        RS485Master_Send(dat,1,50);    //   send message on broadcast address
      }
     }
  }
}

and it gives me lots of errors which say that the compiler doesn't recognize some functions:

undeclared identifier 'RS485Master_Receive' in expression
undeclared identifier 'IVT_ADDR_USART_RXC' in expression
undeclared identifier 'UART_Wr_Ptr' in expression
....

Any idea why ? please give me some advice.

Thanks in advance,

-SQD-

Added after 1 hours 51 minutes:

I fact I observed that this example is made for ATMEGA16. What modifications does this program need to work on ATMEGA8515.

-SQD-
 

Hi,
Change some of these:
Code:
void interrupt() org IVT_ADDR_USART_RXC {
  RS485Master_Receive(dat);
}
to
Code:
void USART_Interrupt() org 0x012{
  RS485Master_Receive(dat);
}
I'm not sure but I think you should also do this:
Code:
UART_Wr_Ptr
to
Code:
UART1_Wr_Ptr
Hope it helped.
Tahmid.
 

Thanks, Tahmid ... I am a newbie in programing AVRs but I realized that I didn't include the UART and RS485 library in my project. It works now.

Can you give me some details about the connectivity between the master and the slave. What does + and - mean ?


Added after 23 minutes:

I have an EasyAVR5a development board. And I plan that the microcontroller on it, an ATMEGA8515 to play the role of the MASTER. And I have another board with another ATMEGA8515 to play the role of the SLAVE. How do I connect these two ? What do I need ? The communication between the master and the slave require two RS485 modules?

-SQD-
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…