cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F0 hangs when using USART & interrupts

prijazendom
Associate II
Posted on October 04, 2013 at 04:46

Hi,

I'm trying t owrite robust code for USART communication with embedded modem like module. Since communication is not strict command-response manner, but module can send messages also in asynhrounous manner (sporadically). I've used USART code and added interrupts, but STM32 hangs, when USART buffer is filled up with characters from USART and buffer is read on other side from normal process that displays data on debug console...

I guess I didn't do this code properly. Anyone with some example or advice or pointer of how to do this properly ?

Thanks in advance,

Bulek.

#interrupts #usart
3 REPLIES 3
Posted on October 04, 2013 at 05:37

I posted a couple of interrupt examples here, lets start with those.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/UART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=5295]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=5295
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
prijazendom
Associate II
Posted on October 04, 2013 at 10:58 Hi, thanks for your response.I've checked the code and have pretty same code. My problems begin when I try to read from that buffer that Interrupt handler is filling in. I have embedded module that I talk to over USART (it has AT like command set). When I do this :

usart_puts(cmd);
while (1) { 
if (UartBuf.LineCnt > 0) {
cbReadLine(&UartBuf,&tmpline, UartBuf.start, USART_TMP_LINE_LEN);
UartBuf.LineCnt--;
printf (''Line:%s
'',tmpline);
}
}

UartBuf:LinCnt is increased in interrupt handler and decreased in my getline code... If code is like shown, printf stops in the middle of the line and if i stop debugging I'm always in interrupt handler and value of USART_GetITStatus(USART1, USART_IT_RXNE) is always RESET. If I add delay of 1 second after usart_puts() it works, cause after 1 second interrupt handler is almost surely not active anymore... I guess I need something more (either disable interrupts temporarily-but could loose characters, or provide some locking mechanism), but for a start need an understanding why this fails... My module can certain messages send over USART also in asynchronous way (with no AT command from my side), so solution with delay is not good, cause it will die if module sends something while I'm reading buffer... I'm desperately seeking some example that would solve problem of robust UART communication, that will never loose any characters... Thanks in advance for your help, regards, Bulek.
Posted on October 04, 2013 at 11:37

Well you don't want to be dwelling in the interrupt handler doing printf or otherwise waiting for multiple TXE. You'd want to copy outgoing data to another buffer, and serve it up a byte at a time in subsequent interrupts. If you must use printf, use the sprintf version into another buffer. Another potential issue is not having a closing NUL on C strings, this can cause a lot of problems if handling a partial byte stream.

If RXNE sticks low, you might want to check the other error status bits, this will jamb up the receiver until you read USARTx->DR to clear the error.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..