Skip to main content
Graduate II
August 7, 2024
Solved

I2C with repeated start condition example

  • August 7, 2024
  • 2 replies
  • 3362 views

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

    This topic has been closed for replies.
    Best answer by Saket_Om

    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:

    2 replies

    Saket_OmAnswer
    Technical Moderator
    August 7, 2024

    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:

    DS.4Author
    Graduate II
    August 7, 2024

    @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!

    Technical Moderator
    August 7, 2024

    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.

    DS.4Author
    Graduate II
    August 7, 2024

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