SPI in 32 bit data TX

Status
Not open for further replies.

philip.porhammer

Well-known member
is there a way to configure the SPI to send 32bits without braking it up?
#include <SPI.h>


// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
long DATA =0;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
digitalWrite (slaveSelectPin, HIGH);
// initialize SPI:
SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
}

void loop() {

delay(1);
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(DATA);
SPI.transfer(DATA);
SPI.transfer(DATA);
SPI.transfer(DATA);
digitalWrite(slaveSelectPin,HIGH);

}
 
The answer is no, at least for the Teensy 3.x. The SPI transmit data register can hold a maximum of 16bit. But there is a configuration flag for continuous mode, so that you can transmit your 32bit value as 2x16bit with (almost) no gap.
But if I remember well, neither 16bit nor continuous mode are supported by the standard (Arduino compatible) SPI library. Either you find an optimized library for the T3.x or you implement these yourself after studying the SPI chapter of the processor reference manual.
 
Status
Not open for further replies.
Back
Top