Arduino Multiple Slave Issue

An area to discuss AVR and Arduino specific problems and examples

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Arduino Multiple Slave Issue

Post 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 337 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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Multiple Slave Issue

Post 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 :)

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Arduino Multiple Slave Issue

Post 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
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Multiple Slave Issue

Post by mnf »

Thanks to Leigh and Martin... Yes, fell into the trap of reusing a variable, and giving it one job too many.

Martin.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Multiple Slave Issue

Post 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

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Multiple Slave Issue

Post by mnf »

Hmm - has an extra master_uninit in the transmit routine... Removing it doesn't fix things however.

Martin

Post Reply