cancel
Showing results for 
Search instead for 
Did you mean: 

USART3 interrupts - stm32f4xx

spyguy99
Associate II
Posted on June 04, 2012 at 05:32

Anyone have any example code for USART Interrupts? I've tried finding some example code to work off of. 

7 REPLIES 7
Posted on June 04, 2012 at 05:58

Anyone have any example code for USART Interrupts? I've tried finding some example code to work off of.

STM32F4xx_DSP_StdPeriph_Lib_V1.0.0\Project\STM32F4xx_StdPeriph_Examples\USART\HyperTerminal_Interrupt

Not USART3, but should be instructive.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
spyguy99
Associate II
Posted on June 04, 2012 at 17:43

Thanks, that looks like what I need!

spyguy99
Associate II
Posted on June 05, 2012 at 04:37

So I've managed to get the interrupt triggering properly on serial data. My problem now is Figuring out how to reset the interrupt. I've tried using

USART_ClearITPendingBit and USART_ClearFlag on the RXNE bit, What seems to happen is anytime I trigger the interrupt more than 2 times in quick 

succession

, while the interrupt code is still running, everything just stops. And I'm not quite sure why. 

Posted on June 05, 2012 at 05:17

Reading the data register (USART3->DR) should be sufficient to clear the interrupt at it's source.

A hazard with the NVIC/peripherals is that if you clear the interrupt immediately before exiting the service routine can cause a re-entry due to a combination of slow clearing, pipelining, and tail-chaining.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
spyguy99
Associate II
Posted on June 05, 2012 at 05:58

Are you saying I should just throw in some USART_RecieveData(USART3) commands at the end of the interrupt code? This is my current code. What its supposed to do is take the custom packet I've created and put it into an array I can refer to in other code. What else do I need to change?

void USARTx_IRQHANDLER(void)
{
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET && USART_ReceiveData(USART3) == 0x12){ //Begin packet
uint8_t Data;
int count=0;
while(Data != 0x13){ //End packet
Data =USART_ReceiveData(USART3);
vec[count] = Data;
count++;
}
USART_ClearFlag(USART3, USART_IT_RXNE);
}
}

Posted on June 05, 2012 at 15:56

This isn't going to work like this under interrupt. You can't keep using USART_ReceiveData() like this, you need to RXNE to be asserted for each byte. Unless you re-implement this as a state machine you may as well just using polling mode.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
spyguy99
Associate II
Posted on June 05, 2012 at 16:18

I realize its not ideal but it was just something I was trying to test with last night. What I would really like is to implement DMA but I don't know if I can figure that out. I've been looking through the USART DataExchangeDMA code and I should be able to get things written into memory fine, but then I don't know how to get things out of memory to be used.