cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMx V1.00 Version 4.4.0 Howto send I2C read/writes with stop control

gerrie
Associate
Posted on February 02, 2015 at 22:23

It is not very clear how the HAL handles the start / write/read / stops.

I am use to the following I2C sequence

<start> < address> <r/w> < wrdata> <stop> this seem to fine using

if (HAL_I2C_Master_Transmit_IT(&hi2c1, (uint16_t)address, (uint8_t*)write_data, (uint16_t)length)!= HAL_OK) ...

But sometimes one need to  read a register  .. two cycles

<start> < address><r/w> < register>    /// no stop  (sequence 1)

< Rddata> <stop>                                    /// no start .(sequence 2)

How is this done using the HAL ?

#i2c #cubemx
1 REPLY 1
Posted on February 26, 2015 at 15:58

Hi de_jager.gerrie,

If my understanding is good, for your need to read a word data (mean 2 bytes expand by MSB+LSB bytes), you can use the same interface package that you have already use but change the length and set it to “2�.

Mean that you will read or write 2 bytes in the same sequence START + Slave Address + R/W bit + ACK + Data1 + Data2 + ACK + STOP.

So to make some function usage on this explanation :

 1- If you want to write/send data to a slave device prefer to use => HAL_I2C_Master_Transmitxx() interface

 2- If you want to read/receive data to a slave device prefer to use => HAL_I2C_Master_Receivexx() interface

Hope that help,

Regards,

Heisenberg.