Skip to main content
Senior III
April 27, 2023
Solved

Minimal HAL Code to connection I2C1 and I2C2 on one board in pooling mode

Hi,

coudl someone paste simple code to send some bytes between I2C1 and I2C2 on one board?

Prefer HAL. I try this:

uint8_t data = 69;

 uint8_t data2 = 0;

 HAL_I2C_Master_Transmit(&hi2c1, 32, &data, 1, HAL_MAX_DELAY);

 HAL_I2C_Slave_Receive(&hi2c2, &data2,1,HAL_MAX_DELAY);

and

 HAL_I2C_Slave_Receive_IT(&hi2c2, &data2,1);

 HAL_I2C_Master_Transmit(&hi2c1, 32, &data, 1, HAL_MAX_DELAY);

but not works. Slave address is 16 (shift left is 32).

This topic has been closed for replies.
Kamil DuljasBest answer
Senior III
April 28, 2023

Ok I resolved my problem. In case of interrupt I mixed cables.

In case of pooling it does not make sense because Master transmit blocks and wait for ACK from Slave :)

Stupid mistake :)

Dudo

6 replies

ST Employee
April 27, 2023

Hi @Kamil Duljas​ 

What STM32 Microcontroller are you using ?

Regards

Diane

Senior III
April 27, 2023

Nucleo f756​

Dudo
Bob S
Super User
April 27, 2023

Your second set of code uses HAL_I2C_Slave_Receive_IT(), which returns immediately (BEFORE the data has been received). Either use HAL_I2C_Slave_Receive() - without the "_IT", or add code to handle the receive complete callback before calling transmit.

Are these in two separate RTOS tasks? Show your real code. Check the return values from the HAL calls. Are you sure the SCL pins are connected to each other and the SDA pins? Using a scope or logic analyzer do you see any clock/data on the pins?

Senior III
April 27, 2023

It's a Real code xD I need minimal example a minimal comunication I2C. I know that second example uses interrupt. If you know how communicate two instances I2C, show peace of HAL code :) it can be board agnostic. Just loopback I2C

Dudo
Kamil DuljasAuthorBest answer
Senior III
April 28, 2023

Ok I resolved my problem. In case of interrupt I mixed cables.

In case of pooling it does not make sense because Master transmit blocks and wait for ACK from Slave :)

Stupid mistake :)

Dudo
Foued_KH
ST Employee
May 2, 2023
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.