2012-06-03 08:32 PM
Anyone have any example code for USART Interrupts? I've tried finding some example code to work off of.
2012-06-03 08:58 PM
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.2012-06-04 08:43 AM
Thanks, that looks like what I need!
2012-06-04 07:37 PM
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.
2012-06-04 08:17 PM
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.2012-06-04 08:58 PM
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);
}
}
2012-06-05 06:56 AM
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.
2012-06-05 07:18 AM
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.