cancel
Showing results for 
Search instead for 
Did you mean: 

Changing I2C reading mode

Fin95
Visitor

Hi,

 

I am trying to create the I2C communication using the format used from the company seller of the device.
I have to follow these steps:

I2CReadFunciton ( uint8_t slAddr,

uint8_t* wrData, int wrLen,

uint8_t* rdData, int rdLen

  1. Initiate the bus by issuing a START condition.

  2. If there are bytes to write (wrLen > 0):

    • Address the target device with its slave address in write mode.
    • Transmit the wrLen bytes contained in wrData.
    • Without releasing the bus (i.e., do not send a STOP), issue a REPEATED START to transition into the read phase.
  3. Begin the read phase:

    • Address the same device with its slave address in read mode.
    • Receive rdLen bytes, storing them sequentially into rdData.
  4. Terminate the transaction with a STOP condition.

Key constraints:

  • If a write phase occurs, it must be immediately followed by a repeated startno STOP is allowed between the write and the subsequent read.
  • The read always occurs after either the initial START (if no write) or the repeated START (if a write was performed).

 

My problem is how to not have the stop condition in the write function using the HAL functions.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

Please include your full chip part number in your posts.

What device are you interfacing with?

 

HAL_I2C_Mem_Read will issue a write then a read with a repeated-start condition. Perhaps use that or look there to see how it is done.

stm32f4xx-hal-driver/Src/stm32f4xx_hal_i2c.c at b0c13b119171025ac8e47d9028032fb7b7f6fd6d · STMicroelectronics/stm32f4xx-hal-driver

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

View solution in original post

1 REPLY 1
TDK
Super User

Please include your full chip part number in your posts.

What device are you interfacing with?

 

HAL_I2C_Mem_Read will issue a write then a read with a repeated-start condition. Perhaps use that or look there to see how it is done.

stm32f4xx-hal-driver/Src/stm32f4xx_hal_i2c.c at b0c13b119171025ac8e47d9028032fb7b7f6fd6d · STMicroelectronics/stm32f4xx-hal-driver

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