Minimal HAL Code to connection I2C1 and I2C2 on one board in pooling mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-27 5:10 AM
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).
Solved! Go to Solution.
- Labels:
-
I2C
-
STM32F7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-28 1:15 AM
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 :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-27 5:23 AM
Hi @Kamil Duljas​
What STM32 Microcontroller are you using ?
Regards
Diane
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-27 5:28 AM
Nucleo f756​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-27 7:04 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-27 7:12 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-04-28 1:15 AM
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 :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-02 2:44 AM
Hello @Kamil Duljas​ ,
I recommend you check the I2C examples in the STM32F7 Cube FW :
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.
