Skip to content
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

Handle I2C scan with specific call to HAL_I2C_IsDeviceReady #301

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

LMESTM
Copy link
Member

@LMESTM LMESTM commented Aug 10, 2018

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

@fpistm fpistm added bug 🐛 Something isn't working review on going labels Aug 10, 2018
@fpistm fpistm added this to the 1.3.1 milestone Aug 10, 2018
@nikisalli
Copy link

works on the bluepill board (stm32f103c8t6) i tested the i2c scanner and 5 different sensors on both i2c1 and i2c2, works flawlessly

@nikisalli
Copy link

works on stm32f103vet6 too (i made a custom board in the selection menu)

@Testato
Copy link
Contributor

Testato commented Aug 10, 2018

Please add to this PR also the scanner sketch that you are used (under Wire library examples).

Thanks a lot for your work

@LMESTM
Copy link
Member Author

LMESTM commented Aug 10, 2018

@nikisalli would you mind pushing your proposed scanner sketch in a dedicated PR to help @Testato ?

@Testato
Copy link
Contributor

Testato commented Aug 10, 2018

PR with the scanner , tested an all three I2c for a Bluepill
#303

@MauroMombelli
Copy link

hi @LMESTM , thanks for the patch. I just tested, using an arduino UNO as slave (standard test sketch), and on a discovery stm32f407
Result: if while scanning i connect the arduino, it does NOT get seen. If i reboot the STM will see the arduino without problem. At least during one disconnection the i2c hanged.

@LMESTM
Copy link
Member Author

LMESTM commented Aug 13, 2018

PR with the scanner , tested an all three I2c for a Bluepill
#303

Thanks @Testato

@LMESTM
Copy link
Member Author

LMESTM commented Aug 13, 2018

hi @LMESTM , thanks for the patch. I just tested, using an arduino UNO as slave (standard test sketch), and on a discovery stm32f407
Result: if while scanning i connect the arduino, it does NOT get seen. If i reboot the STM will see the arduino without problem. At least during one disconnection the i2c hanged.

@MauroMombelli Have you added pull up resistors on the I2C lines ?

@fpistm
Copy link
Member

fpistm commented Aug 13, 2018

This PR Will Fix #298

@MauroMombelli
Copy link

@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.
My idea is once in "error 1" it never really reset completely the communication and will always return error.

@LMESTM
Copy link
Member Author

LMESTM commented Aug 14, 2018

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

@MauroMombelli
Copy link

possible lock-up of the bus

aren't the timeout there to avoid this issue?

@LMESTM
Copy link
Member Author

LMESTM commented Aug 14, 2018

I meant this probably leads to HW lock up ... so the need to reset the STM32.
You may try out using internal pull-up on I2C lines of STM32 as well ... even though this is not the recommended configuration (recommendation is external pull-up resistors)

@fpistm fpistm self-requested a review September 3, 2018 15:56
@fpistm fpistm added the fix 🩹 Bug fix label Sep 3, 2018
Copy link
Member

@fpistm fpistm left a 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

@@ -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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an I2C scan

Copy link
Member Author

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.
@fpistm fpistm merged commit e17c30e into stm32duino:master Sep 4, 2018
benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this pull request Apr 10, 2019
Handle I2C scan with specific call to HAL_I2C_IsDeviceReady
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working fix 🩹 Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants