AnsweredAssumed Answered

Beekit Kinetis uart.c error

Question asked by John Russell on May 13, 2015
Latest reply on May 14, 2015 by John Russell

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

Outcomes