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.
Summary
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
I had the same problem last week, uart0 worked fine but uart1 and uart2 had baud rates of 1/2 of the set value in PE. Because Uart0 has significantly different features then uart1 and uart2, I assumed that the different internal dividers were not accounted for in the processor expert.
Processor expert makes using the peripherals very easy but does not utilize many of the unique features of the peripherals. It also tends to kill the performance with huge software overhead. Many times I use PE to initialize the peripherals but talk to them the “old way” by reading/writing directly to registers for full functionality and performance.
Jeff
LikeLike
Hi Jeff,
yes, there are always trade offs between speed, size and as well for time to implement things. As for myself I need to support many different processors and microcontrollers, and with this PE makes things a lot easier for me. But of course if you target say just one microcontroller (or a few), it might be worthwile to hand-optimize the functions, or to use other libraries. But as you say: initializing the peripherals and using this as a starting point is something I use very frequently too. In this post case Processor Expert implementation was wrong (and the hardware manual was correct). But I have seen more cases were the reference manual was wrong (or maybe not clear, or misleading), while the Processor Expert generated code was giving me a working piece of software.
LikeLike
Hi!
I was trying to set the baud for the UART1 but it doesn’t allow values higher than 57600.
The error reported is “Timing setting failed-it is impossible to set the following items: initialization value”
But I need 115200. What other settings need to be done to achieve 115200?
Cristian
LikeLike
Hi Cristian, I think a higher baud is only possible if you use a higher bus/core clock. Have you already changed the settings say to use 48 MHz?
LikeLike
I have been having a very similar issue with UART1 and UART2. Do you know whether all UARTs not created equal? Using the FRDM board and set up for a 48MHz core / 24MHz bus clock should you be able to get 460800 baud on all three UARTs?
LikeLike
Hi Victor,
to my knowledge that problem applies to all UARTs. 460800 is very high. I tried it, and that at least is accepted in Processor Expert. But I have not tested if communication with this works. Just one thing to keep in mind: typically the baud needs to be in a 1.5% accuracy: using high speed baud might be a problem because of this.
LikeLike
I’ve been browsing and found this: Kinetis%20L%20-%20UART.pdf
There does appear to be at least some difference between UART0 and UART1/2 per slides 11 and 12.
How do you specify the UART Module Clock in Processor Expert?
LikeLike
Hi Victor,
thanks for that link. I was not aware of this. I have checked CodeWarrior for MCU10.5, and indeed I can change the clock source for UART0. I have posted screenshots of this in the article so you can see where you can specify this.
LikeLike
Also, do you know if the % Error setting in PE is just a plausibility check or if it affects code generation?
LikeLike
Hi Victor,
it is just a check for the entered baud rate, and does not affect the code generated.
LikeLike
Hi Erich,
Thank you for this and all your other tutorials. I too am struggling to get a baud of 115200. I am trying to edit my system clocks to the values specified in your screen shot and Processor Expert again says that these values are impossible. I am currently using a Kl25z and running Codewarrior for MCU 10.5. Any help or advice would be greatly appreciated.
LikeLike
What core/bus clock are you using? In order to achieve high baud, you need high clock speed.
LikeLike
Thanks for the quick response. Both the core and bus clocks are still set at 20.97152. When I attempt to change them to 48, and 24 respectively I receive the errors “not possible to set requested value. The closest possible value is 20.97152”
LikeLike
Have a look at the settings of this project:
https://mcuoneclipse.com/2012/10/07/tutorial-usb-cdc-with-the-kl25z-freedom-board/
the project is on GitHub too.
LikeLike
Hello, Ben here.
I’ve been working on a serial datalogger device. And have a question about changing the baud rate while the application is running.
I have 2 uart devices DTE, and DCE each using the serial_ldd bean.
I have them all initialized, receiving, and sending data fine, at the specified baud rate
that I set in the PE settings menu for each bean.
I noticed that there are methods for reading the rate, and changing it. PROVIDED that you have
set up the list of possible speeds in the baud rate list. So I setup the list in the timing dialog box with 3 speeds.
As soon as I did that, the GetSelectedBaudRate became available for use once enabled. But the SelectBaudRate method is still grayed out. Any pointers on getting the SelectBaudRate method functional?
Once it is, I’m pretty sure I would use it like so:
DTE_SelectBaudRate(&DTEdeviceData,x);
where x = (1,2,3,etc…) for each speed.
-Thanks
LikeLike
Hi Ben,
I’m using the AsynchroSerial component. Then this is very easy.
There I select for the Baud Rate ‘List of values’ with all my baud rates.
Then this enables the SetBaudRateMode() function in the component, which can be used with the
#define AS1_BM_9600BAUD 0 /* Baud rate constant for switch to the baud rate mode 0 */
#define AS1_BM_38400BAUD 1 /* Baud rate constant for switch to the baud rate mode 1 */
#define AS1_BM_12000BAUD 2 /* Baud rate constant for switch to the baud rate mode 2 */
I have set up.
LikeLike
Had Similar Problem with FRDM-KE04Z board, KDS 2.0.0, and KDSK 1.1.0, and processor expert for KDS 2.0.0. The desired “Hello World” would transmit properly while loading the code (perhaps from the previous run), but while running the code gibberish appeared. After I switched the baud rate of the AsynchroSerial component to 16500, and left the baud rate of Hyperterminal at 19200 I was able to get Hello World to print out properly when running the code, but gibberish when loading. Wonder what it will be like outside the debug environment? Be fun if I didn’t have other work to do!
LikeLike
That sounds to me like a different issue. Either a hardware problem or something did not got properly initialized?
LikeLike
I’m currently on a project using a KE06Z microcontroller, KDS 2 and Processor Expert. I had the same behavior with the serial interface, and only that combination of baud rate on the AsynchroSerial and Terminal seemed to work.
I found the solution on this thread on freescale community.
Apparently this is a bug in Processor Expert that configures the Internal Oscillator Clock to 32.768 kHz, which is an invalid value for this microcontroller family.
After correcting the value to 37.5, everything started to work just fine.
It took me some weeks to finally find this solution, I hope this helps somebody
=).
LikeLike
Hi Daniel,
indeed, that has been a problem, thanks for pointing to that one. I recommend that you upgrade to KDS v3.0.0 as in that version this issue has been fixed.
Erich
LikeLike