TWI code example for two AVR

Hi,

I need code examples using TWI between two AVR units (in a Master->Slave configuration)

I have seen examples either with only a Master and an EEPROM or something else slave, but no examples of a full-blown communication channel between two AVRs.

I m using AT90CAN128 but i think also code for generic AVR device its ok.

Your help is much appreciated, Thanks, Daniele

Reply to
pidy
Loading thread data ...

Does it really have to be I2C?

SioL

Reply to
SioL

Master->Slave

something

between

ok.

yes I have to use TWI, if its what u mean

Reply to
pidy

There is a good example on the Silabs website for their 8051 based processors which seem to use exactly the same TWI/I2C interface hardware as Atmel. Since the example is in C you can port it pretty much directly with some name changes.

I've done it the other way round when moving a project from a Silabs part to an Atmel (my own code I hasten to add NOT the Silabs code).

Michael Kellett

formatting link

Reply to
MK

Interesting. I must have missed out on this TWI thingy ! What is it ?

Graham

Reply to
Eeyore

its the dreaded firrips I2C protocol.

OT just been looking at the Grace design 802 remote mic amp, they use I2C over a 1000 foot run, seems dumb to me

martin

Reply to
martin griffith

I'd guess "two wire interface" (prolly I2C by another name to get around Philips licencing/licensing issues).

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

In message , dated Wed, 6 Sep 2006, martin griffith writes

That dates you! That 'firrips' ad was run in 1978, I think.

-- OOO - Own Opinions Only. Try

formatting link
and
formatting link

2006 is YMMVI- Your mileage may vary immensely.

John Woodgate, J M Woodgate and Associates, Rayleigh, Essex UK

Reply to
John Woodgate

Advertising works, Havent bought anything with a philips label since

martin

Reply to
martin griffith

as

with

to

thank u Michael... but i couldnt find the example u was talking about... couldnt find no example with TWI/I2C interface...can u give me link??

thanks a lot

Daniele

Reply to
pidy

Oh ! No problem there then. I have my own I2C routines ( not for master slave admittedly but I dare say that could be fixed ).

If it works ! One of the nice things about I2C is that you can run it at ony old speed. Doesn't mind being interrupted either.

Graham

Reply to
Eeyore

What *exactly* is it you want ?

Graham

Reply to
Eeyore

about...

Hello Graham..

I should need the code for the master device and the code for the slave device... but in my case the master and the slave are 2 AVR-AT90CAN128.

I have those 2 devices and want realize a comunications between them using TWI.

Thanks a lot

Daniele

Reply to
pidy

Why does it need to be I2C then ?

Don't they have serial ports ?

Graham

Reply to
Eeyore

Hello,

The Silabs website is

formatting link

You will need to register and then search the tech library for SMB (they call I2C SMBus). You'll get a few hits but you need to look at the app note.

Michael Kellett

Reply to
MK

link??

slave

AVR-AT90CAN128.

using

sure, they have serial ports but i need to use TWI

Reply to
pidy

Will the master always be the master and the slave always the slave?

If so, code is available either from atmel website or a number of other sites, just google. It may not be for exactly your model of AVR, but adapting the code should be easy enough.

SioL

Reply to
SioL

yes

Reply to
pidy

So look for the code out there, it exists. Google is your friend. Avrfreaks etc etc

SioL

Reply to
SioL

ok I'll post some code... look if it could be ok

Master.c

#include #include #include

int TWI_Master_Transmitter(uint8_t data, uint8_t address); void TWI_init(void); void TWI_Master_Transmitter_Error(void);

int main(void) { DDRA=0xFF; PORTA=0xFF; TWI_init(); int a; a=TWI_Master_Transmitter(0xAA,0xE0); if(a!=0) PORTA=a; }

void TWI_init(void) { #define SCL_CLOCK 100000L #define F_CPU 8000000UL

/* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */

TWSR = 0; /* no prescaler */ TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ TWCR=(0

Reply to
pidy

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.