-
Notifications
You must be signed in to change notification settings - Fork 1k
Handle I2C scan with specific call to HAL_I2C_IsDeviceReady #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
works on the bluepill board (stm32f103c8t6) i tested the i2c scanner and 5 different sensors on both i2c1 and i2c2, works flawlessly |
works on stm32f103vet6 too (i made a custom board in the selection menu) |
Please add to this PR also the scanner sketch that you are used (under Wire library examples). Thanks a lot for your work |
@nikisalli would you mind pushing your proposed scanner sketch in a dedicated PR to help @Testato ? |
PR with the scanner , tested an all three I2c for a Bluepill |
hi @LMESTM , thanks for the patch. I just tested, using an arduino UNO as slave (standard test sketch), and on a discovery stm32f407 |
@MauroMombelli Have you added pull up resistors on the I2C lines ? |
This PR Will Fix #298 |
@LMESTM for sure the arduino is using its internal by default, not sure about this core. I can add some 4.7kohm resistor instead if you think this is the issue, but i don't see why it should work when i reboot the stm; technically any new scan should be completely independent from previous status of the bus, and leaving the system connected for a couple of scan should see the slave without need to reboot. |
@MauroMombelli without pull-up resistors, plugging / unplugging the boards will lead to falling edges of the I2C lines which could lead to undesired behavior or possible lock-up of the bus. |
aren't the timeout there to avoid this issue? |
I meant this probably leads to HW lock up ... so the need to reset the STM32. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One typo to fix.
Thanks
cores/arduino/stm32/twi.c
Outdated
@@ -355,6 +355,11 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address, | |||
uint32_t tickstart = HAL_GetTick(); | |||
uint32_t delta = 0; | |||
|
|||
/* When size is 0, this is usually a I2C scan / ping to check if device is there and ready */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an I2C scan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok done
When size is 0, the objective is to check if device is there and ready. A typical use case is to scan through all addresses to check for available slaves. So we're checking the various error cases to report to application.
Handle I2C scan with specific call to HAL_I2C_IsDeviceReady
Description
When size is 0, the objective is to check if device is there and ready.
A typical use case is to scan through all addresses to check for
available slaves.
So we're checking the various error cases to report to application.
Tests
I've run successfully the example sketch from #298 on:
NUCLEO_F429ZI
NUCLEO_F411RE
DISCO L475 IOT