cancel
Showing results for 
Search instead for 
Did you mean: 

I2C detect repeated start condition

sigmuha
Visitor

Hi!

I'm creating an i2c-slave using a stm32g0-series. There are two types of messages that need to be supported, a write-then-read, and a write-only.

The write-then-read starts with a write-message of a register address of the slave device (1 byte). This is followed by a repeated start condition where the master writes the data to the register address.     

The write-only starts in the same manner, but in addition to the register-address, a number of bytes (depending on the register) are also written to the slave. 

IFAIK these are fairly common ways to do reads and writes. 

The write-then-read messages work fine with the use of HAL_I2C_Slave_Seq_Receive_IT (receive one byte) and HAL_I2C_Slave_Seq_Transmit_IT (transmit n bytes). 

My problem arises when the first message (write) can either be one byte (write-then-read) or multiple bytes (write-only). The way I see it, I either have to detect if the repeated start condition has happened (one byte has been sent), or I need to expect more bytes than I potentially can receive and handle an error if fewer bytes were received... both of them don't seem possible to do.

Is there any way of handling both of these message types in the STM32 HAL library?

1 REPLY 1
TDK
Guru

If a multiple-byte write is possible, call HAL_I2C_Slave_Seq_Receive_IT using the largest message size expected.

A repeated start does not generally occur if multiple bytes are being sent. I haven't seen a chip that supports of expects that.

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