mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-25 20:02:37 +03:00
thanks @petrd and @Yazzcat
This commit is contained in:
parent
4cf72e7ef4
commit
46468d4af7
@ -150,9 +150,15 @@ static unsigned char twi_read_byte(bool nack) {
|
||||
unsigned char twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop){
|
||||
unsigned int i;
|
||||
if(!twi_write_start()) return 4;//line busy
|
||||
if(!twi_write_byte(((address << 1) | 0) & 0xFF)) return 2;//received NACK on transmit of address
|
||||
for(i=0; i<len; i++){
|
||||
if(!twi_write_byte(buf[i])) return 3;//received NACK on transmit of data
|
||||
if(!twi_write_byte(((address << 1) | 0) & 0xFF)) {
|
||||
if (sendStop) twi_write_stop();
|
||||
return 2; //received NACK on transmit of address
|
||||
}
|
||||
for(i=0; i<len; i++) {
|
||||
if(!twi_write_byte(buf[i])) {
|
||||
if (sendStop) twi_write_stop();
|
||||
return 3;//received NACK on transmit of data
|
||||
}
|
||||
}
|
||||
if(sendStop) twi_write_stop();
|
||||
i = 0;
|
||||
@ -168,7 +174,10 @@ unsigned char twi_writeTo(unsigned char address, unsigned char * buf, unsigned i
|
||||
unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned int len, unsigned char sendStop){
|
||||
unsigned int i;
|
||||
if(!twi_write_start()) return 4;//line busy
|
||||
if(!twi_write_byte(((address << 1) | 1) & 0xFF)) return 2;//received NACK on transmit of address
|
||||
if(!twi_write_byte(((address << 1) | 1) & 0xFF)) {
|
||||
if (sendStop) twi_write_stop();
|
||||
return 2;//received NACK on transmit of address
|
||||
}
|
||||
for(i=0; i<(len-1); i++) buf[i] = twi_read_byte(false);
|
||||
buf[len-1] = twi_read_byte(true);
|
||||
if(sendStop) twi_write_stop();
|
||||
|
Loading…
x
Reference in New Issue
Block a user