Electronics > Microcontrollers

32F417 - any way to get baud rates below 1200?

(1/7) > >>

peter-h:
We have 42MHz on APB1 (168MHz CPU). Cube IDE generates the code for setting the baud rate in UART_SetConfig (via some extremely convoluted code) and my tests show good accuracy 2400-921.6k which is all I need at the top end, but I am trying to achieve compatibility with other stuff I have done and go down to these

30, 37.5, 50, 75, 100, 110, 134, 150, 300, 600, 1200...

The table in the ref manual for a 42Mhz clock shows this



and nothing below that but even 1200 baud doesn't work (it generates ~ 4k so probably some integer overflow).

This is with x16 oversampling; x8 makes it even worse. This is the relevant bit



Looking in the reference manual, there seems no obvious way other than to drastically slow down APB1, which we can't do because we are running some fast SPI stuff off that. There seems to be no other prescaler there, but maybe I am missing something obvious? And googling for hours finds nothing, other than the usual tons of negative comments on the ST "code generator", and one article which found an int32 overflow bug with CPUs running above 172MHz.

Could one use one of the timers for the clock?

Thank you for any ideas. No; I don't need 30 baud :) but 110 is still used in some very old kit, and 1200 is definitely used (and should work IAW the above).

harerod:
Since you have ruled out slowing down APB1-Clock, and you need a sloooow UART - why not go for a firmware emulation? AN4457 describes the concept.

Not that it helps you with your current issue, but have a look at the STM32F40xxx block diagram. Not all U?ARTs are connected to APB1. USART1/6 are connected to APB2. Same goes for the SPIs. Not being intimate with you actual setup, I can  only say that the firmware approach will work. You might even be able to share a timer.

peter-h:
OK; if one could bring a timer out onto a pin, square wave, and feed the UARTs from that pin, that would be another approach.

I am using four uarts, 1,2,3 and 6. Uarts 1 and 6 come off apb2 (84MHz) and uarts 2,3 come off apb1 (42MHz). The baud rate issue exists on all the UARTs but at a push I would settle for supporting the low speeds on one of the UARTs only.

Also I am using spi2 and spi3. SPI2 and 3 both come off apb1, 42MHz. We can't reduce that; while the fastest SPI3 clock is ~5.5MHz (the submultiple of 42 or 168MHz), I need 21MHz on SPI2. So apb1 is stuck at 42MHz afaict.

It looks like APB2 is the one which we could play with because none of the SPI2/3 use it, and uarts 2,3 use it.



But really I think I have the answer to my basic Q i.e. it is not possible to get low baud rates without some hacks.

SiliconWizard:
Yeah UART emulation that would be. At such low rates, even with no particular care, any jitter due to software emulation is likely to be completely negligible for UART communication. Now for something with good accuracy, you can always use some timer with output compare feature, and feed it with periods corresponding to the 1's and 0's. That could even be done using DMA. All you'd need to do is convert the data to a stream of periods, which is straightforward.

peter-h:
There is something strange in the way the ST code calculates the divisors, because even setting both pclk1 and pclk2 to div16 (about 10MHz) still cannot produce less than 1200 baud on any uart!

They call a function which returns the pclk frequency (which is slick, if slightly weird) so the whole thing is auto-compensating for whatever clock frequencies you select, but something weird is going on.

The reference manual gives 1200 as the lowest baud rate. Maybe for a reason?

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version