I am not using any delay(). I have set up a timer interrupt that sets a flag every 10 millisecond, which I then use to poll data from the sensor. I need to sample higher that this rate. I am aiming at 1K samples / second or read every millisecond.
I am now using SPI instead of I2C and it has reduced the read time significantly. Almost 43% of what it took with I2C. This is at 5MHz, which is the highest the sensor can go.
So, what I take from this is that simultaneous access over 2 different channels is is not possible with Arduino libraries. Right? But is it possible any other way? Say, I write my own code with Atmel Studio. Does it involve dealing with DMA?
Can anyone point me in the right direction?
The code is like this,
Setup SPI:
pinMode(_clk, OUTPUT);
digitalWrite(_clk, HIGH);
pinMode(_do, OUTPUT);
pinMode(_di, INPUT);*/
SPI.begin();
SPI.beginTransaction (SPISettings (5000000, MSBFIRST, SPI_MODE3));
pinMode(_cs,OUTPUT);
digitalWrite(_cs, HIGH)
Read Register:
void Accel::ReadRegister(uint8_t regAddress, uint8_t values[], uint8_t numberOfBytes)
{
regAddress |= 0x80;
// set the multi-read byte if required
if (numberOfBytes > 1) {
regAddress |= 0x40;
}
digitalWrite(_cs, LOW);
SPI.transfer(regAddress);
// read the data
for(int i=0; i<numberOfBytes; i++){
values[i] = SPI.transfer(0x00);
}
digitalWrite(_cs, HIGH);
}