2015-11-04 10:42 AM
Hi to all,
I am encountering a problem using USART1 interrupt.
I can correctly send data on tx line and I woul like to use interrupt to receive data from rx line. I enabled RXNEIE bit in CR1 and created the handler extern ''C'' void USART1_IRQHandler() // I am using C++ { myled.LedOn(LED4); Delay(1000); myled.LedOff(LED4); return; } but nothing happened. Do I have to enable something else? Thank you Freya2015-11-04 11:03 AM
Do I have to enable something else?
The NVIC?You also need to actually clear the source of the interrupt otherwise it will keep re-entering. I don't like the delays, but you might want one after both LED changes, otherwise the re-entry will just glitch it.2015-11-04 12:52 PM
What baudrate and which board? USART1 is a bit wonky on a few of them.
May wanna try a different USART.2015-11-08 11:46 PM
Indeed it is not my goal to switch a led on in the interrupt routine, it was only a test to check if I entered in the toutine.
What I need is, every time a new charcater arrives, catch it and put it in an buffer for futher elaboration. More or less the routine is like this: ===================================================== extern ''C'' void USART1_IRQHandler() { myusart.PrintString((uint8_t *) ''\n\nUSART INTERRUPT\n'', 0); // I am entering in the routine if(USART1->ISR & USART_ISR_RXNE) { if(iocnt < 500) { if(c != '\n') { iobuf[iocnt++] = c; iobuf[iocnt] = 0; } else { iobuf[iocnt] = 0; // redundant instruction iocnt = 0; } } } // USART1->RQR |= 0x00000008; USART1->ICR = 0x00020A5F; return; } ===================================================== Enabling NVIC interrupt is working, but still I encounter some problems: - Interrupt bit should clear when I read ISR register, but it doesn't - Interrupt bit should clear when I set RXRFQ bit in RQR register, but it doesn't The only way I found to clear interrupt is to set bits in ICR register and, furthermore, only the first carachter of input string is read. Do I have to increase sysclock frequency? (it is sysclock = 8 MHz and baud rate = 115200) Thank you Freya2015-11-09 05:15 AM
Interrupt bit should clear when I read ISR register, but it doesn't
Are you sure, most STM32 this only occurs if you read the DR or RDR Using printf in an interrupt is likely to block for several hundred thousand cycles.2015-11-12 11:16 PM
Hi to all,
I didn't inhibit overrun interrupt and that caused the infinite loop. Then I slowed baud rate down to 19200 and deleted all debug lines (that is a lot of printf()) and now it works both on USART1 and USART2. Thank you very much Freya