cancel
Showing results for 
Search instead for 
Did you mean: 

Change parity on UART using LL API during runtime / after init

EMela
Associate II

I need to change the UART parity from a FREERTOS task.

I also use interrupt per byte received.

Do I need to disable UART and interrupt before changing the parity?

I use LL API.

So what I do so far:

initialized_ = false; // Set initialized to false so interrupt handler will not touch flags which causes a hang
LL_USART_DisableIT_RXNE(uartHandle_); // Disable interrupt
LL_USART_Disable(uartHandle_);
auto parity = evenParity ? LL_USART_PARITY_EVEN : LL_USART_PARITY_NONE;
LL_USART_SetParity(uartHandle_, parity);
LL_USART_Enable(uartHandle_);
LL_USART_EnableIT_RXNE(uartHandle_); // Enable interrupt again
currentIndex_ = 0;
initialized_ = true;

interrupt handler:

void Process()
{
    if (!initialized_ || !LL_USART_IsActiveFlag_RXNE(uartHandle_) || !LL_USART_IsEnabledIT_RXNE(uartHandle_))
        return;
 
        // do stuff
}

Am I overdoing it ? Code docs say nothing about how to change these parameters "on the fly" after the program is initialized and running, and I can't find any documentation what it takes to make the changes go into effect in a graceful way.

Thanks! :)

1 REPLY 1

>>Am I overdoing it ?

Probably

With baud rates, etc, you just need to disable the UART (UE bit) whilst changing the settings.

However be aware of side effects. That it will change in-progress transmission/reception, and might flag errors/status that then need to be cleared, ie noise, framing, overrun, parity, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..