diff --git a/subsys/modbus/mb_rtu_core.c b/subsys/modbus/mb_rtu_core.c index b7656932099..8eb6f6a9710 100644 --- a/subsys/modbus/mb_rtu_core.c +++ b/subsys/modbus/mb_rtu_core.c @@ -182,9 +182,6 @@ static int mb_rx_ascii_frame(struct mb_rtu_context *ctx) calc_lrc = mb_ascii_get_lrc(&ctx->uart_buf[1], (ctx->uart_buf_ctr - 5) / 2); - ctx->uart_buf_ctr = 0; - ctx->uart_buf_ptr = &ctx->uart_buf[0]; - if (calc_lrc != frame_lrc) { LOG_ERR("Calculated LRC does not match received LRC"); return -EIO; @@ -322,9 +319,6 @@ static int mb_rx_rtu_frame(struct mb_rtu_context *ctx) calc_crc = mb_rtu_crc16(&ctx->uart_buf[0], ctx->uart_buf_ctr - sizeof(ctx->rx_frame.crc)); - ctx->uart_buf_ctr = 0; - ctx->uart_buf_ptr = &ctx->uart_buf[0]; - if (ctx->rx_frame.crc != calc_crc) { LOG_WRN("Calculated CRC does not match received CRC"); return -EIO; @@ -473,6 +467,9 @@ static void mb_rx_handler(struct k_work *item) ctx->rx_frame_err = mb_rx_rtu_frame(ctx); } + ctx->uart_buf_ctr = 0; + ctx->uart_buf_ptr = &ctx->uart_buf[0]; + if (ctx->client == true) { k_sem_give(&ctx->client_wait_sem); } else if (IS_ENABLED(CONFIG_MODBUS_RTU_SERVER)) {