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


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
for (int i = 0; i<1000; i++)

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.

Sat May 16 11:09:59 2015 +0000
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
Sissors 9:b69faea5252c 1 #if defined(TARGET_LPC1768) || defined(TARGET_LPC1114) || defined(TARGET_LPC11U24) || defined(TARGET_LPC13XX)
Sissors 9:b69faea5252c 2 #include "BurstSPI.h"
Sissors 9:b69faea5252c 3
Sissors 9:b69faea5252c 4 void BurstSPI::fastWrite(int data) {
Sissors 9:b69faea5252c 5 //Wait until FIFO has space
Sissors 9:b69faea5252c 6 while(((_spi.spi->SR) & 0x02) == 0);
Sissors 9:b69faea5252c 7
Sissors 9:b69faea5252c 8 //transmit data
Sissors 9:b69faea5252c 9 _spi.spi->DR = data;
Sissors 9:b69faea5252c 10 }
Sissors 9:b69faea5252c 11
Sissors 9:b69faea5252c 12 void BurstSPI::clearRX( void ) {
Sissors 9:b69faea5252c 13 //Do it while either data in RX buffer, or while it is busy
Sissors 9:b69faea5252c 14 while(((_spi.spi->SR) & ((1<<4) + (1<<2))) != 0) {
Sissors 9:b69faea5252c 15 //Wait until data in RX buffer
Sissors 9:b69faea5252c 16 while(((_spi.spi->SR) & (1<<2)) == 0);
Sissors 9:b69faea5252c 17 int dummy = _spi.spi->DR;
Sissors 9:b69faea5252c 18 }
Sissors 9:b69faea5252c 19 }
Sissors 9:b69faea5252c 20 #endif