I2C resets Ardunio (Master-Slave Dual 328P)

Hi all,

i've build a master-slave combination of two Atmega 328P - So far its not a big problem, but actually i have a strange issue while using I2C for communication.

The communication needs to be stateless and independent, so i do this without using requestFrom - I just use beginTransmission + write + endTransmission for sending a command to the slave and the slave processes this command and sends a response back with beginTransmission + write + endTransmission. Generally it seems to work - but i've discovered that after every write on slave side a reset of slave is being made. My debug protocol of slave looks like:

- setup()
- Starting sensors.
- Starting wire.
- loop()
- received command.
- processing command.
- sending command.
- setup()
- Starting sensors.
[...]

So after every send on slave side the slave 328P performs a reset. I've checked the circuit and cannot discover any connection to the reset line, so i think the reset results from I2C - Is this possible / a known issue?

Thanks in advanced for every hint.

Best regards,

André

so i think the reset results from I2C - Is this possible / a known issue?

Possible? Maybe. Likely? No.

It sounds like your slave is doing something wrong, and crashing, leading to a reset.

So, we need to see some code.

The communication needs to be stateless and independent, so i do this without using requestFrom - I just use beginTransmission + write + endTransmission for sending a command to the slave and the slave processes this command and sends a response back with beginTransmission + write + endTransmission.

That is not how I2C works, I am not supprised it crashes, you are probbly blowing a stack.

@PaulS: Thank you for your answer - I've figured the problem out, its what @Grumpy_Mike means ...

The reset occurs when the slave calls Wire.write method after calling Wire.beginTransmission(MASTER_ADDRESS). So i rebuild my code to have the "normal"/correct i2c workflow - only the master sends data via begin transmission and the slave answers if Wire.requestFrom is called. So everything works fine - Sadly its not so nice stateless and independet as originally wanted - but it don't crashes anymore.

Thank you very much for your supprt, @PaulS and @Grumpy_Mike.

Best regards,

André

Well.. multi-master communication like you described should work.
Your error was somewhere else in the code and you fixed it by accident when changing the way you send/request data.

Well.. multi-master communication like you described should work.

Multi master is not stateless communication like he discribed.
The Wire libary is not a multi master implementation anyway.

I bet he had a cycle-intensive process on the twi_attachSlaveRxEvent() callback..
And it gets even better if you start doing a lot of Serial.print() inside the callback..

Wire lib was not designed with multi-master environment in mind but you can live with it and still do two way communication.

but you can live with it and still do two way communication.

No, there is no collision detection in the wire library, if one system starts to transmit when the other is transmitting then the whole thing ends up in a big wobbly heap.

They end up on the while() { continue; }.
But it still works.