I’m using serial communication in different flavors for my project: with the shell, with OpenSDA USB CDC, to use printf(), and with the Bluetooth module. Processor Expert is a big helper, but as for any software, it is not bug free. And there is a problem with Processor Expert in CodeWarrior for MCU10.3 in respect with Baud settings for a serial interface.
The problem is: depending on my clock configuration of the Kinetis-L KL25Z (e.g. FRDM-KL25Z board), the Baud seen on the wires is off by a factor of two.
❗ This problem has been reported and should be fixed in an upcoming update of CodeWarrior. Until then, this post might help you to work around the problem.
I stumbled upon this problem while developing the firmware for a Serial Bluetooth module and the FRDM-KL25Z Freedom board. In some configurations, I was able to communicate properly over SCI/RS-232 with the Bluetooth module, but not in others.
I had the UART configured for 38400 Baud:
However, although I knew for a fact that my Bluetooth module is configured to communicate with 38400 Baud, I was not able to connect. Time to probe things with my logic analyzer. And this is what came out:
Configured to analyze the UART traffic using 38400 Baud, the result is just garbage. Luckily I had the idea to use the ‘Autobaud’ function in the analyzer. And voilà:
So what came over the wires was only half of the speed I have configured :-(.
So I doubled the Baud in the component settings to 2*38400=76800 Baud, and now it was working with 34800 Baud:
Looking at how the Baud clock is generated in the component, showed the cause of the problem: it is using the core clock (as on Kinetis-K) instead of the Bus clock (as it should for Kinetis-L):
So it is dividing from the 48 MHz core clock (instead of the 24 MHz Bus clock). And indeed I have a clock speeds for bus and core in my CPU settings:
This explains why it was working for a different project. In that different project my core and bus clock are set to the same speed :-).
So: to overcome the issue, either use same core and bus clock, or change the baud setting in the component to ‘tune’ to the desired baud.
Processor Expert in the MCU10.3 release is not taking into account that the bus clock divider on L series is dividing down the Core clock, NOT the MCGOUTCLK that would be used on Kinetis K series. In case the Baud is off by this, a workaround is to change the Baud settings in the component to a higher value to produce the correct Baud. Of course, once a fixed Processor Expert comes out, that ‘fix’ has to be reverted.
Another workaround is to use the same bus and core clock speed. But as the bus clock on the Kinetis-L is limited to 24 MHz, that means to run the CPU with 24 MHz instead of the possible 48 MHz.
Different Clock Source for UART’s
On fact I was not aware of until [Victor] posted a comment to this article: the UART0 on the KL25Z has a selectable clock input: See “UART – Unversal Asynchronous Receiver/Transmitter” on page 7: with the SIM_SOPT register a clock source can be selected:
And indeed: in CodeWarrior for MCU10.5 I can select the clock source in Processor Expert where I can enter the baud:
Happy Bauding 🙂
PS: it is ‘Baud‘, not ‘Baud rate’. ‘Baud’ is the symbol rate, and it already contains the ‘rate’. Sounds like a minor thing, but there is a peer in my office which always points this out, should I ever, ever, ever use the term ‘Baud rate’ ;-). Yes, he is technically 100% correct. Thank you, Marcel :mgreen:
Additional link: What’s the difference between bit rate and baud rate