SPI Hardware Chip Select, how to use?
Posted: Mon May 20, 2019 11:09 pm
I've got some SPI code that works, flipping the CS pin manually. I'd like to see how the "hardware chip select" feature performs but I can't get it to work. I've been hunting for example code but can't find any.
I setup SPI like this
And a typical read looks like this
If I leave out the setHwCs and uncomment the "digitalWrite" statements, everything works fine. In the configuration above the CS line goes high when I do the transfer, but there is no spi clock and the CS never goes back down.
What am I missing?
I setup SPI like this
Code: Select all
ICM40605_SPI->begin(ICM40605_SCK, ICM40605_MISO, ICM40605_MOSI, ICM40605_CS);
ICM40605_SPI->beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, SPI_MODE3));
delay(100);
ICM40605_SPI->setHwCs(true);
Code: Select all
void readRegister(uint8_t* output, uint8_t offset) {
uint8_t result = 0;
// digitalWrite(ICM40605_CS, LOW);
ICM40605_SPI->transfer(offset | 0x80);
result = ICM40605_SPI->transfer(0x00);
// digitalWrite(ICM40605_CS, HIGH);
*output = result;
}
What am I missing?