Go Down

Topic: I2C communication by many ATmega8 coding (Read 508 times) previous topic - next topic

GearMachine

Hi guys,

   I have a project that need to be monitored several potentiometers (44, on total) using the atmega8. I thought about using i2c communication, putting a atmega as master and others 11 atmega as slave (I know, are many, but it has to be with atmega8). But I need help to code them, since I want the slaves inform indetified data potentiometers to the master and this pass to the computer by serial. Could anyone help me?

Thanks.
It's a long way to the top.

tobyb121

#1
May 08, 2013, 06:29 pm Last Edit: May 08, 2013, 06:32 pm by tobyb121 Reason: 1
Work through each piece one at a time:
Start with the slave, write a piece of code that responds to a I2C request (look at Wire.onRequest) by writing the 8 bytes (2 per pot, 4 pots).
With the master, start just requesting 8 bytes from one device to make sure you have got a working I2C bus, then get it to where you step through 11 addresses requesting 8 bytes from each and storing it all in a buffer, and then just print that buffer to the serial port.

You'll need to think of a way of allocating the addresses to the slave devices, you don't want to have to keep 11 copies of the same code with just the address changed in each so allocate some IO pins (4 should do), and wire across jumpers, when you start up before you call Wire.begin, get the state of the lines to get the address to use.

GearMachine

It's a long way to the top.

Go Up