I am using SPI to communicate with a IMU device which is working perfectly, except the SPISpeed which is not being altered as it should:
unsigned int m_SPISpeed = 400000;
SPI.begin();
pinMode(m_SPISelect, OUTPUT);
m_SPISettings = SPISettings(m_SPISpeed, MSBFIRST, SPI_MODE0);
...
SPI.beginTransaction(m_SPISettings);
digitalWrite(m_SPISelect, LOW);
SPI.transfer(regAddr | 0x80);
Where m_SPISpeed
is 400000. No matter what i set this value to it is always operating at 125000Hz
.
unsigned int
4000000L
, looking at the source code for the new SPI library, it applies a simple algorithm to get a clock divider, so unless you're spot on with a multiple, you get the next lowest.