Using SPI, USART and still communicate with another AVR?

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

I already have some Atmega16's so I was planning on using them. I need to set up the USART to communicate with my PC through the com port, and I also want to connect to a 16 bit ADC, something like the ADS8344 using the SPI. But I also want to communicate with other AVR's. Is this possible? Can I simulate SPI using normal I/O pins?

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

Yes, you can bit-bang another SPI interface. You could also do a sotware UART. Another option is to use 1 AVR with multiple UART's with your M16's.

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

Keep in mind that SPI is not limited to a connection between a master and a single slave any more than a microprocessor is limited to talking to a single external memory device. The master usually supplies some type of enable that tells the slave that it is the target for a particular transaction. In the case of SPI, this is the SS pin, which is an output from the master and an input to the slave (it may be called something different on the slave depending on the manufacturer, but it is still an enable). On the master side, it can be nothing more than a single bit position in an I/O port that is enabled prior to the transaction and disabled afterwards so that only a single slave reacts to the SPI operation.

Dave

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

Thanks for the tips.

I do need to communicate with more than one slave. So I think I'll use the SPI to link the AVR's. So what would be my options in communicating with the 16bit ADC? Can I use UART of one of the slaves for SPI? I suppose the other option is to use a TWI ADC, but that is slower communications, is that right? I want to transfer data as fast as possible

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

Quote:
Can I use UART of one of the slaves for SPI?

While this is possible with some of the newer devices, such as the Mega1280, I don't think this is possible with a standard Mega16. As for what's best to use to use to communicate between AVR devices, this depends a lot on your application. Are the devices located near each other on the same board or are they on separate boards separated by some distance? Is one AVR going to act as the master and the other a slave or is the application structured more like a peer-to-peer configuration? Do you feel comfortable programming towards one interface over another? In one of the posts above, dksmall recommended using one AVR that had multiple UART's. I realize you already have the Mega16's, but if you can afford the few extra $$, I would recommend you consider this. It will likely simplify the software enough to be well worthwhile. In the designs I've done I've found that SPI works best between a microcontroller and a dumb peripheral. For those applications where I've had to use multiple microcontrollers I've found that communicating between them via a UART worked best.

Dave

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

dharper wrote:
As for what's best to use to use to communicate between AVR devices, this depends a lot on your application. Are the devices located near each other on the same board or are they on separate boards separated by some distance?

They will be on separate boards probably about half a meter apart.
dharper wrote:

Is one AVR going to act as the master and the other a slave or is the application structured more like a peer-to-peer configuration?

One will be a master and there will be 3 slaves.
dharper wrote:

Do you feel comfortable programming towards one interface over another? In one of the posts above, dksmall recommended using one AVR that had multiple UART's. I realize you already have the Mega16's, but if you can afford the few extra $$, I would recommend you consider this. It will likely simplify the software enough to be well worthwhile. In the designs I've done I've found that SPI works best between a microcontroller and a dumb peripheral. For those applications where I've had to use multiple microcontrollers I've found that communicating between them via a UART worked best.

Dave


I haven't done much any of these interfaces as yet. I'll have to test a few things out and learn as I go. I'll definitely look at an AVR with multiple UART's.