Beekit Kinetis uart.c error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Beekit Kinetis uart.c error

966 Views
john5
Contributor I

I've been writing a function for a MK21D256 project that uses uart1 (or uart2) in two different baudrate/parity configurations.

The uart is initially configured at 38400/noparity, then later switches to 9600/evenparity. All good so far.

Then I switch back to 38400/noparity, but the baud rate is set incorrectly.

The error lies in function

UartErr_t UartSetConfig( uint8_t UartNumber,  UartConfig_t* pConfig );

in the section that calculates and sets uartregs->BDH and uartregs->BDL.

Here is the fix.

#if (1)     -

        mUartModule[UartNumber].UartRegs->BDH = (uint8_t)((mUartSBR >> 8) & gUART_BDH_MASK_c);     // this code works

        mUartModule[UartNumber].UartRegs->BDL = (uint8_t) (mUartSBR & gUART_BDL_MASK_c);               //---------------------

#else // (1)

     // when BDH is written the value is buffered and only applied when BDL is written

     // the two writes to BDH here mess that requirement up ie the 0x00 does not get written, so the previous value is not zeroed.

        mUartModule[UartNumber].UartRegs->BDH = 0x00;

        mUartModule[UartNumber].UartRegs->BDH |= (uint8_t)((mUartSBR >> 8) & gUART_BDH_MASK_c);

        mUartModule[UartNumber].UartRegs->BDL = (uint8_t) (mUartSBR & gUART_BDL_MASK_c);

#endif // (1)

That took quite a while to find - i.e. I assumed that the Freescale code was sacrosanct.

John

0 Kudos
Reply
2 Replies

854 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi John,

The original code without clear the previous value and just add the register bits, which cause the issue.

I will forward this info to related team. Thank you for the info.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

854 Views
john5
Contributor I

Hi Hui Ma,

Also, have discovered an error in uart.h relating to using 8 bit data, with parity. The error was discovered in 3.0.1 and is still in projects generated using 3.0,2 :

/* Data bits mask */

#define gUART_DATA_BITS_BIT_c (0x8u)

That should be

/* Data bits mask */

#define gUART_DATA_BITS_BIT_c (0x10u)

Thats the UARTX_C1.M bit setting, It currently incorrectly sets the UARTX_C1.WAKE bit.

John

0 Kudos
Reply