Arduino Multiple Slave Issue

An area to discuss AVR and Arduino specific problems and examples

Moderator: Benj

mnf
Valued Contributor
Valued Contributor
Posts: 507
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 279 times
Contact:

Arduino Multiple Slave Issue

Postby mnf » Sun May 06, 2018 8:28 pm

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 74 times

receiver.fcfx
(13.9 KiB) Downloaded 59 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: 1873
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 438 times
Been thanked: 625 times
Contact:

Re: Arduino Multiple Slave Issue

Postby LeighM » Tue May 08, 2018 2:07 pm

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 :)
These users thanked the author LeighM for the post:
mnf (Tue May 08, 2018 5:46 pm)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8378
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3416 times
Contact:

Re: Arduino Multiple Slave Issue

Postby medelec35 » Tue May 08, 2018 2:46 pm

LeighM wrote:ps. Yes, it maybe would have been better as a new topic,

Moved to a new section of the forums

Martin
These users thanked the author medelec35 for the post:
LeighM (Tue May 08, 2018 4:01 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

mnf
Valued Contributor
Valued Contributor
Posts: 507
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 279 times
Contact:

Re: Arduino Multiple Slave Issue

Postby mnf » Tue May 08, 2018 5:49 pm

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: 507
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 279 times
Contact:

Re: Arduino Multiple Slave Issue

Postby mnf » Wed May 09, 2018 8:11 am

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 58 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: 507
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 279 times
Contact:

Re: Arduino Multiple Slave Issue

Postby mnf » Wed May 09, 2018 6:28 pm

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

Martin