I have a Nucleo L476RG board and I'd like to read the outputs from two IIS3DWB accelerometers and send them to a serial communication at 22kHz frequency.
At the moment I'm trying with just a single accelerometer but I'm getting only about 10k values per second, how can I improve the speed?
I've read that the SPI library is not well optimized for speed...
I'm using this library for the accelerometers: https://github.com/kriswiner/IIS3DWB
This is how readBytes and writeByte functions look like:
Code: Select all
void IIS3DWB::readBytes(uint8_t reg, uint8_t count, uint8_t * dest)
{
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
digitalWrite(_cs, LOW);
SPI.transfer((reg & 0x7F) | 0x80);
for (uint8_t ii = 0; ii < count; ii++)
{
dest[ii] = SPI.transfer(0);
}
digitalWrite(_cs, HIGH);
SPI.endTransaction();
}
void IIS3DWB::writeByte(uint8_t reg, uint8_t value)
{
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
digitalWrite(_cs, LOW);
SPI.transfer(reg & 0x7F);
SPI.transfer(value);
digitalWrite(_cs, HIGH);
SPI.endTransaction();
}
Fabio