Skip to content

Commit b5a8788

Browse files
author
ficeto
committed
fix I2C
1 parent 3178e06 commit b5a8788

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_si2c.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ unsigned char twi_writeTo(unsigned char address, unsigned char * buf, unsigned i
150150
if(!twi_write_byte(buf[i])) return 3;//received NACK on transmit of data
151151
}
152152
if(sendStop) twi_write_stop();
153+
i = 0;
154+
while(SDA_READ() == 0 && (i++) < 10){
155+
SCL_LOW();
156+
twi_delay(twi_dcount);
157+
SCL_HIGH();
158+
twi_delay(twi_dcount);
159+
}
153160
return 0;
154161
}
155162

@@ -158,15 +165,13 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
158165
if(!twi_write_start()) return 4;//line busy
159166
if(!twi_write_byte(((address << 1) | 1) & 0xFF)) return 2;//received NACK on transmit of address
160167
for(i=0; i<len; i++) buf[i] = twi_read_byte(false);
161-
if(sendStop){
162-
twi_write_stop();
163-
i = 0;
164-
while(SDA_READ() == 0 && (i++) < 10){
165-
SCL_LOW();
166-
twi_delay(twi_dcount);
167-
SCL_HIGH();
168-
twi_delay(twi_dcount);
169-
}
170-
}
168+
if(sendStop) twi_write_stop();
169+
i = 0;
170+
while(SDA_READ() == 0 && (i++) < 10){
171+
SCL_LOW();
172+
twi_delay(twi_dcount);
173+
SCL_HIGH();
174+
twi_delay(twi_dcount);
175+
}
171176
return 0;
172177
}

0 commit comments

Comments
 (0)