LPUART acts strange with StopMode - STM32L081KZT6
Hello,
I am using a STM32L081KZT6. My code sends a Message via LPUART every second and receives an input over the same LPUART from the user. The RTC is used for the timing with LSE. To save power, I go into sleep mode between sending and receiving. The sleep function is called like this:
void schlafen_wenn_nichts_zu_tun(void)
{
if (!TESTBIT(1, m1_rs232_aktiv)) {
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
}
}The sending is done with Interupt and works fine:
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart == &hlpuart1)
{
idlemode_tx = IDLE_NACHLAUF_TX;
if(TESTBIT(1, m1_rs232_aktiv))
{
if (rs232_outbuf_index < rs232_outbuf[0])
{
rs232_outbuf_index++;
HAL_UART_Transmit_IT(&hlpuart1,&rs232_outbuf[rs232_outbuf_index], 1);
}
else
{
HAL_UART_AbortTransmit_IT(&hlpuart1);
CLRBIT(1, m1_rs232_aktiv);
memset(&rs232_outbuf, 0, sizeof(rs232_outbuf));
}
}
}
}The receive also works fine:
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
unsigned char zeichen;
if (huart == &hlpuart1)
{
if(!TESTBIT(1, m1_rs232_aktiv))
{
SETBIT(1, m1_rs232_aktiv);
}
if ((rs232_inbuf_index < RS232_INBUF_LEN))
{
if(!TESTBIT(1, m1_rs232_aktiv))
{
SETBIT(1, m1_rs232_aktiv);
}
zeichen = rs232_inbuf[rs232_inbuf_index];
}
if(zeichen != LF){
HAL_UART_Receive_IT(&hlpuart1, &rs232_inbuf[rs232_inbuf_index+1], 1);
rs232_inbuf_index++;
}
else{
CLRBIT(1, m1_rs232_aktiv);
}
}The Problem starts when I use STOPMode (HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI)) instead of SLEEPMode. The transmit still works as its supposed to, but the Receive function doesn't. I lose the first 1-2 bytes of the message and the next 3-4 bytes are flawed. For example, I send the message "44 45 56 3F 5F 58 32 45 44 34 0D 0A" and the receive reads "5A 36 7A 61 32 45 44 34 0D 0A".
Can anyone tell me why the STOPMode flaws my HAL_UART_Receive_IT ?
Thanks for help