Due won't write I2C data when slave

Hey guys.

I've been having problems with my Due and I2C.
I have been building a large project and the Due has been working pretty good when receiving data over the I2C bus, but tonight, making progress in the project I tried sending data.
When I try to send data nothing is happening. My logic analyzer shows no activity. I tried the example Master Writer sketch and it works. I figured out if I put an address in the Wire.begin() function, making the Due a slave, it won't send data.

In my project, I removed the address from my begin() function and all the expected data started showing up on the analyzer. But I need to Due to be a Master and Slave.

Has anybody else experienced this issue? And if so, has a fix been found?

PS. I'm using Arduino 1.5.6-r2 and I've tried both with and without the Wire.cpp modifications posted here

If the Due is the slave what kind of device is the master? Did you check that the master does send the necessary clock signals?

Please show your code (and use code tags to make it readable!).

I have things setup in a multi master environment. Currently I have 4 Arduionos hooked up, 3 Uno’s and 1 Due.
All of the Uno’s work as expected. I can do this and it works just fine

// This example code is in the public domain.
#include <Wire.h>
void setup() {
  Wire.begin(); // join i2c bus (address optional for master)

byte x = 0;

void loop() {
  Wire.beginTransmission(4); // transmit to device #4
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte  
  Wire.endTransmission();    // stop transmitting


In fact that code works on the Due as well. But when I change




The code on the Uno’s works exactly the same, they assume the role of master and send out the data, but the Due does nothing.

Logically, the device that is the fastest and that has the most memory should be the master device.

Now, it is a issue that is on the table that they have not fully patch the I2C library for DUE. First report your bug on the DUE board, so you bug repport won't be lost, second use your DUE as a Master on the I2C network.

I have things setup in a multi master environment.

That mode is not supported by the Wire library.

All of the Uno’s work as expected.

Because you don’t really do a multi master mode but just let any one of the Arduinos act as a master for a while. You do that by using a “design flaw” of the Wire implementation for the ATmega processors, in that if you use the beginTransaction() calls, it automatically switches to the master mode until a endTransaction() is called. That’s not documented and therefor not supported so it doesn’t surprise me that it doesn’t work on the Due.

The code on the Uno’s works exactly the same, they assume the role of master and send out the data, but the Due does nothing.

Because on the Due there is a difference between master and slave mode and the hardware is either in one or the other mode but not in both almost simultaneously as it can be on the ATmegas.

A real multi master mode is a complex thing to do, I would try to avoid it if ever possible because you seldom get it to run reliably.

Please explain what you try to achieve, maybe we can give you a hint how to do that with using that mixed master/slave hack.

the short version of what I'm trying to do is basically a bunch of Arduino's being able to randomly send and receive data at any possible time.
all of them have their own sensors, and output, and I need them to be able to share their data with each other.
I did just have a thought, maybe I can use both i2c channels on the due, one for sending and one for receiving.

That sound like a RS-485 project.

Unfortunately I'm pretty reluctant to switch to rs485. The fact that the Uno's work perfectly, has already lead me have PCB's made. I'd hate to have to write off my existing work. Currently only thing is not working properly is the due. And if I can make it work using both i2c channels, I'd be happy. It's less than ideal, but if it functions it functions

Re-post your problem there:

You might hit people who has more experience with the DUE.

Well my idea of using both I2C channels is working. I set one as a master (no address in begin()) and one as a slave (providing an address). On the Uno's I can address my slave address and deal with the data, and I can send data via the master at any time.
I know it's less than ideal, but for now it's working. Hopefully the Wire library gets updated and can behave more like the ATMega version.

Yeah it does all sorts of nice things, but SAM is still a strange beast for now… :stuck_out_tongue:

Hopefully the Wire library gets updated and can behave more like the ATMega version.

That probably won't be possible because you're using a non-standard behavior of the ATmega hardware which is completely undocumented for the Wire library (because it's not intended to work that way) and probably will never be supported by that software. Even in a multi-master I2C setup the masters are not expected to be slaves at the same time, this is not part of the I2C standard. Although that may work with some hardware it's not really clever to use I2C that way, communication will never be reliable, so if you use it be prepared for the communication to fail. You may have to add some mechanism to your protocol to detect such situation and retransmit if they occur.