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:
frankvnk
Date:
Fri Jan 04 09:51:42 2013 +0000
Revision:
2:a8e55f7cbfee
Parent:
0:600eecd89a78
none

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:600eecd89a78 1 #include "BurstSPI.h"
Sissors 0:600eecd89a78 2
Sissors 0:600eecd89a78 3 BurstSPI::BurstSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk){
Sissors 0:600eecd89a78 4
Sissors 0:600eecd89a78 5 }
Sissors 0:600eecd89a78 6
Sissors 0:600eecd89a78 7
Sissors 0:600eecd89a78 8 void BurstSPI::fastWrite(int data) {
Sissors 0:600eecd89a78 9 //Wait until FIFO has space
Sissors 0:600eecd89a78 10 while(((_spi.spi->SR) & 0x02) == 0);
Sissors 0:600eecd89a78 11
Sissors 0:600eecd89a78 12 //transmit data
Sissors 0:600eecd89a78 13 _spi.spi->DR = data;
Sissors 0:600eecd89a78 14 }
Sissors 0:600eecd89a78 15
Sissors 0:600eecd89a78 16 void BurstSPI::setFormat( void ) {
Sissors 0:600eecd89a78 17 format(_bits, _mode);
Sissors 0:600eecd89a78 18 frequency(_hz);
Sissors 0:600eecd89a78 19 }
Sissors 0:600eecd89a78 20
Sissors 0:600eecd89a78 21 void BurstSPI::clearRX( void ) {
Sissors 0:600eecd89a78 22 //Do it while either data in RX buffer, or while it is busy
Sissors 0:600eecd89a78 23 while(((_spi.spi->SR) & ((1<<4) + (1<<2))) != 0) {
Sissors 0:600eecd89a78 24 //Wait until data in RX buffer
Sissors 0:600eecd89a78 25 while(((_spi.spi->SR) & (1<<2)) == 0);
Sissors 0:600eecd89a78 26 int dummy = _spi.spi->DR;
Sissors 0:600eecd89a78 27 }
Sissors 0:600eecd89a78 28 }