cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Master Sequential function

YDann.7
Associate III

Dear,

I currently use a STM32G070 with external touch sensor component usuing I2C interface.

This component aloow me to communicate with it only during a ready window and this window is automatically closed after a delay without communication or a I2C STOP.

So, I try to communicate multiple time during this window (transmit and/or receive) using "HAL_I2C_Master_Seq_Transmit_IT" and "HAL_I2C_Master_Seq_Receive_IT" function.

The I2C frames are always composed of 2 step:

  • read: Transmit register address (HAL_I2C_Master_Seq_Transmit_IT) + Receive data (HAL_I2C_Master_Seq_Receive_IT)
  • write Transmit register address (HAL_I2C_Master_Seq_Transmit_IT) + Transmit data (HAL_I2C_Master_Seq_Transmit_IT)

In both case, when I transmit the register address, I use the "I2C_FIRST_FRAME" option.

For the second command, I use "I2C_LAST_FRAME" or "I2C_LAST_FRAME_NO_STOP" option depending if I must close the communication or not.

The first command is always sending in background task of my firmware and the second is send during the "HAL_I2C_MasterTxCpltCallback" interrupt callback.

But I have a problem to a read - read - write - read sequence (always without I2C stop). All i OK for the read - read sequence but for the write, I always have only the register address and not the data. And I don't have the next read sequence.

Maybe I don't use the right options but I don't know.

0693W00000JPpzuQAD.png

5 REPLIES 5
YDann.7
Associate III

Nobody have an idea for my problem ?

YDann.7
Associate III

Nobody know how to use I2C sequencial functions ?

YDann.7
Associate III

A little more information.

If I use "I2C_FIRST_AND_NEXT_FRAME" option with the first step for the write sequence ("HAL_I2C_Master_Seq_Transmit_IT" function), the data are send but I not able to make another write sequence.

If I check into the HAL librairy in the "HAL_I2C_Master_Seq_Transmit_IT", I see a difference in the I2C registers just after the call of "I2C_TransferConfig" between the 2 options (even if the parameters are the same).

The ISR register is different.

With the "I2C_FIRST_FRAME" option, I directly have the STOPF bit flag (STOP detection flag).

With the "I2C_FIRST_AND_NEXT_FRAME" option, I have the TXIS bit flag (Transmit interrupt status) and the STOPF is only set when the data have been send.

S.Ma
Principal

Clearly HW I2C would benefit with a richer examplensuch as true I2C complete transaction, including optional sub adress, block writr option, optional restart with read block option and stop. To me most device work like this. Timeouts in slaves are probably power sleep saving techniques.

YDann.7
Associate III

I agree, the I2C need to have more examples. But ST give only example for basic usage of the peripherals.

I changed the way to communicate with my component.

It work a little bit like an EEPROM so I use the "HAL_I2C_Mem_Write_IT" and "HAL_I2C_Mem_Read_IT" functions to write and read.

But, instead of sending many I2C frames into a communication window, I need many communication window (one by I2C frame) and I lose time.