Permalink
Browse files

- Fix bug with repeate START

  • Loading branch information...
YogoGit committed Mar 7, 2012
1 parent a292677 commit 8aff39a229362e0167e5f48f6c15d02b39b0fbca
Showing with 0 additions and 2 deletions.
  1. +0 −2 libraries/Wire/utility/twi.c
@@ -464,8 +464,6 @@ SIGNAL(TWI_vect)
if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
twi_rxBuffer[twi_rxBufferIndex] = '\0';
}
- // sends ack and stops interface for clock stretching
- twi_stop();
// callback to user defined callback
twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
// since we submit rx buffer to "wire" library, we can reset it

3 comments on commit 8aff39a

@Friar-Festus

This comment has been minimized.

Show comment
Hide comment
@Friar-Festus

Friar-Festus Feb 6, 2015

Thanks! Couldn't get Wire.onReceive() and Wire.onRequest() to work together in the same sketch until I stumbled upon a link to this change.

Thanks! Couldn't get Wire.onReceive() and Wire.onRequest() to work together in the same sketch until I stumbled upon a link to this change.

@ekiuser

This comment has been minimized.

Show comment
Hide comment
@ekiuser

ekiuser Aug 29, 2016

I have tried this change in the code for using both Wire.onReceive() and Wire.onRequest() to work together in the same sketch, but I still have problems. I´m using Arduino M0 Pro as a slave and the code is the next:
`

include <Wire.h>

define SLAVE_ADDRESS 0x0B

volatile byte command=0x00;

void setup() {
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);}

void loop() {}

void receiveData(volatile int byteCount){
command=Wire.read();
while (Wire.available()>0){
Wire.read();}
}

void sendData(){
Wire.write(command);
command=0;
Wire.write(command);
}
`
The problem is that the master receives the data wrongly; If the master sends firstly to arduino command 0x0d, it receives nothing. If next, the master sends to arduino command 0x02, it receives 0x0d. If next, master sends command 0x06, it will receive 0x02.

What could be the problem??

I have tried this change in the code for using both Wire.onReceive() and Wire.onRequest() to work together in the same sketch, but I still have problems. I´m using Arduino M0 Pro as a slave and the code is the next:
`

include <Wire.h>

define SLAVE_ADDRESS 0x0B

volatile byte command=0x00;

void setup() {
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);}

void loop() {}

void receiveData(volatile int byteCount){
command=Wire.read();
while (Wire.available()>0){
Wire.read();}
}

void sendData(){
Wire.write(command);
command=0;
Wire.write(command);
}
`
The problem is that the master receives the data wrongly; If the master sends firstly to arduino command 0x0d, it receives nothing. If next, the master sends to arduino command 0x02, it receives 0x0d. If next, master sends command 0x06, it will receive 0x02.

What could be the problem??

@VictorTagayun

This comment has been minimized.

Show comment
Hide comment
@VictorTagayun

VictorTagayun Mar 3, 2017

Could you try this?

http://forum.arduino.cc/index.php?topic=385377.0

Wire.requestFrom(FPGA_ADDRESS, 1, FPGA_REG, 1, true);

Could you try this?

http://forum.arduino.cc/index.php?topic=385377.0

Wire.requestFrom(FPGA_ADDRESS, 1, FPGA_REG, 1, true);

Please sign in to comment.