cancel
Showing results for 
Search instead for 
Did you mean: 

HAL I2C Transmit then Receive without a stop between

SnoZek
Associate II

Hello,

I’m using an STM32WBA65 and trying to communicate with a peripheral (PTX30W) over I2C1.

The peripheral requires the following I²C sequence:

 
STARTWRITE → REPEATED STARTREAD → STOP

However, using HAL_I2C_Master_Transmit() followed by HAL_I2C_Master_Receive() does not work, because both HAL functions generate a STOP condition, and the PTX30W does not accept a STOP between the write and read phases.

On STM32WBA, I don’t see a HAL equivalent of HAL_I2C_Master_TransmitReceive() that would allow a repeated START without a STOP in between.

My questions are:

  • Is there a way to achieve a WRITE + REPEATED START + READ sequence using the HAL on STM32WBA?

  • Or is the correct approach to switch to the LL (Low Layer) I2C driver to get finer control over START/STOP conditions?

Any guidance or best practices for this use case would be appreciated.

Thanks in advance.


here is the i2c protocol :

SnoZek_0-1766073089303.png

3 REPLIES 3
TDK
Super User

Use HAL_I2C_Mem_Read to write 1-2 bytes, then read a bunch, using a repeated start.

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

@TDK wrote:

Use HAL_I2C_Mem_Read to write 1-2 bytes, then read a bunch, using a repeated start.


@Emil Damkjaer PETERSEN @Loic CHOSSAT this is particularly poorly described in the HAL documentation:

AndrewNeil_0-1766076967189.png

https://www.st.com/resource/en/user_manual/um3140-description-of-stm32wba-hal-and-lowlayer-drivers-stmicroelectronics.pdf#page=327

 

I really don't think it's at all clear from this description that "MEM" is the one to use in this application?

 

Please can we have a clear description like @TDK's in the HAL manuals - this kind of question comes up frequently on the forum!

I suspect that most applications where HAL_I2C_Mem_Read is the correct choice are not actually "memory" devices - as is the case here.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User

I think the HAL_I2C_Mem_Read naming is appropriate. Most uses of this are for actual memory addresses or register analogs. For example, accelerometers and other sensors, EEPROMs, LCD character displays. Just my opinion.

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