2015-02-02 01:23 PM
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 #cubemx2015-02-26 06:58 AM
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() interfaceHope that help,Regards,Heisenberg.