Skip to content

Commit c7a46bc

Browse files
committed
Merge pull request #554 from bbx10/tcs34725_patch
NACK last byte when read
2 parents 6e23468 + ad03594 commit c7a46bc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/*
22
si2c.c - Software I2C library for esp8266
33
44
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
55
This file is part of the esp8266 core for Arduino environment.
6-
6+
77
This library is free software; you can redistribute it and/or
88
modify it under the terms of the GNU Lesser General Public
99
License as published by the Free Software Foundation; either
@@ -26,10 +26,10 @@ unsigned char twi_dcount = 18;
2626
static unsigned char twi_sda, twi_scl;
2727

2828
#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)
3030
#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))
3333
#define SCL_READ() ((GPI & (1 << twi_scl)) != 0)
3434

3535
#ifndef FCPU80
@@ -99,7 +99,7 @@ static bool twi_write_stop(void){
9999
twi_delay(twi_dcount);
100100
SDA_HIGH();
101101
twi_delay(twi_dcount);
102-
102+
103103
return true;
104104
}
105105

@@ -166,7 +166,8 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
166166
unsigned int i;
167167
if(!twi_write_start()) return 4;//line busy
168168
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);
170171
if(sendStop) twi_write_stop();
171172
i = 0;
172173
while(SDA_READ() == 0 && (i++) < 10){

0 commit comments

Comments
 (0)