cancel
Showing results for 
Search instead for 
Did you mean: 

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

Kamil Duljas
Senior III

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).

Dudo
1 ACCEPTED SOLUTION

Accepted Solutions
Kamil Duljas
Senior III

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

View solution in original post

6 REPLIES 6
Diane POMABIA
ST Employee

Hi @Kamil Duljas​ 

What STM32 Microcontroller are you using ?

Regards

Diane

Nucleo f756​

Dudo
Bob S
Principal

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?

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 Duljas
Senior III

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

Hello @Kamil Duljas​ ,

I recommend you check the I2C examples in the STM32F7 Cube FW :

Git : GitHub - STMicroelectronics/STM32CubeF7: STM32Cube MCU Full Package for the STM32F7 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))

You can refer too to the I2C WIKI : Getting started with I2C - stm32mcu

Hope my answer helped you!

Foued

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.