Electronic – How to buffer SPI

bufferfifomicrocontrollerspi

I have a board with a device that outputs data over SPI (as slave device) and a microcontroller. The device signals that data is available (24 bits) by setting a certain pin low, around 8000 times per second. If the data is not read before the next data is available it is lost. Unfortunately the microcontroller may sometimes be busy with another task, for as much as 1-2 milliseconds.

I would like some way to read the data from the device whenever it is available into a FIFO or buffer of some kind. The microcontroller can retrieve that data later when not busy. I also want to be able to do SPI read/write directly to the device when the buffer is empty. What is the best way to set that up?

Best Answer

I'm afraid the answer is going to be a microcontroller or other programmable device. My reasoning is as follows:

  1. The sensor is a slave device, not a master.

  2. Slave devices need an external clock to clock the data out.

  3. But only 24 clock pulses.

  4. Simple logic devices aren't generally set up to make their own clock.

  5. Therefore, the simplest solution will be a microcontroller with two SPI peripherals and sufficient memory to buffer through your maximum interrupt latency. Choose a micro with an internal clock and appropriate supply voltage for your circuit. Perhaps MSP430F5151.

Now, if your sensor was a SPI master, then you could be clever with multiplexed pins and just use a Microchip serial SRAM, setting up the write with the microcontroller, then letting the sensor continue writing into the RAM. See e.g., the Logic Shrimp logic analyzer for creative use of serial RAM parts.

Power consumption calculation with microcontroller.

By popular request, let's estimate the current draw for the MSP430 that I linked above.

MSP430 achieves low power with a switchable high-speed clock DCO, which will only need to run for the duration of the data transfer.

Let's choose 8 MHz SPI clock. 24-bit transfer will therefore take 24/(8 MHz) or 3 microseconds. From the datasheet, the DCO takes 1.6mA maximum and 6.5 microseconds maximum to start at 8 MHz. So the entire transfer takes about 10 microseconds. Each transfer takes 1.6 mA * 10 microseconds, or 16 nC. 8000 transfers / sec is 128 microamp average current. But double this, because we have to read out as well. (This is bit pessimistic, as the clock doesn't need to run during an SPI slave transaction.) So say an average current of 256 microamps.