10-30-2020 11:11 AM
In section "6.1 Data registre shadowing", it is stated that the end of the burst read for I2C is marked by a STOP condition. I would like to know if a NACK after reading the last byte will allow the updating of the data registre.
Normally, I understand an I2C stop condition as the action where the master releases the I2C bus (i.e. SCL high, SDA low to high).
I post this question, as I would like to read the data 2 times (or more) without allowing the BME280 to update the data registre. This will allow me to continue reading until I get repeated identical readings (hence ensuring that the readout is correct).
This requires that I burst read the data and then retransmits the start address (0xF7) before burst reading the data again. Here a NACK is sent after reading the last byte, but the bus is not released (it is repeat started). I do however think that the NACK allows the BME280 to update the data registre. Is this correct?
Solved! Go to Solution.
10-30-2020 06:50 PM
In formal I2C spec, the burst read action is terminate by the STOP. But for the slave, when the read transmit is finished with requested bytes, it will send NACK. then host can send STOP. this means slave here is expect a STOP instead of START signal.
Your intend action is violating the I2C spec.
So i can't say how sensor will react to this. Most probably sensor I2C module will return error and ignore this START signal.
If you are wondering your I2C read is correct or not, you can try to read sensor chip id twice. this contains constent value, so you should read out everytime with same value.
If you are wondering if BME280 data is correct or not, you can read out register value, use API to convert to physical value. then compare to reference device to see BME280 output is reasonable or not.
11-02-2020 03:39 PM
It is my understanding that repeat start is allowed by the I2C protocol. Please see:
3.1.10 The slave address and R/W bit
Data transfers follow the format shown in Figure 9. After the START condition (S), a slave
address is sent. This address is seven bits long followed by an eighth bit which is a data
direction bit (R/W) — a ‘zero’ indicates a transmission (WRITE), a ‘one’ indicates a
request for data (READ) (refer to Figure 10). A data transfer is always terminated by a
STOP condition (P) generated by the master. However, if a master still wishes to
communicate on the bus, it can generate a repeated START condition (Sr) and address
another slave without first generating a STOP condition. Various combinations of
read/write formats are then possible within such a transfer.
This section is copied from "https://www.nxp.com/docs/en/user-guide/UM10204.pdf".
I think the idea of the repeat start is that the master can keep using the bus and in princip read other sensors. Here I just want to read the data 2 times to ensure that the data transfer is correct.
Please let me know If my interpretation of the I2C bus protocol is incorrect. In this case, I would like to see a reference that says repeat start after a burst read is prohibited.
If my interpretation of the I2C protocol is correct, then please let me know if the BME280 updates its data registre after a NACK (i.e. before the master releases the bus, but after the burst read ends).
11-02-2020 11:39 PM
At least from my point of view, your interpretation is not very accurate.
SO overall burst read on slave side should be START + device address + register address | read action + REPEAT START + burst read data + NACK + STOP.
Within this timing digram, the register address is increased by 1 automatically on slave side.
This means on slave side, the NACK means the burst read is finished, auto increasement of address is also finished. then STOP expected to next read / write action. For internal logic, the lock of shadow register is also finished. new data will be copied into data register directly.
If you send REPEAT START intead of STOP plus a new register address, it is obviously violate the time digram of our datasheet.
Thus, i can't gurantee if sensor can act as your expected.
11-03-2020 07:42 AM
Thanks for your answer.
I would just like to be 100% sure. During a burst read, when the master-reciever sends a NACK (hence ending the read burst), the BME280 will stop the shadowing of the data registres (i.e. before the master sends a STOP)?