Moved Modbus message processing to UART ISR
This commit is contained in:
parent
7220a36fa7
commit
fcdbb63ca4
@ -231,33 +231,6 @@ int main(void)
|
||||
/* Enter the main loop */
|
||||
while (1)
|
||||
{
|
||||
/* UART RX is done */
|
||||
if (lpuart1_rx_done == 1)
|
||||
{
|
||||
/* Process the message */
|
||||
if (lpuart1_rx_message_too_long)
|
||||
{
|
||||
/* Do nothing, just delete the buffer and set the flag back to zero*/
|
||||
lpuart1_rx_message_too_long = 0;
|
||||
} else
|
||||
{
|
||||
/* Process the message:
|
||||
* message is stored in modbus_buffer[], no copying necessary;
|
||||
* but we need to make sure that modbus_buffer[] will not be used while
|
||||
* processing the message: this can be done by disabling RX interrupt */
|
||||
LL_LPUART_DisableIT_RXNE(LPUART1);
|
||||
modbus_slave_process_msg(modbus_buffer, lpuart1_rx_message_len);
|
||||
/* Reset the RX DONE flag */
|
||||
lpuart1_rx_done = 0;
|
||||
LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||
}
|
||||
/* Reset the RX DONE flag */
|
||||
lpuart1_rx_done = 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* It is time for measurement */
|
||||
if (tim21_elapsed_period == 1)
|
||||
{
|
||||
|
@ -45,8 +45,6 @@
|
||||
/* USER CODE BEGIN PV */
|
||||
uint16_t lpuart1_rx_message_index = 0;
|
||||
uint16_t lpuart1_rx_message_len = 0;
|
||||
uint8_t lpuart1_rx_done = 0;
|
||||
uint8_t lpuart1_rx_message_too_long = 0;
|
||||
|
||||
uint8_t tim21_elapsed_period = 0;
|
||||
/* USER CODE END PV */
|
||||
@ -166,19 +164,16 @@ void TIM21_IRQHandler(void)
|
||||
*/
|
||||
void LPUART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN LPUART1_IRQn 0 */
|
||||
|
||||
|
||||
/* USER CODE BEGIN LPUART1_IRQn 0 */
|
||||
/* Check RXNE flag value in SR register */
|
||||
if(LL_LPUART_IsActiveFlag_RXNE(LPUART1) && LL_LPUART_IsEnabledIT_RXNE(LPUART1))
|
||||
{
|
||||
/* RXNE flag will be cleared by reading of DR register (done in call) */
|
||||
/* Call function in charge of handling Character reception */
|
||||
LPUART1_CharReception_Callback();
|
||||
}
|
||||
|
||||
/* USER CODE END LPUART1_IRQn 0 */
|
||||
/* USER CODE BEGIN LPUART1_IRQn 1 */
|
||||
if(LL_LPUART_IsActiveFlag_RXNE(LPUART1) && LL_LPUART_IsEnabledIT_RXNE(LPUART1))
|
||||
{
|
||||
/* RXNE flag will be cleared by reading of DR register (done in call) */
|
||||
/* Call function in charge of handling Character reception */
|
||||
LPUART1_CharReception_Callback();
|
||||
}
|
||||
/* USER CODE END LPUART1_IRQn 0 */
|
||||
/* USER CODE BEGIN LPUART1_IRQn 1 */
|
||||
/* If the IDLE flag is active */
|
||||
if (LL_LPUART_IsActiveFlag_IDLE(LPUART1) && LL_LPUART_IsEnabledIT_IDLE(LPUART1))
|
||||
{
|
||||
@ -188,11 +183,18 @@ void LPUART1_IRQHandler(void)
|
||||
/* Reset the buffer index */
|
||||
lpuart1_rx_message_len = lpuart1_rx_message_index;
|
||||
lpuart1_rx_message_index = 0;
|
||||
lpuart1_rx_done = 1;
|
||||
if (lpuart1_rx_message_len > MODBUS_MAX_RTU_FRAME_SIZE)
|
||||
{
|
||||
lpuart1_rx_message_too_long = 1;
|
||||
/* message too long, ignore */
|
||||
return;
|
||||
}
|
||||
/* Process the message:
|
||||
* message is stored in modbus_buffer[], no copying necessary;
|
||||
* but we need to make sure that modbus_buffer[] will not be used while
|
||||
* processing the message: this can be done by disabling RX interrupt */
|
||||
LL_LPUART_DisableIT_RXNE(LPUART1);
|
||||
modbus_slave_process_msg(modbus_buffer, lpuart1_rx_message_len);
|
||||
LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||
}
|
||||
/* USER CODE END LPUART1_IRQn 1 */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user