Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
gedex
PostPosted: Apr 04, 2007 - 06:55 AM
Newbie


Joined: Feb 21, 2007
Posts: 3


I've two AVRs (both are Atm8535) for my robot.
I need a fast protocol to communicate between them.
since 10 pins are free on each, i could use TWI (Ten Wire Interface) Very Happy, just to speed up data transfer
since 7 ultrasonics & electric compass are assigned to the slave

It's so confused to implement the handshaking. Is there anyone implemented this before? or is it possible to modify some I2C / TWI routine available here?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Apr 04, 2007 - 12:09 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62246
Location: (using avr-gcc in) Finchingfield, Essex, England

SPI is also a "nice and easy" communcation for a couple of AVRs in close proximity.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
rasto_novak
PostPosted: Apr 04, 2007 - 02:28 PM
Newbie


Joined: Jan 30, 2007
Posts: 10
Location: Slovakia: Kosice

Code:
I need a fast protocol to communicate between them.


what fast have to be the protocol ?
 
 View user's profile Send private message  
Reply with quote Back to top
gedex
PostPosted: Apr 04, 2007 - 03:48 PM
Newbie


Joined: Feb 21, 2007
Posts: 3


rasto_novak wrote:
Code:
I need a fast protocol to communicate between them.


what fast have to be the protocol ?


It should be 1 - 2 Mbps.
I've used USART before, since my target board uses 4 MHz crystal, i set baud rate to 9600bps and set U2X to enhance transfer rate. But this setting will give 0.2% error. The data being transfered consists 7 byte & i dont want to lose 1 bit.
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Apr 04, 2007 - 05:02 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13825
Location: Vancouver, BC

Quote:
But this setting will give 0.2% error.

I think that you are misunderstanding what this value means. It does not mean "0.2 % of the time there will be an error". It means that the baud rate is off by 0.2%. This is a very different thing. UARTs are tolerant of baud rate errors up to 2.0%, so 0.2% shouldn't cause you any problems. But for short distances such as this TWI (two wire interface), or SPI might still be a better choice. Or you could use an entire 8 bit port for data and another pin as a strobe/latch signal (and one more pin to indicate direction if you need bi-directional).

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
dksmall
PostPosted: Apr 04, 2007 - 05:21 PM
Raving lunatic


Joined: Apr 16, 2001
Posts: 3522
Location: Phoenix, Arizona

I've done almost exactly what you're trying to do. First off, with both micros running at the same frequency (4mhz), there is no baudrate error between the 2 micros, so set the UBRR to 1 and run 115.2K. That 8.5% error will only occur if you try to communicate with another device like a PC, that's using standard baudrates and standard frequencies.

Here's the maze runner I did that with http://www.parex.org/parex_autoevent_ma ... azer.shtml
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Apr 04, 2007 - 11:56 PM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

dksmall wrote:
First off, with both micros running at the same frequency (4mhz), there is no baudrate error between the 2 micros, so set the UBRR to 1 and run 115.2K.
That's not entirely correct. There will be some baud rate error since the two micros are not running at exactly 4 MHz. If they're running on external crystals or resonators, for example, the baud rate error is insignificant. However, if either is running on the internal RC oscillator, the baud rate error can be significant.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
dksmall
PostPosted: Apr 05, 2007 - 12:20 AM
Raving lunatic


Joined: Apr 16, 2001
Posts: 3522
Location: Phoenix, Arizona

donblake wrote:
dksmall wrote:
First off, with both micros running at the same frequency (4mhz), there is no baudrate error between the 2 micros, so set the UBRR to 1 and run 115.2K.
That's not entirely correct. There will be some baud rate error since the two micros are not running at exactly 4 MHz. If they're running on external crystals or resonators, for example, the baud rate error is insignificant. However, if either is running on the internal RC oscillator, the baud rate error can be significant.

Don


This is true, I was thinking external resonators, since that's what I did.
 
 View user's profile Send private message  
Reply with quote Back to top
glitch
PostPosted: Apr 05, 2007 - 12:26 AM
Raving lunatic


Joined: Jan 12, 2002
Posts: 7828
Location: Canada

gedex wrote:
It should be 1 - 2 Mbps.


well you won't get that rate with the AVR's TWI hardware, and you certainly won't get there through a bit banged solution either. SPI is probably your bst option here, and the implementation is quite straight forward.
 
 View user's profile Send private message  
Reply with quote Back to top
zoomcityzoom
PostPosted: Apr 05, 2007 - 01:04 AM
Posting Freak


Joined: Nov 10, 2005
Posts: 1527
Location: Redmond, WA

Quote:
since 10 pins are free on each, i could use TWI (Ten Wire Interface) Very Happy, just to speed up data transfer


I think you were joking about TWI being a 10 wire interface, but if you do have 10 free pins on each micro, why not use a 4 or 8-bit dbi-directional interface between the two? A 4-bit interface shouldn't be too difficult. An 8-bit bi-directional interface with 2 control lines is a bit more challenging. If the 10 free pins include the SPI pins then you could always drop back to that if you decide you don't want to continue working on the parallel interface.

SPI would be easier than TWI, but a parallel interface would be more interesting to implement.
 
 View user's profile Send private message  
Reply with quote Back to top
glitch
PostPosted: Apr 05, 2007 - 02:15 AM
Raving lunatic


Joined: Jan 12, 2002
Posts: 7828
Location: Canada

zoomcityzoom wrote:
Quote:
since 10 pins are free on each, i could use TWI (Ten Wire Interface) Very Happy, just to speed up data transfer


I think you were joking about TWI being a 10 wire interface,


Hint, what if that was a binary number?
 
 View user's profile Send private message  
Reply with quote Back to top
zoomcityzoom
PostPosted: Apr 05, 2007 - 02:50 AM
Posting Freak


Joined: Nov 10, 2005
Posts: 1527
Location: Redmond, WA

Doh!
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Apr 05, 2007 - 04:51 AM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25897
Location: Wisconsin USA

Quote:

It's so confused to implement the handshaking.

Quote:

10 pins are free on each,

Confused is right. With a summary of above: "It will take some pins on each plus a bunch of stuff to implement a 'fast protocol'", why not do it on one AVR such as Mega640? [I'm guessing that A/D channels are the limiting factor.]

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
Jepael
PostPosted: Apr 05, 2007 - 10:00 AM
Raving lunatic


Joined: May 24, 2004
Posts: 5994
Location: Tampere, Finland

gedex wrote:
rasto_novak wrote:
Code:
I need a fast protocol to communicate between them.


what fast have to be the protocol ?


It should be 1 - 2 Mbps.
I've used USART before, since my target board uses 4 MHz crystal, i set baud rate to 9600bps and set U2X to enhance transfer rate. But this setting will give 0.2% error. The data being transfered consists 7 byte & i
dont want to lose 1 bit.


Note that the concept of error in this case is quite relative.

With a 4MHz oscillator, you can only get within 0.2% from exact 9600bps for PC communications, but with a 4MHz oscillator, you can make the two AVRs talk to eachoter with 0% error at least 250kbps, or 500kbps if you use the U2X feature.

The error only comes from the crystals, which should be less than 1000ppm (0.1%). You won't lose any bits, as anything less than 2% mismatch should be ok.

- Jani
 
 View user's profile Send private message  
Reply with quote Back to top
Jepael
PostPosted: Apr 05, 2007 - 10:04 AM
Raving lunatic


Joined: May 24, 2004
Posts: 5994
Location: Tampere, Finland

glitch wrote:
zoomcityzoom wrote:
Quote:
since 10 pins are free on each, i could use TWI (Ten Wire Interface) Very Happy, just to speed up data transfer


I think you were joking about TWI being a 10 wire interface,


Hint, what if that was a binary number?


Another joke:

There are only 10 kinds of people. Those who understand binary numbers, and those who don't.

Actually I think I've seen this on a T-shirt somewhere or something.

- Jani
 
 View user's profile Send private message  
Reply with quote Back to top
RES
PostPosted: Apr 06, 2007 - 05:01 PM
Resident


Joined: Dec 31, 2005
Posts: 687


Jepael wrote:


Another joke:

There are only 10 kinds of people. Those who understand binary numbers, and those who don't.

Actually I think I've seen this on a T-shirt somewhere or something.

- Jani


I've got a 100 wheel drive car with 10 rear wheels and 10 front wheels.

Why don't you use USI?

_________________
RES - http://www.attiny.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
brberie
PostPosted: Apr 06, 2007 - 09:24 PM
Resident


Joined: Sep 12, 2003
Posts: 529
Location: XX century

I'm thinking of a 1000 cylinder 100 wheel drive track with 10 front wheels and 1 only driver!

Dentist has charged me for all my 100000 teeth!
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Apr 08, 2007 - 03:04 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

RES wrote:
Why don't you use USI?
FWIW, I just got slave TWI (I2C) working on a ATTiny2313 using USI. It's based on Atmel's AVR312 Application Note. I ported the code to WINAVR GCC, did some cleanup and fixed several errors. If anyone's interested, I can make it available.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
ZachSt
PostPosted: Apr 10, 2007 - 02:22 AM
Newbie


Joined: Feb 06, 2007
Posts: 1


donblake wrote:
RES wrote:
Why don't you use USI?
FWIW, I just got slave TWI (I2C) working on a ATTiny2313 using USI. It's based on Atmel's AVR312 Application Note. I ported the code to WINAVR GCC, did some cleanup and fixed several errors. If anyone's interested, I can make it available.

Don


If you could post that, it would be great. I'm working on a similar project now. I have one master microcontroller, which I want to speak to three slave ones separately depending on the address. Right now I use an 8-bit bus, 3 address bits, and 2 control bits for a hand-shake, before realizing that TWI is probably the way to go.
 
 View user's profile Send private message  
Reply with quote Back to top
NightSky
PostPosted: Apr 10, 2007 - 07:36 AM
Hangaround


Joined: Aug 12, 2005
Posts: 363
Location: Florida

SPI is more along the master/peripheral addressing scheme found in classic microprocessor architecture. You have an SS line which functions as a chip select for each SPI chip hooked to the master. That would allow you to keep your 3 address lines.

TWI is reliable (for me) using the TWI hardware, and questionably reliable with the USI hardware. Atmel is looking into this, I think.

TWI can be quite nice, but you need to put your own message protocol on top of it. TWI gives you the addressing capability of 128 possible addresses using the 7 bit addressing scheme, but certain addresses are reserved. You might want to look at the nxp (www.nxp.com) site for more information on addressing. I'd suggest at a minimum the combination of address/count/command/data with a possible return of count/status/data for each message.

Harvey
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits