1

I am currently working on RS485 usart interrupts on AT32UCB1258 custom board and struggling with txempty interrupt. Basically, I want to disable tx after 5 bytes have been sent. My rx interrupt (receive command from master board) and tx ready interrupts are firing correctly, however, tx empty interrupt is not firing at all. I am checking channel status register to distinguish which interrupt to be fired in the USART2 interrupt handler. Any help is greatly appreciated. Thanks in advance!

//***********************USART INT HANDLER***************************************
__attribute__((__interrupt__)) static void rs485Interrupt(void)
{   
     if(AVR32_USART2.CSR.rxrdy)
     {  
         gpio_set_pin_low(AVR32_PIN_PA08);
         AVR32_USART2.IDR.txrdy = 1;
         AVR32_USART2.IDR.txempty = 1;
         rs485RxInterrupt();
     }
     else if(AVR32_USART2.CSR.txrdy)
     {  
         AVR32_USART2.IDR.rxrdy = 1;
         AVR32_USART2.IDR.txempty = 1;
         rs485TxInterrupt();
     }
     else if(AVR32_USART2.CSR.txempty)
     {
         gpio_set_pin_low(AVR32_PIN_PA06);
         rs485TxEmpty();
     }
}
 //**********************************************************************************

 // this function is in main, and calls txrdy interrupt if data is available to send
 static void rs485_write(void)
 {
     gpio_set_pin_high(AVR32_PIN_PA10);
     txBuf[0] = ATEAddress;
     AVR32_USART2.THR.txchr = txBuf[0];
     tx_outctr = 1;
     txLength = 5;
     //txempty_flag = false;

     txBuf[1] = peaks[loop][0];
     txBuf[2] = peaks[loop][1];
     txBuf[3] = peaks[loop][2];
     txBuf[4] = peaks[loop][3];
     AVR32_USART2.IER.txrdy = 1;
 }


 //************************TX INTERRUPT ROUTINE******************************************
 static void rs485TxInterrupt(void)
 {  
     //gpio_set_pin_low(AVR32_PIN_PA06);
     for(tx_outctr=1; tx_outctr<=5; tx_outctr++)
     {
     //AVR32_USART2.THR.txchr = 0x01;
         AVR32_USART2.THR.txchr = txBuf[tx_outctr];
         //usart_write_char(&AVR32_USART2,(int)txBuf[tx_outctr]);
         if (tx_outctr == 5)
         {   
             // if 5btyes are sent, disable tx by causing txempty interrupt
             AVR32_USART2.IDR.txrdy = 1;
             AVR32_USART2.IER.txempty = 1;
             txempty_flag = true;
         }
     }
     //gpio_set_pin_low(AVR32_PIN_PA08);
 }
 //**********************************************************************************

Currently, watching gpio_pin06 going low if there is txempty interrupt, but never going to that stage. I think usart initilisations, gpio enabling modules and interrupt registerations are correctly set since other interrupts are firing correctly.

emacs drives me nuts
  • 2,785
  • 13
  • 23
Jin
  • 119
  • 7

0 Answers0