cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 HAL_I2C_Master_Transmit not sending correct byte sequence STM32F407

LPetr.1
Senior

I am writing an I2C driver on STM32F407 for the following IC:

https://www.ti.com/lit/ds/symlink/ads7828.pdf

Page 12 describes how to properly communicate with the device.

0693W00000LxwzdQAB.png 

A1 = 1

A0 = 1

SD = 1

C2 = 0

C1 = 0

C0 = 0

PD1 = 1

PD0 = 1

2 last X bits dont matter so I just set them both to 0.

So according to the documentation and my configuration, I should transmit the following sequence to the I2C:

1 0 0 1 0 A1 A0 W ACK SD C2 C1 C0 PD1 PD0 X X ACK

So I send:

0b10010110 WAIT FOR ACK 0b10001100 WAIT FOR ACK

In my code, I call the following function:

uint8_t address_byte = 150;
	  uint8_t command_byte = 140;
		HAL_I2C_Master_Transmit(&hi2c2, address_byte, (uint8_t*)command_byte, 1, HAL_MAX_DELAY);

As you can see from above, I hardcoded address and command byte just for testing purposes:

I have connected logic analyzer to the I2C pins and see the following:

0693W00000LxxNzQAJ.png 

Which is not correct. I expect to see 150+ack and 140+ack but instead I see 75+ack and 181 + ack.

My I2C configuration on CubeMX:

0693W00000LxxRhQAJ.png 

2 REPLIES 2
Pavel A.
Evangelist III

Check return value of HAL_I2C_Master_Transmit.

If it is HAL_OK, the device likely replied ACK after the address, then the issue is with your analyzer. Else ...

TDK
Guru

> 150+ack and 140+ack but instead I see 75+ack and 181 + ack.

150 is 2*75. The 7-bit address (reported by the scope) is 75, while the 8-bit address is 150. No issues with this byte. Datasheets vary between specifying 7-bit or 8-bit (7bit shifted left by one bit plus R/W bit) addresses.

Not sure on the second bit. Micros are not prone to erratic behavior. There is certainly an explanation somewhere.

If you feel a post has answered your question, please click "Accept as Solution".