cancel
Showing results for 
Search instead for 
Did you mean: 

NACK when reading a register through I2C communication

Tung Nguyen
Associate II
Posted on July 07, 2018 at 04:41

Hi, 

I'm having trouble reading a register in a slave through I2C communication. 

Slave: bq25895 

http://www.ti.com/lit/ds/symlink/bq25895.pdf

In main:

while (1){

   HAL_StatusTypeDef status

=

HAL_OK

;

   uint16_t

return_value

=

0

;

   status

=

HAL_I2C_Mem_Read

(&

hi2c1

,

0xD4

,

(

uint16_t

)(0x07)

,

I2C_MEMADD_SIZE_8BIT

,

&

return_value

,

1

,

1000

);

   

if

(

status

!=

HAL_OK

)

{

printf ('Error');

}

   else {printf ('No error');}

}

Problem: The I2C_FLAG_AF is set since there is no ACK from the slave. 

Tracing the problem down: 

/* Send Slave Address and Memory Address */

if (I2C_RequestMemoryRead(hi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)

/* Wait until TXIS flag is set */

if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, Tickstart) != HAL_OK)

/* Check if a NACK is detected */

if (I2C_IsAcknowledgeFailed(hi2c, Timeout, Tickstart) != HAL_OK)

/* Check if NACK is set inside of 

I2C_IsAcknowledgeFailed

() */

if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF) == SET)

How do I fix this problem? 

I'm new to this whole thing, so I appreciate any helps. 

Thanks. 

#nack #bq25895
1 ACCEPTED SOLUTION

Accepted Solutions
Tung Nguyen
Associate II
Posted on July 08, 2018 at 17:29

Hey guys,

Thanks. I figured out the problem. It weren't the software problem, but the hardware. Apparently, the master board had some problem with it, so there was no ACK. I changed to an application board from TI and got the ACK. I'll talk to an electrical engineer on Monday to fix the old board. 

Appreciate all your helps. 

View solution in original post

5 REPLIES 5
Posted on July 07, 2018 at 13:41

Top-of-the-head questions:

0. Are the required pull-up resistors installed on the I2C signals?

1. Do you know for certain that your call to HAL_I2C_Mem_Read() results in I2C activity?  (via a scope or logic analyzer)

2. Section 8.3.1 in the bq Data Sheet indicates the device wakes up in 'Default Mode' and requires an I2C write and some bit twiddling to get (and stay) in 'Host Mode'.  Are you doing this write?  (I didn't study the Data Sheet to try to determine if I2C reads attempted before it's in Host Mode will be NACKed or not - that kind of annoyance would be just like TI.)

Posted on July 07, 2018 at 19:53

0. Yes. On the master (STM32F746), there are pull-up resistors installed on the SDA and SCL pin before connecting to the slave (bq25895). 

1.  What steps do you need to go through to set up the scope to measure I2C? How do you know if your measurement indicate I2C activity? 

2. No, I did not do the write. I did not see any mentions about putting the master in host mode before reading through I2C. But good point, let me confirm with TI.

Thanks David.  

Posted on July 08, 2018 at 01:45

Use the scope trigger on the clock SCLK pin.

then try to show both SDA and SCLK at the same time.

sometimes you have to twiddle the HOLD-OFF to longer than the byte time...

are you shifting the address up one bit ?

The first  time I used IIC on STM, the whole thing was running in a few hours... ST has done a great job really...

Tung Nguyen
Associate II
Posted on July 08, 2018 at 17:29

Hey guys,

Thanks. I figured out the problem. It weren't the software problem, but the hardware. Apparently, the master board had some problem with it, so there was no ACK. I changed to an application board from TI and got the ACK. I'll talk to an electrical engineer on Monday to fix the old board. 

Appreciate all your helps. 

Hi Tung Nguyen,

I also get stuck same you, but I use BQ7411 and no ACK when I debug at I2C_IsAcknowledgeFailed. Could you send me the code example?

Thank you.