cancel
Showing results for 
Search instead for 
Did you mean: 

I2C with repeated start condition example

DS.4
Senior II

HI

Got an I2C device connected to my p nucleo wb 55 board. currently no luck communicating.

I've been instructed to to use a  repeated start condition in I2C   https://www.i2c-bus.org/repeated-start-condition/

Not sure if my current   HAL functions work for an I2C repeated start condition device? they are :

HAL_I2C_Mem_Write XXX

HAL_I2C_Master_Transmit XXX 

 

Any other example I can use ?

 

need to achieve this :

DS4_0-1723014680800.png

 

S start

R restart

 

THNAKS

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello @DS.4 

 

To achieve a repeated start condition with your I2C device, you will need to use specific HAL functions that support repeated start conditions. The functions you mentioned (HAL_I2C_Mem_Write and HAL_I2C_Master_Transmit) do not support repeated start conditions.

For repeated start conditions, you should use the following HAL functions:

  • HAL_I2C_Master_Sequential_Transmit_IT
  • HAL_I2C_Master_Sequential_Receive_IT

These functions are designed to handle sequential transmit and receive operations, which include the capability to perform repeated start conditions.

Please refer to these examples for farther more details:

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

View solution in original post

4 REPLIES 4
Saket_Om
ST Employee

Hello @DS.4 

 

To achieve a repeated start condition with your I2C device, you will need to use specific HAL functions that support repeated start conditions. The functions you mentioned (HAL_I2C_Mem_Write and HAL_I2C_Master_Transmit) do not support repeated start conditions.

For repeated start conditions, you should use the following HAL functions:

  • HAL_I2C_Master_Sequential_Transmit_IT
  • HAL_I2C_Master_Sequential_Receive_IT

These functions are designed to handle sequential transmit and receive operations, which include the capability to perform repeated start conditions.

Please refer to these examples for farther more details:

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
DS.4
Senior II

@Saket_Om  thanks! just 2 follow up questions:

 

Can I set/configure the sequential transmit

  • HAL_I2C_Master_Sequential_Transmit_IT

to behave as the regular ones I use :

  • HAL_I2C_Master_Sequential_Transmit_IT
  • HAL_I2C_Master_Sequential_Receive_IT

Is it possible?

Also what is the difference between the projects:

?

 

Thanks!

Hello @DS.4 

 

>> Can I set/configure the sequential transmit

  • HAL_I2C_Master_Sequential_Transmit_IT

to behave as the regular ones I use :

  • HAL_I2C_Master_Sequential_Transmit_IT
  • HAL_I2C_Master_Sequential_Receive_IT

Is it possible?

 

I didn't understand your question. If you want to say configure HAL_I2C_Master_Sequential_Transmit_IT to behave like HAL_I2C_Master_Transmit_IT, my answer is yes. You need to set the XferOptions argument to I2C_FIRST_AND_LAST_FRAME. This setting ensures that the transfer is treated as a single transaction, similar to how HAL_I2C_Master_Transmit_IT operates.

Please refer to this post for more details. 

 

The difference between the two examples is that the first one uses the sequential API to send and receive simple data between two boards, while the second one uses the sequential API to send and receive commands between two boards. Please see the readme files for more details.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

@Saket_Om Thanks for the quick answer, you are the best!