Implementing I2C

The ATmega32u2 doesn’t have a two-wire interface (as far as I can tell) or I2C, so this method was used to have an I2C bus. The circuit shows the SCL line, and the same circuit is duplicated for the SDA line.

i2c.jpg

Then, the attached code here i2c1.txt was used.

Only the I2C write capability was tested, and it worked fine. The I2C read should work, but it has not been tested yet.

This was an example write, to the TEF6606 ic:


init();

delay_10ms(400);

i2c_start();
i2c_write(0xc0); // write to the tuner's address
i2c_write(0x00); // mode and sub-addr: standard mode, sub-addr tuner0
// tuner0:
i2c_write(0x27); // tuner0: Europe FM, write high bits for freq 98.8MHz
i2c_stop();

i2c_start();
i2c_write(0xc0); // write to the tuner's address
i2c_write(0x21); // mode and sub-addr: preset mode, sub-addr tuner1
// tuner1:
i2c_write(0xb8); // tuner1: Write low bits forĀ  freq 98.8MHz
i2c_stop();

This entry was posted in microcontroller, radio. Bookmark the permalink.

Leave a Reply