stevemarple / SoftWire

Software I2C implementation for Arduino and other Wiring-type environments
GNU Lesser General Public License v2.1
136 stars 31 forks source link

Problem with handling of timeout #11

Closed Phonog closed 3 years ago

Phonog commented 4 years ago

I have implemented a I2C master on a STM32F103 and it works correctly. However, while performing tests, I did an experiment: I shorted the scl line to ground, to see whether this was correctly handled. My application then crashed. After a long examination, I found that in such a case there is an infinite indirect recursion, thus the crash. The problem lies in the function sclHighAndStretch. In case of a timeout, it calls the function stopwhich itself calls sclHighAndStretch. We need a way to break this recursion. I see two ways:

PS : advice : in the description of the library, it would be useful to specify that the user needs to supply a read and a write buffer at initialisation time. I had a hard time figuring out what was wrong until I discovered this. I used to use a library from Roger Clark's package that was very close, but that did not require buffers to be supplied, so I was not aware of the need of buffers.

stevemarple commented 3 years ago

I've pushed a new version which I believe fixes this problem. I've used one of the methods you suggested and have credited you as a contributor.

Another user also highlighted the need to configure buffers. I have added a new example which shows this and also improved the README.

Many thanks.