SPI baud rate

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
HolyGrail
Posts: 7
Joined: Fri Jul 08, 2022 3:45 pm

SPI baud rate

Post by HolyGrail » Sun Jul 10, 2022 2:40 pm

I wonder if anyone knows what the range of SPI Baud rates are for the Micro:Bit (v2)? The docs give an example setup of baudrate = 1000000
(ie 1MHz).
I have built a PIC based SPI client (slave) that drives a 20x4 line 'old fashioned' LCD display. This receives nicely from the Micro:bit.
I have tried increasing the Micro:bit SPI baudrate to ridiculous levels (10MHz) and also slowing it to 10 baud but everything still works as though the Micro:bit is still set at 1MHz.

Also, what is the max SPI buffer size on the Micro:bit please?

Any ideas please?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: SPI baud rate

Post by jimmo » Mon Jul 11, 2022 1:04 am

HolyGrail wrote:
Sun Jul 10, 2022 2:40 pm
I have tried increasing the Micro:bit SPI baudrate to ridiculous levels (10MHz) and also slowing it to 10 baud but everything still works as though the Micro:bit is still set at 1MHz.
The microbit port of MicroPython is a bit different to regular MicroPython and is based on the CoDAL.

It does seem like this is supposed to work though, when you construct a microbit.SPI instance
https://github.com/microbit-foundation/ ... _spi.c#L82
which then does
https://github.com/microbit-foundation/ ... l.cpp#L230
and then
https://github.com/lancaster-university ... I.cpp#L192
(that last one gives you the limits)

Are you able to confirm with a scope or logic analyser that setting the baudrate parameter has no effect? (Although it certainly sounds like it doesn't).
HolyGrail wrote:
Sun Jul 10, 2022 2:40 pm
Also, what is the max SPI buffer size on the Micro:bit please?
The last link above also has the transfer function, which uses

Code: Select all

#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA)
#define SZLIMIT 0xffff
#else
#define SZLIMIT 0xff
#endif
(The microbit v2 uses a 52833 Q1AA)

HolyGrail
Posts: 7
Joined: Fri Jul 08, 2022 3:45 pm

Re: SPI baud rate

Post by HolyGrail » Mon Jul 11, 2022 11:30 am

Thanks, Jimmo. I can get it on a scope in a couple of weeks so that will be interesting.

JeffT
Posts: 2
Joined: Mon Jul 11, 2022 1:58 am

Re: SPI baud rate

Post by JeffT » Mon Jul 11, 2022 3:05 pm

I noticed this sometime ago, the test I did was to write 10KB sequentially to sram with a timer at the end of the loop. Entering a frequency of 600000 (and anything above that) I got a time of ~2.7 seconds. That was the best I could do with the test I was using.

I did the same test using JavaScript setting a frequency of 1000000 and got a time of 0.8 seconds. I could not better that even when I raised the frequency value. Going below 1MHz the time increased significantly.

Not a very scientific test but the difference in times gave me a pretty good idea of how bad the Python spi is if you need the speed.

I am interested in seeing the results of your scope readings, I would love to be able to have the same speed in Python as I got in Java but I'm not sure that is possible.

Post Reply