Author Topic: UART Tx bytes are shifted  (Read 634 times)

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
UART Tx bytes are shifted
« on: August 16, 2020, 03:04:09 AM »
Hi,

I'm having a small issue with UART on a KL03.
By default the UART clock is LPUART_IRC48M                                       

Code: [Select]
        #define LPUART_IRC48M                                            // if the 48MHz clock is available clock the LPUART from it
      //#define LPUART_OSCERCLK                                          // clock the LPUART from the external clock
      //#define LPUART_MCGIRCLK                                          // clock the LPUART from MCGIRCLK (IRC8M/FCRDIV/LIRC_DIV2) - default if others are not defined

Now if I comment LPUART_IRC48M and uncomment #define LPUART_MCGIRCLK it happens that when I transmit, my characters are wrong. Basically, the transmitted bytes are shifted of 0x60
So for example, if I want to transit "A" (0x41), instead of an "A", UART transmits 0xA1 (which is 0x41 + 0x60).

What am I doing wrong? How can I fix this?
Thank you
« Last Edit: August 16, 2020, 03:31:44 AM by Raffaele »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3158
    • View Profile
    • uTasker
Re: UART Tx bytes are shifted
« Reply #1 on: August 16, 2020, 11:57:36 PM »
Hi

I would measure the waveform that is sent when transmitting The MCGIRCK sources are not that accurate (these are based on trimmed internal RC oscillators) so it may be that the frequency off a bit, which results in errors in the Rx data sampling.
You may be able to compensate for it by adding or subtracting 1 from the value programmed in the baud rate register, or by tripping the RCC oscillator manually (search for its register in the device and also check the errata since not all trimming registers actually work in all Kinetis parts).

Regards

Mark