Communcating Between Two AVR With I2C_Master

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

How might I communcating between two AVR with I2C_Master? I came up with code but it does work. The master chip's code I'm pretty sure works but I'm not sure the slave chip's code works at all.

Master:

i2c_init();

if (i2c_start(0b11001111) == 0) // AVR slave
{
	i2c_write(0b10000000); 
}

Slave:

int a = 1;
int8_t info = 0b00000000;
i2c_init();
TWAR = 0b11001111;

while(a == 1)
{
	info = i2c_read(0);
	if(info < 1)
	{
		a = 0;
	}
}
(display info)

Life Is Like A Bucket Of Chicken.

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

You might check out AVRLib, which has "libraries" for i2c master and slave communication. It's pretty easy to use, although if you're new to C and AVR (as I am), it can be an awful hassle to figure out some of the more basic things (such as needing to copy/paste (not cut/paste!) the relevant .h and .c files into the local directory where your code is)

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

When I include the i2c.c and i2c.h 75 errors(all coming for the two files) come up(if you wrote complete gibberish in the the header file and would have came up with less errors)? May be it has to do with my Apple? ? ? ?

Life Is Like A Bucket Of Chicken.

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

Maybe you need a little editing for using the library. And it depends on your version of gcc.

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

Can Atmel's TWI drivers work with I2C devices?

Life Is Like A Bucket Of Chicken.

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

Yes. I2C is just a trademark for Philips. TWI is the exact same interface. See application note AVR300 (listed in the tools section) for more information about TWI. The images in AVR300 are pulled directly from the a Philips I2C documentation pdf I have lying around. (Or perhaps the other way around. Who knows?)