Class to be able to send SPI data with almost no overhead, useful at very high speeds.

Dependents:   MakerBotServer epaper_mbed_130411_KL25Z epaper_mbed_test epaper_mbed_test_copy1 ... more

General

BurstSPI sends SPI data without reading it back, allowing higher speeds than the regular SPI library. This is mainly useful at high frequencies and large payloads. With a small number of bytes the setting up and finishing time will remove any advantage.

The three new functions compared to regular SPI are: fastWrite, setFormat and clearRX.

fastWrite is the function to quickly write data. setFormat is only required if the SPI format might have changed, or the first time you fastWrite something and you haven't used a regular SPI write before. clearRX is required if you also want to be able read from the SPI peripheral later on.

//Send 1000 SPI packets as fast as possible
spi.setFormat();
for (int i = 0; i<1000; i++)
    spi.fastWrite(data[i]);
spi.clearRX();

Supported targets

  • KL25Z, KL46Z
  • LPC1768, LPC11u24, LPC1114, LPC1549, LPC1347
  • STML152RE

If a target is not supported the library will issue a warning, and use regular writes. This means if you for example use this library to speed up writing to an LCD display, your LCD display library will work on all targets, and if possible BurstSPI will speed up the process.

Committer:
Sissors
Date:
Sat May 16 11:09:59 2015 +0000
Revision:
13:bc069279eb37
Parent:
5:4437229b0738
Added STM F4XX support.
;
; (And seriously STM, it has the same SPI as the already supported L152, but you just had to go ahead and change all your driver files)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenno 5:4437229b0738 1 #ifdef TARGET_KL46Z
kenno 5:4437229b0738 2 #include "BurstSPI.h"
kenno 5:4437229b0738 3
kenno 5:4437229b0738 4 void BurstSPI::fastWrite(int data) {
kenno 5:4437229b0738 5 //Wait until FIFO has space
kenno 5:4437229b0738 6 while(((_spi.spi->S) & SPI_S_SPTEF_MASK) == 0);
kenno 5:4437229b0738 7 //transmit data
kenno 5:4437229b0738 8 _spi.spi->DL = data;
kenno 5:4437229b0738 9 }
kenno 5:4437229b0738 10
kenno 5:4437229b0738 11 void BurstSPI::clearRX( void ) {
kenno 5:4437229b0738 12 //We put in a delay here, this function shouldn't be called very often, so not a huge problem
kenno 5:4437229b0738 13 //Without delay you will rise the CS line before it is finished (been there, done that)
kenno 5:4437229b0738 14 //We use time required to transmit 20 bits (8 bits being transmitted, 8 bits in FIFO, 4 bits safety margin
kenno 5:4437229b0738 15
kenno 5:4437229b0738 16 float bytetime = 20.0/_hz;
kenno 5:4437229b0738 17 wait(bytetime);
kenno 5:4437229b0738 18
kenno 5:4437229b0738 19 //Wait until status is flagged that we can read, read:
kenno 5:4437229b0738 20 while (_spi.spi->S & SPI_S_SPRF_MASK == 0);
kenno 5:4437229b0738 21 int dummy = _spi.spi->DL;
kenno 5:4437229b0738 22
kenno 5:4437229b0738 23 }
kenno 5:4437229b0738 24 #endif