Skip to content
Snippets Groups Projects
Commit 423c7c84 authored by fteso's avatar fteso Committed by Federico
Browse files

Found undefined behavior in functions static unsigned char recvWithAck() and...

Found undefined behavior in functions static unsigned char recvWithAck() and static unsigned char recvWithNack(). In some cases the MSB bit of the incoming byte was read 0 instead 1 because the sampling of the SDA line was made too early. Solved adding delayUs()
parent 7c2ddc72
Branches
No related tags found
No related merge requests found
...@@ -164,9 +164,11 @@ unsigned char SoftwareI2C<SDA, SCL, stretchTimeout>::recvWithAck() ...@@ -164,9 +164,11 @@ unsigned char SoftwareI2C<SDA, SCL, stretchTimeout>::recvWithAck()
{ {
SDA::high(); SDA::high();
unsigned char result=0; unsigned char result=0;
delayUs(3);
for(int i=0;i<8;i++) for(int i=0;i<8;i++)
{ {
result<<=1; result<<=1;
if(SDA::value()) result |= 1; if(SDA::value()) result |= 1;
delayUs(3); delayUs(3);
SCL::high(); SCL::high();
...@@ -190,9 +192,11 @@ unsigned char SoftwareI2C<SDA, SCL, stretchTimeout>::recvWithNack() ...@@ -190,9 +192,11 @@ unsigned char SoftwareI2C<SDA, SCL, stretchTimeout>::recvWithNack()
{ {
SDA::high(); SDA::high();
unsigned char result=0; unsigned char result=0;
delayUs(3);
for(int i=0;i<8;i++) for(int i=0;i<8;i++)
{ {
result<<=1; result<<=1;
if(SDA::value()) result |= 1; if(SDA::value()) result |= 1;
delayUs(3); delayUs(3);
SCL::high(); SCL::high();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment