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.

Revision:
2:a8e55f7cbfee
Parent:
1:5ef4a019e0db
Child:
3:7d9b64d67b22
--- a/BurstSPI.h	Thu Jan 03 20:43:55 2013 +0000
+++ b/BurstSPI.h	Fri Jan 04 09:51:42 2013 +0000
@@ -6,9 +6,12 @@
 
 /** An SPI Master, used for communicating with SPI slave devices at very high speeds
  *
- * The default mbed SPI class allows for communication via the SPI bus at high clock frequencies, however at these frequencies there is alot of overhead from the mbed code.
- * While this code makes sure your code is alot more robust, it is also relative slow. This library adds to your default SPI commands some extra commands to transmit data rapidly with
- * very little overhead. Downsides are that currently it is TX only (all RX packets are discarded), and it requires some extra commands.
+ * The default mbed SPI class allows for communication via the SPI bus at high clock frequencies,
+ * however at these frequencies there is alot of overhead from the mbed code.
+ * While this code makes sure your code is alot more robust, it is also relative slow.
+ * This library adds to your default SPI commands some extra commands to transmit data rapidly with
+ * very little overhead. Downsides are that currently it is TX only (all RX packets are discarded),
+ * and it requires some extra commands.
  *
  * Example:
  * @code
@@ -19,7 +22,8 @@
  *  spi.clearRX();
  * @endcode
  *
- * As an example, writing 76,800 16-bit data packets to an LCD screen at 48MHz requires 111ms with the normal mbed library. With this library it takes 25ms, which is also the theoretical
+ * As an example, writing 76,800 16-bit data packets to an LCD screen at 48MHz requires 111ms with
+ * the normal mbed library. With this library it takes 25ms, which is also the theoretical
  * amount of time it should take. If you are running at 1MHz this will do alot less.
  */
 class BurstSPI : public SPI {
@@ -39,7 +43,8 @@
 
     /** Put data packet in the SPI TX FIFO buffer
     *
-    *  If there is no space in the FIFO buffer it will block until there is space. The FIFO buffer will automatically send the packets. There is no receiving here, only transmitting.
+    *  If there is no space in the FIFO buffer it will block until there is space.
+    * The FIFO buffer will automatically send the packets. There is no receiving here, only transmitting.
     *
     *  @param data Data to be sent to the SPI slave
     */
@@ -47,16 +52,20 @@
     
     /** Use this function before fastWrite to set the correct settings
     * 
-    * It is not needed to use this if the last SPI commands were either normal SPI transmissions, or setting different format/frequency for this object. It is required to call this
-    * function when several SPI objects use the same peripheral, and your last transmission was from a different object with different settings. Not sure if you should use it?
+    * It is not needed to use this if the last SPI commands were either normal SPI transmissions,
+    * or setting different format/frequency for this object. It is required to call this
+    * function when several SPI objects use the same peripheral, and your last transmission was
+    * from a different object with different settings. Not sure if you should use it?
     * Use it, it takes very little time to execute, so can't hurt.
     */
     void setFormat( void );
     
     /** After you are done with fastWrite, call this function
     *
-    * FastWrite simply fills the SPI's (SSP's actually) TX FIFO buffer as fast as it can, and that is the only thing it does. It doesn't do anything with received packages (currently, may change),
-    * so the the RX buffer is full with unneeded packets. This function waits until transmission is finished, and clears the RX buffer. You always have to call this before you want to receive
+    * FastWrite simply fills the SPI's (SSP's actually) TX FIFO buffer as fast as it can,
+    * and that is the only thing it does. It doesn't do anything with received packages (currently, may change),
+    * so the the RX buffer is full with unneeded packets. This function waits until transmission is finished,
+    * and clears the RX buffer. You always have to call this before you want to receive
     * SPI data after using fastWrite.
     */    
     void clearRX( void );