0

Background Information

I am trying to make sure I will be able to run two ADXL345 Accelerometers on the same I2C Bus.

To my understanding, the bus can transmit up to 400k bits/s on fast mode.

In order to send 1 byte of data, there are 20 extra bits of overhead.

There are 6 bytes per accelerometer reading (XLow, XHigh, YLow, YHigh, ZLow, ZHigh)

I need to do 1000 readings per second with both accelerometers

Thus, My total data used per second is 336k bits/s which is within my limit of 400k bits/s.

I am not sure if I am doing these calculations correctly.

Question:

How much data am I transmitting per second with two accelerometers reading 1000 times per second on i2c?

7
  • How did you get the 20 bit overhead per read? If you need to send a command, it's around 20 bits, but then you usually need to send the device address again to read => + 10 bits more! And remember 400k is the max speed if everything is perfect, which won't likely happen...
    – B. Go
    Feb 18, 2020 at 21:16
  • And the 20 bits don't include start and stop time. But maybe the 400k neither?
    – B. Go
    Feb 18, 2020 at 21:17
  • And your i2c interface may not support using that speed outside bursts : how many reads can you do before having to empty the registers? Will you use DMA for that? and so on
    – B. Go
    Feb 18, 2020 at 21:19
  • 1 start bit + 7 chip addr bit + 1 ack + 8 register bit + 1 ack + (8 data) + 1 ack + 1 stop = 20 bits of overhead + 8 data bits. I got those numers from: avrfreaks.net/forum/solved-atmega328-i2c-slave-mode. Feb 18, 2020 at 21:51
  • 1
    You diagram only works for a write, not a read, and you at least forgot the r/w bit after the chip addr, and a few bit times after the stop. Your actual timings are at analog.com/media/en/technical-documentation/data-sheets/… page 18, the last 2. Using a second chip addr as I was thinking. But there is a multiple read mode which can be used if you're lucky, as it may do sequential (auto increment) register reads (didn't check)
    – B. Go
    Feb 19, 2020 at 11:28

1 Answer 1

0

Your math seems to be a bit off; for this accelerometer (from the datasheet: https://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf), in order to read the 6 bytes of XYZ sample data, you need to perform a 6-byte burst read of the registers. What this means in terms of data transfer is a write of the register address to the accelerometer (0x31) then a burst read of 6 bytes continuously. Each of these two transfers requires sending first the I2C device address and the R/W bit, as well as an ACK/NAK per byte, including the address bytes, as well as START/REPEAT START/STOP conditions. So, over all, an individual transfer to get a single sample (ie, a single XYZ acceleration vector) is as follows:

Start (*) | Device Address: 0x1D (7) | Write: 0 (1) | ACK (1) | Register Address: 0x31 (8) | ACK (1) | Repeat Start (*) | Device Address: 0x1D (7) | Read: 1 (1) | ACK (1) | DATA0 (8) | ACK(1) | DATA1 (8) | ACK (1) | ... | DATA5 (8) | NAK (1) | Stop (*)

If we add all that up, we get 81+3 bits of data that need to be transmitted. Note first that the START, REPEAT START and STOP might not actually take a bits worth of time each but for simplicity we can assume they do. Note also that while the device address is only 7 bits, you always need to postpend the READ/WRITE bit, so an I2C transaction is always 8 bits + ACK/NAK, so 9 bits in total. Note also, the I2C max transfer rate really defines the max SCK speed the device can handle, so in fast mode, the SCK is at most 400KHz (thus 400Kbps at most, but because of the protocol, you'll get less in real data). Thus, 84 bits at 400KHz means that we can transfer a sample in 0.21 ms or ~4700 samples/sec assuming no gaps or breaks in transmission.

Since you need to read 2 samples every 1ms (2 accelerometers, so 84 bits * 2 = 164 bits/sample or 164Kbps at 1KHz sampling rate), this should at least be possible for fast mode I2C. However, you will need to be careful that you are taking full use of the I2C controller. Depending on the software layer you are working on, it might be difficult to issue I2C burst reads fast enough (ie, 2 burst read transactions within 1ms). Using the FIFO on the accelerometer would significantly help the latency requirement, meaning instead of having 1ms to issue two burst reads, you can delay up to 32ms to issue 64 burst reads (since you have 2 accelerometers); but since you need to issue a new burst read to read the next sample, you'll have to be careful about the delay introduced by software between calls to whatever API youre using to perform the I2C transactions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.