Accelerometer Data Transfer Rate Question

Hello,

I am doing a project where I need to read data from an accelerometer (in only one dimension), and know precisely when these readings occurred. I am connecting an ADXL345 to an Arduino Uno via an SPI connection. I think the part of my code that sets the data transfer rate is SPI.beginTransaction (SPISettings (maxSPIClockSpeed, MSBFIRST, SPI_MODE0)); where maxSPIClockSpeed is some integer around 3200. I have also set the serial monitor to the same baud rate.

My main question: does this mean that readings from the accelerometer are being transmitted to the Arduino at 3200Hz? Is it more complicated than this? To be clear I am not necessarily interested in the fastest sample rate, but rather knowing a sample rate accurately.

Thanks for the help!

No, it does not. SPI transfers are completely under the control of the master, and will not happen unless you initiate them. beginTransaction does not set up any kind of period reading, you must do that yourself.

Thanks for the reply.

Is there any way for the accelerometer to return the time each sample was taken or an accurate way to know the frequency at which it is transferring data to the Arudino?

AnthonyBuo:
Thanks for the reply.

Is there any way for the accelerometer to return the time each sample was taken or an accurate way to know the frequency at which it is transferring data to the Arudino?

The accelerometer has no timestamp capability, but the Arduino does.

I was considering something like Serial.println(millis()); after every accelerometer reading is printed to the serial monitor. Do you think this method would be accurate if I was doing this at over 100Hz?

I was also considering setting the data rate bit to transmit at 3200Hz or some similar number.

Don't forget that if you're using Serial prints, you need to ensure that the serial line speed is set very high.
9600 bits per second is only 960 characters per second, and these get used up mighty fast at even a 100Hz reporting rate, if you're printing timestamps and multiple axes (don't forget to include whitespace and CR/LF in your reckoning)

AnthonyBuo:
Thanks for the reply.

Is there any way for the accelerometer to return the time each sample was taken or an accurate way to know the frequency at which it is transferring data to the Arudino?

The ADXL345 is a slave device. This means that it cannot initiate communications, that must be done by the master (the Arduino). Since you can control exactly when the Arduino talks to the sensor, you can control it to happen at any sampling rate you want.