NRF52840 Eval Kit User Manual
CHAPTER 7. I2C
In this chapter, we will learn about how to use the I2C interface of NRF52840. There
are three examples, which are used here: 006_I2C(Scan Device), 007_I2C(BME280),
008_I2C(MPU6050 3D COUBE)
SCANNING SLAVE DEVICES
It keeps scanning the slave device address of those devices which are connected to
I2C bus.
for(address=1; address<=TWI_ADDRESSES; address++)
{
err_code
= nrf_drv_twi_rx(&m_twi, address, &sample_data,
sizeof(sample_data));
if
(err_code
{
detected_device
device_address
NRF_LOG_INFO("TWI device detected at address
address);
NRF_LOG_FLUSH();
}
}
The code will scan slave devices address connected and print them.
READ DATA FROM BME280
BME280 is a module from Bosch that supports sense environmental temperature,
humidity and barometric pressure.
Write/read function from Bosch:
int8_t user_i2c_read(uint8_t
*reg_data,
uint16_t
Vision: V1.0.1 Date: 2019.01.19
== NRF_SUCCESS)
= true;
= address;
https://github.com/BoschSensortec/BME280_driver
dev_id,
len)
0x%x.",
uint8_t
reg_addr,
uint8_t
33 / 72