RS485 Interrupt on atmega88

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
dalahooel
Posts: 1
Joined: 15 Mar 2021 12:09

RS485 Interrupt on atmega88

#1 Post by dalahooel » 15 Mar 2021 12:25

Hi
I use RS485 library with atmega8 and it's work well. now i change my micro to atmega88 but Interrupt not work. Do you know what is the problem?

Code: Select all

int address = 102;
char dat[9];             // buffer for receving/sending messages
int num = 1;
int flag = 0;
int color = 1;
int rc1=0;
int gc1=0;
int bc1=0;
int rc2=0;
int gc2=0;
int bc2=0;


sbit  rs485_rxtx_pin  at PORTD2_bit;         // set transcieve pin
sbit  rs485_rxtx_pin_direction at DDD2_bit;  // set transcieve pin direction

void interrupt()org IVT_ADDR_USART__RX
{
  RS485Slave_Receive(dat);
}

void Init()
{
     UART1_Init(4800);                  // initialize UART1 module
     Delay_ms(100);
     RS485Slave_Init(address);          // Intialize MCU as slave, address 160

     dat[1] = 0;
     dat[2] = 0;
     dat[3] = 0;
     dat[4] = 0;
     dat[5] = 0;
     dat[6] = 0;

     SREG_I_bit = 1;                    // enable global interrupt
     RXCIE0_bit  = 1;                   // enable interrupt on UARTs receive
     

     DDD3_bit = 1;
     DDD5_bit = 1;
     DDD6_bit = 1;
     DDB1_bit = 1;
     DDB2_bit = 1;
     DDB3_bit = 1;

     DDD0_bit=0;

     PWM16bit_Init(_PWM16_FAST_MODE_9BIT, _PWM16_PRESCALER_16bit_1, _PWM16_NON_INVERTED, 255, 1);
     PWM1_Init(_PWM1_FAST_MODE, _PWM1_PRESCALER_1, _PWM1_NON_INVERTED, 255);
     PWM2_Init(_PWM2_FAST_MODE, _PWM2_PRESCALER_1, _PWM2_NON_INVERTED, 255);
}

void SetColor()
{
     PWM16bit_Change_Duty(gc1*2, _TIMER1_CH_A);   //g1
     PWM16bit_Change_Duty(rc2*2, _TIMER1_CH_B);  //r2
     PWM1A_Set_Duty(bc1);                       //b1
     PWM1B_Set_Duty(rc1);                      //r1
     PWM2A_Set_Duty(bc2);                     //b2
     PWM2B_Set_Duty(gc2);                    //g2
}

void main() {
 Init();

while (1) {

    if (dat[5])
    {                   // if an error detected, signal it by
      dat[5] = 0;
    }
    if (dat[4])
    {                    // upon completed valid message receive
      dat[4] = 0;                    //   data[4] is set to 0xFF
      
      rc1=rc2=dat[0];
      gc1=gc2=dat[1];
      bc1=bc2=dat[2];
      
      SetColor();
    }   
  }
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: RS485 Interrupt on atmega88

#2 Post by filip » 19 Mar 2021 08:18

Hi,

Have you been able to sort out this issue ?

Regards,
Filip.

Post Reply

Return to “mikroC PRO for AVR General”