5 years, 6 months ago.

Delay between SPI.write() calls

Hi all,

I'm using a RedBearLabs Blend V2 to communicate with a SPI peripheral. Everything is functioning correctly at this point and I am receiving the expected data using SPI.write() and catching the return value. The SPI bus is running at 1 MHz in mode 0.

The image below shows the SPI bus connected to a scope. Trace 1 is SCLK, 2 is MISO, 3 is MOSI and 4 is CS. As you can see, I have 4 bursts of SCLK whilst CS is low, each 8 bits in length with a delay of approximately 20 µs in between each burst. Ideally, I need to completely alleviate this 20 µs delay and have 1 SCLK burst of 32 cycles.

/media/uploads/amitchone/ds1z_quickprint3.png

So far I have tried setting SPI.format(16, 0), however the SPI bus no longer functions if I do this. The same happens if I use SPI.transfer() with 32-bit buffers.

I am able to increase the frequency of the bus, thus reducing the delay between each SCLK burst, however this is not really a suitable solution due to the end-application for this device.

What am I doing wrong here, or is what I am attempting to do just not possible?

Thanks, Adam

2 Answers

5 years, 2 months ago.

Hi Adam, when I use a 4 char buffer, I get 4 closely grouped 8-bit bursts... so 32-bit bursts. Unfortunately, there is a large delay between 32-bit bursts and I haven't found a solution. If anyone knows what causes the delay, please post. I am for instance doing two writes in a row... no other code in between write requests.

I've tried using a larger buffer but the biggest burst I can get is 32-bits. I've got MAX32630FTHR hardware.

5 years, 6 months ago.

The different mbed platforms dont all have support for the same message formats. The 8 and 16 bit length is pretty much available on all platforms, but other formats like 9bit or 32 bit are rarely or never supported in the libs even if they are in fact available on the SPI hardware engine. It would be nice if more formats were supported or if there would at least be a return value for the spi.format() that gives you feedback about success. I needed 9bits for some LCD controllers and that only worked on the LPC1768.

You could add these missing formats yourself by cloning the mbed lib and adapting the code for your target platform. You can also add a separate piece of code in your project that accesses the SPI hardware directly. The long delays between messages are caused by overhead in the spi.write() calls. There are some user libs in the repository that speed up the transmission. Search for Burst SPI or something like that.