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:
4:8585ddebd28b
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
Alamalione 4:8585ddebd28b 1 /* BurstSPI_NUCLEO_L152RE.cpp */
Alamalione 4:8585ddebd28b 2 #ifdef TARGET_NUCLEO_L152RE
Alamalione 4:8585ddebd28b 3 #include "BurstSPI.h"
Alamalione 4:8585ddebd28b 4
Alamalione 4:8585ddebd28b 5 void BurstSPI::fastWrite(int data) {
Alamalione 4:8585ddebd28b 6
Alamalione 4:8585ddebd28b 7 SPI_TypeDef *spi = (SPI_TypeDef *)(_spi.spi);
Alamalione 4:8585ddebd28b 8 // Check if data is transmitted
Alamalione 4:8585ddebd28b 9 while (!((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_TXE) != RESET) ? 1 : 0));
Alamalione 4:8585ddebd28b 10 SPI_I2S_SendData(spi, (uint16_t)data);
Alamalione 4:8585ddebd28b 11 }
Alamalione 4:8585ddebd28b 12
Alamalione 4:8585ddebd28b 13 void BurstSPI::clearRX( void ) {
Alamalione 4:8585ddebd28b 14 int status;
Alamalione 4:8585ddebd28b 15 //Check if the RX buffer is busy
Alamalione 4:8585ddebd28b 16 SPI_TypeDef *spi = (SPI_TypeDef *)(_spi.spi);
Alamalione 4:8585ddebd28b 17 status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_BSY) != RESET) ? 1 : 0);
Alamalione 4:8585ddebd28b 18 if (status){
Alamalione 4:8585ddebd28b 19 // Check RX buffer readable
Alamalione 4:8585ddebd28b 20 while (!((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_RXNE) != RESET) ? 1 : 0));
Alamalione 4:8585ddebd28b 21 int dummy = (int)SPI_I2S_ReceiveData(spi);
Alamalione 4:8585ddebd28b 22 }
Alamalione 4:8585ddebd28b 23 }
Alamalione 4:8585ddebd28b 24 #endif
Alamalione 4:8585ddebd28b 25