c - Usart interrupt registeration -
i using at32uc series (custom board) application , usart rs485 interrupts killing me today. have rx interrupt set , working. trying add tx interrupt called if data available send. problem tx interrupt never called. after few hours fighting i've found strange.
int main() .....// other initialisations intc_init_interrupts(); intc_register_interrupt(&timerinterrupt, avr32_tc_irq0, avr32_intc_int0); intc_register_interrupt(&rs485txinterrupt, avr32_usart2_irq, avr32_intc_int1); intc_register_interrupt(&rs485rxinterrupt, avr32_usart2_irq, avr32_intc_int0); enable_global_interrupt();
from above, rx interrupt working , if change order of intc rx interrupt tx interrupt, tx interrupt working , no rx interrupt. function calling each interrupts in main. can explain wrong understanding in implementing interrupts. i've attached snippets of relevant codes further reference.
static void sendtx(void) { txlength = 5; gpio_set_pin_high(avr32_pin_pa10); txbuf[0] = ateaddress; avr32_usart2.thr.txchr = txbuf[0]; tx_outctr = 1; if(peaksrdy_flag == true) { txbuf[1] = peaks[loop][0]; txempty_flag = false; avr32_usart2.ier = avr32_usart_ier_txrdy_mask; } } __attribute__((__interrupt__)) static void rs485txinterrupt(void) { //avr32_usart2.idr.txrdy = 1; avr32_usart2.thr.txchr = txbuf[1]; avr32_usart2.cr.sttbrk = 1; gpio_set_pin_low(avr32_pin_pa10); gpio_set_pin_low(avr32_pin_pa06); if(!txempty_flag) { //gpio_set_pin_high(avr32_pin_pa06); //avr32_usart2.imr.txrdy; } } static void readrx(void) { avr32_usart2.cr.txdis = 1; avr32_usart2.ier = avr32_usart_ier_rxrdy_mask; } __attribute__((__interrupt__)) static void rs485rxinterrupt(void) { //avr32_usart2.idr.rxrdy = 1; uint32_t data; static char rxdatalength = 98; data = avr32_usart2.rhr.rxchr; if(data & 0x00000100) { if((data & 0x000000ff) == 0x92) //dsp board address = 0x92 { rxbuf[0] = data; addr_flag = true; rxinctr = 1; } else { addr_flag = false; return; } } else if (addr_flag == true) { rxbuf[rxinctr++] = data; if(rxinctr == 2) // command check { if(data < 0x80) { addr_flag = false; // reset addr flag if(data==0x10)//start { start_flag = true; } else if(data == 0x11) //cancel { gpio_set_pin_high(avr32_pin_pa13); break_flag = true; } } else if(data >= 0x80) rxdatalength = 3; } if ((rxinctr == rxdatalength) || ((rxdatalength == 98) && (rxinctr == rxbuf[2]+1))) { //gpio_set_pin_high (avr32_pin_pa16); addr_flag = false; start_flag = true; } } gpio_set_pin_low(avr32_pin_pa13); }
thanks in advance!
you registering 2 different routines same interrupt (avr32_usart2_irq
), second registration overwrites first one.
notice there's one irq/isr both rx , tx in at32uc , you'll have determine 1 occurred in isr, see e.g. http://www.avrfreaks.net/forum/how-distinguish-usart-interrupts-txrdy-rxrdy.
Comments
Post a Comment