Question
Multiple USART Issue
Posted on March 29, 2013 at 09:23
Hello, I have been trying to use multiple usarts with receive on interrupts. Some part of the communication takes place between a PC Com and STM, while some communications is taking place with STM to another STM device. The setup comprises of 2 STMs and a PC.
During reception I store received data in a array. there are many functions that use this facility (Interrupt Handler for RX).void
USART1_IRQHandler (
void
) {
if
(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
if
(CYCLE_DATA_FLAG) {
CYCLE_DATA[CYCLE_RxCounter++] = USART_ReceiveData(USART1);
}
else
if
(CYCLE_NUMBER_FLAG == 1) {
CycleNumber_RxBuffer[CycleNumber_RxCounter++] = USART_ReceiveData(USART1);
}
else
{
/* Read one byte from the receive data register */
Modbus_RxBuffer[Modbus_RxCounter++] = USART_ReceiveData(USART1);
}
}
}
void
USART2_IRQHandler (
void
) {
if
(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
if
(CYCLE_NUMBER_FLAG == 1)
/* Disable the USARTz Receive interrupt */
CycleNumber_RxBuffer[CycleNumber_RxCounter++] = USART_ReceiveData(USART2);
RxBuffer[RxCounter++] = USART_ReceiveData(USART2);
}
}
void
USART3_IRQHandler (
void
) {
if
(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
CycleAccept_RxBuffer[CycleAccept_RxCounter++] = USART_ReceiveData(USART3);
if
(CycleAccept_RxCounter ==4) {
if
( (CycleAccept_RxBuffer[0] == 0x05) && (CycleAccept_RxBuffer[1] == 0x05) ) {
POSTING_FLAG = 0;
}
}
}
}
The issue is that some times the data received in this array is jumbled.
For Example if i was sent 1 4 5 6 on the usart the array would reflect data received as 5 6 1 4
Please request for more details if you cannot catch my point.