NRF52840 Eval Kit User Manual
Vision: V1.0.1 Date: 2019.01.19
33
/
72
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
==
NRF_SUCCESS
)
{
detected_device
=
true
;
device_address
=
address
;
NRF_LOG_INFO
(
"TWI device detected at address 0x%x."
,
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:
https://github.com/BoschSensortec/BME280_driver
int8_t
user_i2c_read
(
uint8_t
dev_id
,
uint8_t
reg_addr
,
uint8_t
*
reg_data
,
uint16_t
len
)