Programming AVR I2C Interface

I2C as many of you know, is a simple serial interface for many peripheral devices to micro controllers, but it can quickly become confusing to people who may not be accustom to it. Because of that, I2C tutorials are always welcome, and this new tutorial by [Embedds] does an excellent job of how to use I2C with an AVR with a 24C16 2Kbyte EEPROM.

The first half of the tutorial provides a clear explanation of how I2C works, including its signal structure, addressing, and data packets. It then moves on to AVR territory showing how to setup the I2C in an AtMega micro controller. The author uses a pretty standard to most of us Arduino, with software written in AVR C and a nifty little GUI programming application which eases the hassle of dealing with AVRDude directly.

Plenty of code samples follow from twiddling registers to a full blown application reading and writing bits from the EEPROM to a serial terminal on a PC.

8 thoughts on “Programming AVR I2C Interface

  1. It’s probably not worthwhile to connect an I2C EEPROM to an AVR, unless you have one lying around; AVRs are all about SPI for native communication, and SPI EEPROMs are readily available. Nevertheless, I’ve definitely found ultra-useful I2C devices without SPI equivalents, and this could be useful for that.

    Incidentally, I’ve seen a couple of I2C libraries around for AVRs, but never tried any of them. Can anyone confirm a particular one as being robust and not too heavy?

    1. I2C is native for the AVR, so it’s no heaver then UARTs for example. They call it TWI, I’m guessing to get around licensing issues, but it’s the same protocol.

      It works great, for Master->slave communication. However, we had a project that required a multi-master bus, and that didn’t work reliably with the TWI from the AVR. While it is a supported mode according to the datasheet.

      1. There’s something in the errata of most of the AVRs I use regarding the I2C/TWI bus. IIRC, there’s a 100ns ‘pulse’ on the I2C/TWI lines immediately after restart, and their ‘solution’ is to delay initialization of any other devices on the bus.

        Not sure if you’d read that, nor whether it’s even relevant to your particular device.

  2. How to calculate clock cycles taken per second in i2c interface?
    im using 33mhz processor
    only one master(MC)
    only one slave(camera)
    i want to transmit 200KB data over i2c(400kbps speed).
    so how long will it take to transfer?

    and also tell me how to calculate the clock cycle.,.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s