SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By Moggity
#112187
Hi Guys,

I'm just looking for some validation of my ideas and any code tips that you'd have for the following scenario.
I am working on a project that will have a series of AVR's (most likely ATTiny 2313's) daisy chained together into a long string. I need each of these micro's to be individually addressable, but I want to be able to break the system down into individual pieces which can be re-assembled without regard for the order they were in or are put into.

What I'm considering is the following. Each module will be held in reset by the previous module. A control module will set the reset line high so the first module can start and then proceed to broadcast an id out via a serial connection. The first module will hold the reset of the next module in line low until it has received the id and transmitted a confirmation back to the control unit. Once a module has an id it will let the reset go high for the next module and pass on any serial commands through its second serial port. This process will repeat until all modules are discovered and have id's.

Once all the modules have id's, the master will know how many there are and how to address each individual module. By passing the serial control commands through each micro there won't be any attenuation throughout the system enabling reasonably long chains to be built. The ATTiny has a USART and a USI so I'll be using one hardware serial port and one software serial port.

Does this sound reasonable and likely to work? The main drive to having the automatic addressing system is for ease of assembly on site and so all spares can be common and not have to be programmed specifically for an application.

Sorry for the long post but any hints, tips or example code would be great. I’m not 100% sure how to handle the addressing pickup or the pass-through at this stage so any suggestions would be great.

Cheers

Andrew
User avatar
By thebecwar
#112232
Seems like it may work.

Some thoughts:
-If you go with the scheme you've layed out, you probably want the last board to pass back a message to the controller, stating that it's last, otherwise you can't be sure that they're all set up. You'll probably need to design in some kind of bus terminator.
-If the modules have specific purposes, why not address them that way?
-Logical addressing is independant of physical connection. You don't need the closest device to be device 0.
-Each micro in the chain will delay every byte by at a minimum 5-10 clock cycles. If you have 10 devices that means a delay of 50-100 clock cycles. At 1 MHz clock you've got a delay of .05ms to .1ms. Not a show stopper, but something to be aware of if you're working with time critical information.
By n1ist
#112248
I have done something similar by having all of the modules in a long SPI chain with the last one's MISO linked back to the micro. You can count the number of modules by seeing how long it takes for a word to make it through the chain. Then you can send addresses to each and use a common latch pin to save the addresses in the modules.
/mike
By Moggity
#112418
Hi thebecwar and mike,

Thanks very much for your replies and advice. It's greatly appreciated.

I can't pre-address the modules beforehand because their physical layout and their logical layout have to match to be able to do what I want to do. The modules all have the same function, and there will possibly be up to 400 modules in a chain out to 400m long.

Fortunately the control isn't very time critical, and any delays can be compensated for in the control software.

The bus termination issue is something I haven't thought about very much. I was working on the assumption that the control would just keep trying to assign addresses until it failed to hear back from the last address, but the end of the bus would also look exactly the same as a bus failure, which wouldn't be so nice. I think that I'll definitely have to produce some sort of bus termination device that provides a definite notification of the end of the bus to allow detection of bus failures. Thanks thebecwar!

The SPI chain idea is interesting, I haven't investigated SPI as an option due to the potential length of the bus and the potential number of modules, but that was working on the assumption that the whole setup would be run on a conventional SPI bus. I'll definitely investigate this further, thanks Mike!

Again, thanks very much for the replies so far. It's always great to be able to bounce ideas off people and receive some wisdom and ideas back.

Cheers

Andrew