Multi AVR communications

Go To Last Post
46 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello friends i wanna ask a simple but complicated question try to understand my need thanks.

i am trying to communicate 5 microcontrollers and every controller is master like no one depends on no one,

second thing is every microcontroller transmits and receives data and accordance to received data action will be taken.

i am using USART with 1Mhz internal clock and 2400 baud in proteus (simulation). please help me if it is possible or anyother way to do it. 

Thanks.

Manish verma

Last Edited: Tue. Sep 12, 2017 - 02:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, having decided to tag your question onto the end of this eight year old thread, have you actually read all the preceding posts?

 

What have you learned from them?

 

 

You haven't fulfilled the promise you made here http://www.avrfreaks.net/comment... yet ...

 

EDIT

 

Was originally tacked onto the end of this thread:

 

http://www.avrfreaks.net/forum/c...

 

 

Last Edited: Tue. Sep 12, 2017 - 03:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working on that and almost completed my document....but i need some more info to complete it hope you don't mind giving me some more time.

 

and awneil please if you can help me with above please do it. 

Thanks

Manish verma

Last Edited: Tue. Sep 12, 2017 - 11:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems that your previous thread is foundational to this one - you really need to ensure that you have the foundations right before you start building more stuff!

 

And, again, why did you choose this thread? What have you learned from the posts in it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You say they are "all" master - but one has to be a coordinator. You can't have them all "talk at once" can you?

 

What made you choose UART anyway?

 

UART is usually about one-to-one.

 

The AVR UART has a special mode for allowing multiple UARTs but this does involve "addressing" (saying which one the next message is directed to) and to achieve that you need an arbiter to do such addressing.
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

You say they are "all" master - but one has to be a coordinator. You can't have them all "talk at once" can you?

 

What made you choose UART anyway?

 

UART is usually about one-to-one.

 

The AVR UART has a special mode for allowing multiple UARTs but this does involve "addressing" (saying which one the next message is directed to) and to achieve that you need an arbiter to do such addressing.
 

yes you are right my friend.

Actually my main concern is not to talk at once its just like transmitting some data and rest of the microcontrollers receive according to their need. and i want to know about MPCM because this is the only register i found at google which can help me by addressing  microcontrollers. 

being specific MPCM is (9th bit of UART which is for multi processsor)

Manish verma

Last Edited: Tue. Sep 12, 2017 - 11:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
You say they are "all" master - but one has to be a coordinator.

...at any given time. Token passing comes to mind.

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:
i want to know about MPCM ... i found at google 

Go on - if you managed to find it on google, then you must also be able to find some explanations and examples!

 

It's not like it's a new or unusual feature ...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:

...every controller is master like no one depends on no one,...

 

That's not what a master-slave relationship in data communications is about. The master is simply the one that arbitrates bus access and can dynamically change.

 

You need to start thinking about the bus access separately to the data flow. 

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

Last Edited: Tue. Sep 12, 2017 - 11:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well I did but their is no related example for MPCM ,actually i just need to know how to address any microcontroller may be this can make my task easier. if you know something about it then please tell me.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How much data are you passing between 'nodes'?

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

 

That's not what a master-slave relationship in data communications is about. The master is simply the one that arbitrates bus access and can dynamically change.

well my bad, i want to say like there are 5 microcontrollers and 5th one is the coordinator who receives data from rest of 4 microcontrollers and sending data to those 4 microcontrollers.

Now i acheived the transmiting part where 5th microcontroller transmits its data to rest 4 microcontrollers and according to received data my microcontrollers are working but i can't receive data from 4 microcontrollers to that 5th microcontroller. i am doing this on proteus simulation.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

How much data are you passing between 'nodes'?

i am transmitting like 8bit data only at a time.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So make the "5th one" the master. First it sends a message (maybe just a byte) to the first one to say "you have the bus - pass your data". Then the first one sends data. When the 5th (master) recognises the end of his data he sends a message to the 2nd to say "now you...." and so on.

 

MPCM is a mode in which there is the usual passing of UART data on the bus but if the 9th bit is ever set it says "the other 8 bits here are not data but they are the number of the next unit I would like to talk to". So the master may set bit 9 and set the other bits to 0x01 to say "unit 1, it is you I am talking to now", Anything it sends after that (with bit 9 = 0) is only intended for unit 1 to "hear". That is how it can send a "unit1 - you have the bus - pass your data" style of message. When unit 1 is complete the master can now set bit 9 and send 0x02 to say "now it is unit 2 I want to talk  to".

 

In MPCM the "listeners" all set a "filter" to 0x01 or 0x02 or whatever. When a message with bit 9 set also has "their number" they then start listening to subsequent traffic that passes by until the master send a message with bit 9 and some number that does not match their ID.

 

That, roughly, is how your addressing scheme should work.

 

Can we assume you have actually READ the bit of the datasheet where it talks about using UART in MPCM mode?

Last Edited: Tue. Sep 12, 2017 - 11:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:

Brian Fairchild wrote:

How much data are you passing between 'nodes'?

i am transmitting like 8bit data only at a time.

 

But how often?

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
the bit of the datasheet where it talks about using UART in MPCM mode?
For example:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
But how often?

 

once only.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

So make the "5th one" the master. First it sends a message (maybe just a byte) to the first one to say "you have the bus - pass your data". Then the first one sends data. When the 5th (master) recognises the end of his data he sends a message to the 2nd to say "now you...." and so on.

 

 

^^^That.

 

I do something very similar between 7 controllers. One is the 'access-controller' aka 'arbiter' aka 'master'. It send a single byte in MPCM mode which is just a number between 0 and 6; that byte is sent at a regular interval with a gap in-between. That gap is where the node that has been granted access transmits its data. Even the 'master' listens to the bus for its own ID before it transmits.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks a ton i really need this .......this will be very helpful.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:

Brian Fairchild wrote:
But how often?

 

once only.

 

As in, 'only once and then the nodes goes to sleep for the rest of time?'

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

staring.net@gmail.com wrote:

Brian Fairchild wrote:
But how often?

 

once only.

 

As in, 'only once and then the nodes goes to sleep for the rest of time?'

well not really, i am using timer CTC mode so it was checking like in every 2400(OCRA value to compare ) ticks and whenever any event occur it starts receiving and transmitting according to the event occurance

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google RS-485.  I think this is what you will need. 

 

Also search this site for RS-485....There are more threads on this, and how it relates to what you are looking to do.

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Google RS-485. I think this is what you will need.
That's going to kind of depend how far apart these micros actually are.

 

If they are 5 on one PCB then it's not needed. If they are 50ft apart across a room in which 10kV is being switched rapidly with all kinds of electrical noise then it probably is needed.

 

So it kind of depends on environment.

 

Now this is a wild guess but when I read about one master and four slaves my first inclination is to think "quadcopter". Maybe it's just me? But if that is what we are talking about here the next question would then be "why 5 micros"? Why not just one big one in the middle? (which is a more general question even if it isn't specifically a quadcopter)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

jgmdesign wrote:
Google RS-485. I think this is what you will need.
That's going to kind of depend how far apart these micros actually are.

 

If they are 5 on one PCB then it's not needed. If they are 50ft apart across a room in which 10kV is being switched rapidly with all kinds of electrical noise then it probably is needed.

 

So it kind of depends on environment.

 

Now this is a wild guess but when I read about one master and four slaves my first inclination is to think "quadcopter". Maybe it's just me? But if that is what we are talking about here the next question would then be "why 5 micros"? Why not just one big one in the middle? (which is a more general question even if it isn't specifically a quadcopter)

No not quadcopter,It is for traffic light and i need 5 microcontrollers so i can handle about 4 traffic signals with 1 microcontroller or you can say one crossing 1 micrcontroller so basically i m going to communicate 5 crossing through 5 microcontrollers but as i am working on small scale like study thing so i m using only proteus and there is no dependancy of distance in meters or centimeters. 

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think we're talking about a traffic light controller.
One would rarely transfer one byte of information between micros - main reason being you have no means of error checking. Once you add error checking, you have multiple bytes so you need a method of ensuring synchronisation. Then there's addressing.
At a higher level, you need to decide if your slave micros have any control logic running in them or whether the control logic is central in the master controller.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
I think we're talking about a traffic light controller. One would rarely transfer one byte of information between micros - main reason being you have no means of error checking. Once you add error checking, you have multiple bytes so you need a method of ensuring synchronisation. Then there's addressing. At a higher level, you need to decide if your slave micros have any control logic running in them or whether the control logic is central in the master controller.

 

Kartman your concern about higher level is absolutely correct but in my case i need to stimulate only so here i just wanna communicate with no means of addressing so no need for address error checking and more bytes. what i need is i want to know why my system is behaving like half duplex while i am using full duplex. see above posts.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:
well my bad, i want to say like there are 5 microcontrollers and 5th one is the coordinator who receives data from rest of 4 microcontrollers and sending data to those 4 microcontrollers.

So, are you actually saying something like "one master, four slaves"?

There is no communication between the four?

 

Like this:

 

One master four slaves on one bus

?

 

You still haven't told us anything about how long distance you need to cover.  Why?

 

EDIT: Took a while to sketch up that figure, and other posts came in to clarify things in between.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Tue. Sep 12, 2017 - 12:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

staring.net@gmail.com wrote:
well my bad, i want to say like there are 5 microcontrollers and 5th one is the coordinator who receives data from rest of 4 microcontrollers and sending data to those 4 microcontrollers.

So, are you actually saying something like "one master, four slaves"?

There is no communication between the four?

 

Like this:

 

One master four slaves on one bus

?

 

You still haven't told us anything about how long distance you need to cover.  Why?

there is no distance, i m doing it on proteus (simulator). and if u really need to know then u can say that they all are on same board.

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

here 5 microcontrollers use same RXC and TXC pins

Attachment(s): 

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You clearly did not understand the point i was making. How do you propose to address four slaves, send data and get a response using 1 byte each way?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well through every micro i am transmitting UDR value very different like 0b00000001 and next is 0b00000010 and so on.....and use switch case to vary which command has been received so take that action . Am i clear to you or you need me to elaborate it more

Manish verma

Last Edited: Tue. Sep 12, 2017 - 12:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:

here 5 microcontrollers use same RXC and TXC pins

 

That will not work as you cannot tie all teh slaves TX lines together.

 

Suggestion, use an AVE with four USARTS....Mega2560 is the big boy on the block for this.  I believe the Mega 640 does as well.  You can connect each slave to the master through the usarts this way.  Each slave gets it's own usart port

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow - is it 2004 already?

 

Have we finished re-inventing the wheel yet?

 

http://www.8052.com/forum/read/6...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
you cannot tie all teh slaves TX lines together

Just one of the spokes of this >13 year old wheel!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

That will not work as you cannot tie all teh slaves TX lines together.

 

You only have a problem if you leave all the transmitters enabled. If you use this feature...

 

Quote:

The USART Transmitter is enabled by setting the Transmit Enable (TXEN) bit in the UCSRnB Register. When the
Transmitter is enabled, the normal port operation of the TxDn pin is overridden by the USART and given the func
tion as the Transmitter’s serial output.

 

...leaving the normal IO port as an input, you can tie all the RXD and TXD pins together with a pull-up resistor to keep things tidy. The bus arbitrator enables its TX, send the token to the bus and turns off its TX. All nodes receive the token and the addressed one replies.

 

With small fixed length packets there's really no chance of collision. 
 

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This works even better on uCs that have a more developed MPCM function. It's now quite common to have an address match register so that only the addressed node will wake up unlike the AVR where every node wakes up and needs to check UDR for a its address.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Points made Andy.

 

Time to split this thread....

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
uCs that have a more developed MPCM function

Like the 8052 !

 

laugh

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I like the old RING structure for this.

 

uC A transmits to uC B,

uC B transmits to uC C,

uC C transmits to uC D,

uC D transmits to uC E,

uC E transmits, full circle, back to uC A.

 

All data is sent in a packet which describes who send the data, the data packet type, perhaps who the data is for, if the packet descriptor doesn't already make that clear, and either a checksum or a CRC for error detection.

 

As each uC has an interrupt driven, ring buffered buffer for both the incoming and outgoing data, ANY of the uC's can insert its own packet into the loop, as long as it is not interrupting a packet transmission that is already in progress.

 

When a uC receives a packet for itself, it can set a flag in the packet and send it on.

The packet originator then knows that the packet was received correctly.

 

Some packets can be for all nodes in the ring, others for only a single or specific group of nodes.

 

If each uC always transmits each data packet on, then when it receives its own initiated packet it eats it, and doesn't send it a second time.

 

This process avoids data collisions, and no "Master" is required.

 

JC

 

Edit:Typo

Last Edited: Tue. Sep 12, 2017 - 05:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

This process avoids data collisions, and no "Master" is required.

 

But it does mean that if one processor goes down then the whole lot goes down.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A lower power alternative to RS-485 is M-LVDS but its length is limited to about 100m.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 i really need to know why my controller not receiving from other microcontrollers....but when i try to communicate through single micro it happens. why..?? when i send data from 5th micro(assume main coordinator) than all four micro receives data and work according to it, but when i try to send data seperately from other 4 micros to that 5th one it ain't happens the question is why?????

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:
but when i try to send data seperately from other 4 micros to that 5th one it ain't happens the question is why?????

 

I told you in post#32

jgmdesign wrote:
That will not work as you cannot tie all the slaves TX lines together.

 

The TX lines are ACTIVE meaning they sit at a logic one or zero...at idle logic one so when one of these micros tries to talk it in reality is shorting all the TX lines out....hence no communications

 

 

Have we hit #100 yet?

 

Jim

 

EDIT:

Read post #35.  Brian gives you the answer on how to tie all the TX lines together if thats what you intend on doing.  What does your code look like By The Way?

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Wed. Sep 13, 2017 - 01:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If this is a proteus simulation, then use the proteus tools to visualise what is happening. You have a virtual oscilloscope that might be useful.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
use the proteus tools to visualise what is happening

And to single-step your code.

 

EDIT

 

Simply googling "Proteus single step" finds:

 

Labcenter Electronics wrote:

Proteus VSM supports source level debugging ... 

:

:

Single Stepping

A number of options for single stepping are provided, all available from the toolbar on the source window itself or from the Debug menu...

:

:

Multi-CPU Debugging

Proteus VSM has no problem simulating designs containing more than one CPU...

 

http://systembus.com/Proteus/LISA/MICROPROCESSORS/Source_Level_Debugging.htm

Last Edited: Wed. Sep 13, 2017 - 02:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Read post #35. Brian gives you the answer on how to tie all the TX lines together if thats what you intend on doing.

I've lost track whether we are still on the n independent nodes that can each initiate a transaction at any time, or whether the system design will be a polling master and n-1 slaves.

 

Anyway, I agree that if directly-connected then TXEN could [probably--not tested] be used the same way TE is used with an RS485 transceiver, with the same caveats. [edit] In fact, a bit easier as one doesn't have to wait for TXC necessarily...

20.6.5 Disabling the Transmitter
The disabling of the Transmitter (setting the TXEN to zero) will not become effective until ongoing and pending
transmissions are completed, i.e., when the Transmit Shift Register and Transmit Buffer Register do not contain
data to be transmitted. When disabled, the Transmitter will no longer override the TxDn pin.
 

 

Remember that back when I was your age, Ethernet was "Carrier-sense multiple access with collision detection (CSMA/CD) ".  And token ring, and other schemes some more widespread than others.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Wed. Sep 13, 2017 - 02:53 PM