1
- /*
1
+ /*
2
2
si2c.c - Software I2C library for esp8266
3
3
4
4
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
5
5
This file is part of the esp8266 core for Arduino environment.
6
-
6
+
7
7
This library is free software; you can redistribute it and/or
8
8
modify it under the terms of the GNU Lesser General Public
9
9
License as published by the Free Software Foundation; either
@@ -26,10 +26,10 @@ unsigned char twi_dcount = 18;
26
26
static unsigned char twi_sda , twi_scl ;
27
27
28
28
#define SDA_LOW () (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
29
- #define SDA_HIGH () (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
29
+ #define SDA_HIGH () (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
30
30
#define SDA_READ () ((GPI & (1 << twi_sda)) != 0)
31
- #define SCL_LOW () (GPES = (1 << twi_scl))
32
- #define SCL_HIGH () (GPEC = (1 << twi_scl))
31
+ #define SCL_LOW () (GPES = (1 << twi_scl))
32
+ #define SCL_HIGH () (GPEC = (1 << twi_scl))
33
33
#define SCL_READ () ((GPI & (1 << twi_scl)) != 0)
34
34
35
35
#ifndef FCPU80
@@ -99,7 +99,7 @@ static bool twi_write_stop(void){
99
99
twi_delay (twi_dcount );
100
100
SDA_HIGH ();
101
101
twi_delay (twi_dcount );
102
-
102
+
103
103
return true;
104
104
}
105
105
@@ -166,7 +166,8 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
166
166
unsigned int i ;
167
167
if (!twi_write_start ()) return 4 ;//line busy
168
168
if (!twi_write_byte (((address << 1 ) | 1 ) & 0xFF )) return 2 ;//received NACK on transmit of address
169
- for (i = 0 ; i < len ; i ++ ) buf [i ] = twi_read_byte (false);
169
+ for (i = 0 ; i < (len - 1 ); i ++ ) buf [i ] = twi_read_byte (false);
170
+ buf [len - 1 ] = twi_read_byte (true);
170
171
if (sendStop ) twi_write_stop ();
171
172
i = 0 ;
172
173
while (SDA_READ () == 0 && (i ++ ) < 10 ){
0 commit comments