2024-05-21 10:55 PM
I am trying to implement MODBUS slave on custom board with WB55 on low power mode and need to support 9600, 19200, 57600 and 115200 baud rates.
As a first step, I tried to receive 8 bytes of MODBUS command on LPUART and send it on USART1 with HAL without low power mode and it worked as expected on all baud rates.
As next step, I had added Low power mode (STOP2) implementation code from LPM utilities without enabling the WPAN module. I see that the bytes are received as junk with all baud rates. Thinking about the generic implementation in HAL and switching between the clocks from 32 MHz to 16 MHz might be the reason for overhead during wakeup. So, I had ported the STOP2 example on the custom board and this was working as expected on all baud rates.
As next step, I had improved the example to receive multiple bytes and transmit it on USART1. With 115200 baud rate bytes are being received as junk and on all other (9600, 19200 and 57600) baud rates reception was good.
ISR routine:
void LPUART1_IRQHandler(void)
{
/* USER CODE BEGIN LPUART1_IRQn 0 */
/* Check WUF flag value in ISR register */
if (LL_LPUART_IsActiveFlag_WKUP(LPUART1) && LL_LPUART_IsEnabledIT_WKUP(LPUART1))
{
mbus.IsActive = true;
/* Configure LPUART1 transfer interrupts : */
/* Disable the UART Wake UP from stop mode Interrupt */
LL_LPUART_DisableIT_WKUP(LPUART1);
/* WUF flag clearing */
LL_LPUART_ClearFlag_WKUP(LPUART1);
/* Read Received character. RXNE flag is cleared by reading of RDR register */
Mb_Rx_Buffer[mbus.ByteCount++] = LL_LPUART_ReceiveData8(LPUART1);
// HAL_GPIO_WritePin(GPIOC, MBUS_TX_EN_Pin,GPIO_PIN_SET);
// /* Echo received character on TX */
// LL_LPUART_TransmitData8(LPUART1, ubReceivedChar);
// HAL_GPIO_WritePin(GPIOC, MBUS_TX_EN_Pin,GPIO_PIN_RESET);
/* Call function in charge of handling Character reception */
// mbus_poll_Rx_Frame(ubReceivedChar);
// Mb_Rx_Buffer[mbus.ByteCount++] = ubReceivedChar;
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);
}
/* USER CODE END LPUART1_IRQn 0 */
/* USER CODE BEGIN LPUART1_IRQn 1 */
/* USER CODE END LPUART1_IRQn 1 */
}
Super loop:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(mbus.ByteCount >= 8)
{
/* Send Text Information on LPUART TX to PC Com port */
PrintInfo();
mbus.ByteCount = 0;
// mbus.IsActive = false;
}
/* Prepare LPUART for entering Stop Mode */
PrepareLPUARTToStopMode();
// if(mbus.IsActive == false)
{
/* Enter Stop 2 mode */
EnterSTOP2Mode();
}
/* At this point, MCU just wakes up from Stop 2 mode */
}
Initialization:
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LPUART1_UART_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
// Serial_Transmit((uint8_t *)"\r\n");
/* MODBUS tranceiver in RX mode */
HAL_GPIO_WritePin(GPIOC, MBUS_TX_EN_Pin,GPIO_PIN_RESET);
/* Power ON MOSFET for MODBUS */
HAL_GPIO_WritePin(GPIOB, MBUS_MOSFET_SW_Pin, GPIO_PIN_SET);
/* Configure Power IP */
Configure_PWR();
mbus.State = MBUS_STATE_IDLE;
mbus.IsActive = false;
mbus.ByteCount = 0;
Build details:
Can anyone suggest me, that something i had done wrong in this!
2024-06-14 11:42 AM
Hello @sridharstm32
Can you check whether the MCU can wake-up fast enough for the required baud rate? that may be the Cause.
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.