0
\$\begingroup\$

I am having this microcontroller - S32K142 64 Pin 5V Core voltage

Microcontroller Reference Manual

I am using an 8MHz external clock.

I want to calculate the Bit error rate of my LIN Communication.

My LIN Communication Baud rate is 19.2kbps.

My questions :

  1. Can I use the LPUART Module in the Mirocontroller for the LIN Communication?

  2. How to find the Bit error rate for the LIN Protocol communication for my baud rate of 19.2kbps and external clock of 8MHz.

I found this below from the reference manual. But not sure, how to calculate the Bit error rate from this.

enter image description here

  1. How to calculate the SBR Register value, OSR and the LPUART ASYNCH Module clock?

Please help

\$\endgroup\$
  • \$\begingroup\$ First you need to solve how the device clocks end up to the UART, i.e. is the system clock and peripheral clocks really 8MHz or something else to know what the module clock is. Then look at what values the OSR can be set to, and choose SBR and OSR so that they are withing range. But using 8 MHz sounds quite slow for a 32-bit MCU capable of going at 48-100 MHz, as with a faster clock you can get baud rate more accurately, but it depends on what tolerance you need. 8MHz sounds OK if you don't need speed and you must operate at low power. \$\endgroup\$ – Justme Jun 23 '20 at 11:17
  • \$\begingroup\$ Could you please guide me to how to figure this out \$\endgroup\$ – Newbie Jun 23 '20 at 11:51
  • \$\begingroup\$ I am not able to trace the clock which ends in the UART \$\endgroup\$ – Newbie Jun 23 '20 at 11:53
  • \$\begingroup\$ Only you know how your MCU is configured, or if you use the PLL to go near 100 MHz? How did you even get it running so far? Did you use some example project or code generator? Does NXP provide libraries? I know little of Cortex-M4, and even less about NXP's implementation of it. \$\endgroup\$ – Justme Jun 23 '20 at 13:34
  • \$\begingroup\$ nxp.com/docs/en/application-note/AN5408.pdf - I found this online. And in the reference manual section 27.6 modules clocks, the clock source for the UART are - SPLLDIV2_CLK, FIRCDIV2_CLK, SIRCDIV2_CLK, SOSCDIV2_CLK. The FIRC is 48MHz and the SIRC is 8MHz and the SOSC (which I assume is the system clock i.e, the external crystal frequency which I connect on XTAL and EXTAL pins) is 8MHz. Not sure on what would be the SPLL, though. So, how to proceed from here? Could you explain \$\endgroup\$ – Newbie Jun 23 '20 at 13:38
1
\$\begingroup\$

Everything related to the clock is configured by the software running on the MCU.

This includes what is the clock source (internal/external), the clock multiplication with PLL (if it is used or not), enabling and dividing down the clocks for buses and peripherals.

There is no way we can know without looking at the source code how your software team has set up the clocks. Ask them.

Edit to actually answer the questions:

  1. Yes, LIN is usually implemented with simple UART, so any UART should be capable of implementing LIN. The datasheet specifically mentions LPUART is a LIN/UART peripheral.

  2. When you know how what system frequency comes in to the LPUART peripheral, calculating the values to get 19200 baud rate is easy, and if the resulting baud rate is not exactly 19200, you can check if it is within LIN tolerance.

SPLL is the clock output from PLL. Configured in software. However, it uses the crystal as reference, so at least you know 8 MHz goes into PLL.

FIRC is the clock output from Fast Internal RC oscillator.

SIRC is the clock output from Slow Internal RC oscillator.

SOSC is the clock output from the crystal oscillator, so it's 8 MHz.

The SIRC has a tolerance of max 3.0% or 3.3%, so it can't be used for LIN.

The FIRC has a tolerance of max 1.4%, and they specifically mention it is suitable for LIN as a slave, but not for LIN master. It's 48 MHz.

So the only way to be a LIN master is to use the 8 MHz crystal, either directly or via PLL.

  1. The UART is a bit non-conventional as it has freely selectable oversampling ratio. Assuming you use the 48 MHz clock, and if oversampling ratio is set to 16 like for other typical UARTs, the OSR=15. The SBR must then be set to rounded value of 156 to achieve closest value to 19200. The baud rate error is 0.16%. You can select other oversampling ratios to get closer to 19200.
\$\endgroup\$
  • \$\begingroup\$ Thank you very much for the detailed answer. I was not notified of the edit in your answer. I have a doubt. 1. How to choose the oversampling ratio? There are many values. How to pick a value and why is that value taken? \$\endgroup\$ – Newbie Jul 6 '20 at 13:39
  • 1
    \$\begingroup\$ It depends on your requirements. Typically, MCUs offer only one ratio, 16x, or sometimes only two ratios, 16x and 8x, so usually everything is based on 16x ratio. LIN actually has a requirement, that the edge of start bit is detected at minimum 8x oversampling rate, and it states that typical is 16x. If you select 17x oversampling ratio, you will be able to reach 0.04% baud rate error for 19200. Just put the numbers in a spreadsheet program to see. \$\endgroup\$ – Justme Jul 6 '20 at 13:58
  • \$\begingroup\$ Thank you for the answer \$\endgroup\$ – Newbie Jul 6 '20 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.