This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52832 + LIS2DH12 : Issue using I2C : no address acknowledge (NACK) received

Hi !

I'm using the nrf52832 chip and I'm trying to communicate with a LIS2DH12 accelerometer using the I2C protocol.

But unfortunately I can't handle with it, it seems that the accelerometer doesn't respond at his adress...

So first here is my hardware connections : 

The pin are connected as follow to the nrf52832 : 

SDA - P0.14

SCL - P0.15

As said in the LIS2DH12 datasheet, the SD0 pin is connected to the supply voltage so the I2C address of the accelerometer is 0x19.

Here are the relevant firmware parts : 

1) Address of the LIS2DH12

Fullscreen
1
2
3
4
/* TWI instance ID. */
#define TWI_INSTANCE_ID 0
/* Common addresses definition for temperature sensor. */
#define C_ACCELEROMETER_I2C_ADDR 0x19
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

2) twi_handler() and twi_init()

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* @brief TWI events handler.
*/
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
switch (p_event->type)
{
case NRF_DRV_TWI_EVT_DONE:
if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
{
data_handler(m_sample);
}
m_xfer_done = true;
break;
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
break;
case NRF_DRV_TWI_EVT_DATA_NACK:
break;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

So as you can see, I've just followed the nordic example (twi_sensor).

But when I try to configure the accelerometer with this function : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* @brief Function for LIS2DH accelerometer config.
*/
void fn_configure_LIS2DH_accelero(void)
{
ret_code_t err_code;
//lire who i am
m_xfer_done = false;
uint8_t reg2[2] = {C_WHO_AM_I, 0x00};
err_code = nrf_drv_twi_tx(&m_twi, C_ACCELEROMETER_I2C_ADDR, reg2, 1, true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
m_xfer_done = false;
/* Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. */
err_code = nrf_drv_twi_rx(&m_twi, C_ACCELEROMETER_I2C_ADDR, m_sample_axis, 1);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The program get stuck in the first while loop : 

Fullscreen
1
while (m_xfer_done == false);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And using a breakpoint, I can see that the twi_handler() is called because an NRF_DRV_TWI_EVT_ADDRESS_NACK event is rised.

So it seems that the lis2dh12 does not respond...

I tried to "scan" every adresses from 1 to 126 and for each I receive the same event : NRF_DRV_TWI_EVT_ADDRESS_NACK

Is there a configuration that I forgot ? Maybe the SDA and SCL pins needs to an internal pull-up ?

I don't understand, so if someone could help me, it would be great !

Thank you !!

Olivier