My Arduino DUE cannot send restart in I2C , but UNO can work well

hi
i am using DUE for control I2C. the slave IC can support restart I2C. so i use this code
Wire.endTransmission(false);

int read_byte_value(unsigned char r)

{

int v1;

Wire.beginTransmission(address);

Wire.write(r);

Wire.endTransmission(false);

// delay(2);

Wire.requestFrom(address,1);

v1=Wire.read();

return v1;

// delay(100);

Wire.endTransmission();

delay(100);

// }

}

the slave's address is 0x07. the reg of slave is 0x01. and its value should be 0x80
but i use prober in SDA and SLC. I found SDA still exist stop signal

i program this code into my Arduino uno. It dont exist this issue. the SDA is the real restart.


here is the same code in UNO. we can see the restart work well

can someone help me? thanks

i just review the code of endTransmission of DUE and UNO. I found that

sendStop dont include in DUE's code

uint8_t TwoWire::endTransmission(uint8_t sendStop) {
uint8_t error = 0;
// transmit buffer (blocking)
TWI_StartWrite(twi, txAddress, 0, 0, txBuffer[0]);
if (!TWI_WaitByteSent(twi, XMIT_TIMEOUT))
error = 2; // error, got NACK on address transmit

if (error == 0) {
	uint16_t sent = 1;
	while (sent < txBufferLength) {
		TWI_WriteByte(twi, txBuffer[sent++]);
		if (!TWI_WaitByteSent(twi, XMIT_TIMEOUT))
			error = 3;	// error, got NACK during data transmmit
	}
}

if (error == 0) {
	TWI_Stop(twi);
	if (!TWI_WaitTransferComplete(twi, XMIT_TIMEOUT))
		error = 4;	// error, finishing up
}

txBufferLength = 0;		// empty buffer
status = MASTER_IDLE;
return error;

}

and endTransmission of due include sendStop

uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
// transmit buffer (blocking)
uint8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);
// reset tx buffer iterator vars
txBufferIndex = 0;
txBufferLength = 0;
// indicate that we are done transmitting
transmitting = 0;
return ret;
}

TWI (a subset of I2C) is a bit touchy on a DUE plus Wire library is not properly adapted for this board.

There are some example sketches using direct register programming to find workarounds. Note that a 10 Ohm resistor in serie on SDA and SCL lines should also provide an improvement against EMI.

See for example this topic:

There should be four bytes: address, write_date, address, read_data.
I think I see a fifth byte in the picture of the Arduino Uno.
Could you remove the Wire.endTransmission() after a Wire.requestFrom() ?

The Wire.endTransmission() should not be used to stop or end something. That is not what it does. See also my alternative explanation of the Wire functions.

The name "restart" is confusing for a start without a preceding stop. The official name is "repeated start condition": https://www.i2c-bus.org/repeated-start-condition/.

Is that a know problem ? This seems to be the same problem: https://github.com/arduino/ArduinoCore-sam/issues/70. @hvpower I'm afraid you have run into a bug that is not fixed yet.

hi Koepel:
you are a good person. thanks for your nice answer. yes. i make a mistake. it should be name repeated start.

i reviewed the issue/70 . yes. i meet the same problems. do you have any fix solution for this?

@Koepel: As per Sam3x datasheet, to read only one byte, a Start AND a Stop have to be sent at the same time BEFORE reading this single byte. When several consecutive bytes have to be read, a STOP has to be sent right BEFORE the last byte to read (see Sam3x datasheet page 715/716).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.