Page 1 of 1

Arduino Multiple Slave Issue

Posted: Sun May 06, 2018 8:28 pm
by mnf
A small related problem - surely not enough to warrant a new topic.

In a group of 3 arduinos - One acting as master and transmitting to two slaves.

This seems to work aok - with one exception - one of the slaves seems to receive the data transmitted by the other slave (but not vice versa - it is always the same slave that receives the data)

In the setup the slaves have addresses of 0x20 and 0x30 (set in the properties) with mask of 0xff. They are also set to transmit different data (nothing exciting just one transmitting an increasing variable and one a constant (123))

The code:
sender.fcfx
(12.41 KiB) Downloaded 338 times
receiver.fcfx
(13.9 KiB) Downloaded 329 times
Slave at 0x20
33 addr 0x20
Transmit
123 Data
Slave at 0x30
49 addr 0x30
Transmit
Sender
20 sent 123
30 sent 5
Any suggestions as to what is going wrong (if it is wrong?)
The standard Arduino libraries use the i2c hardware interrupt to jump to an onReceive handler - which seems a neater way of dealing with waiting for a message. Probably problematic to implement something similar when targeting multiple MCUs?

Martin

Re: Arduino Multiple Slave Issue

Posted: Tue May 08, 2018 2:07 pm
by LeighM
Hi Martin,
In your receiver main you have used the .b variable to hold the result from Check_Status and also the result from ReceiveByte,
which just happens to return 0x21 in the case of the "0x20" Slave address in read mode.
One solution might be to move the (if .b = 0x21) decision into the "No" branch of the (if .b = 1) decision
Leigh
ps. Yes, it maybe would have been better as a new topic, but I don't have powers to move it :)

Re: Arduino Multiple Slave Issue

Posted: Tue May 08, 2018 2:46 pm
by medelec35
LeighM wrote:ps. Yes, it maybe would have been better as a new topic,
Moved to a new section of the forums

Martin

Re: Arduino Multiple Slave Issue

Posted: Tue May 08, 2018 5:49 pm
by mnf
Thanks to Leigh and Martin... Yes, fell into the trap of reusing a variable, and giving it one job too many.

Martin.

Re: Arduino Multiple Slave Issue

Posted: Wed May 09, 2018 8:11 am
by mnf
Ok - so after your starter for 10.....

What I'm trying to do is create a chain (actually a ring) of Arduinos.. The code that does('nt do) it is:
MasterSlave.fcfx
(17.72 KiB) Downloaded 311 times
But note that it doesn't work :-(
I did get a message spinning around briefly, but just random numbers and when I modified the code to transmit .data - it stopped working.

A few questions:

1) Is this a sensible way to do things? (ie Would spi be better?)
2) Is there a way to make it more robust - currently an i2c error will lock things up.
3) Is there a way to get the Arduino to automagically identify it's place in the chain (at the moment the address of the next link is hard coded) I wondered about using 3 pins as an 0..7 selector.
4) I need to pass a 32 bit number around a ring of Arduinos. I did wonder about the slaves replying to the master which then passes the data to the next - which is maybe slightly simpler?

Martin

Re: Arduino Multiple Slave Issue

Posted: Wed May 09, 2018 6:28 pm
by mnf
Hmm - has an extra master_uninit in the transmit routine... Removing it doesn't fix things however.

Martin