Home
Up
I2C library
Serial Interface

 

 

I2C library

 

The following source files and headers were written by me, Chris Keeser on 6/4 - 6/11 2005.  Copyright Chris Keeser 2005.
Updated on 6/21/05 to allow SDA and SCK to be on different ports
Updated on 7/16/05 to allow for clock stretching during byte recieve.  Can be enabled / disabled through condition compilation.  The I2Croutines.h header file contains the conditional compile flag CLOCK_STRETCHING.

bullet

I2Croutines.c 

bullet

I2Croutines.h
bullet

test.c

I2Croutines: 

#defines in the header file are used to set the specific port and pins.

bullet

void i2cInit(void)
bullet

Initializes the I2C interface pins

bullet

void start(void);
bullet

i2c start condition generator

bullet

void restart(void);
bullet

i2c restart condition generator

bullet

void sendByte(uint8_t);
bullet

shifts out a byte, msb first, data is latched in on the rising edge

bullet

uint8_t recieveByte(void);
bullet

shifts in a byte, msb first, data is latched in on the rising edge

bullet

void sendAck(void);
bullet

Master Acknowledge generator

bullet

void sendNack(void);
bullet

Master NO Acknowledge generator

bullet

uint8_t recieveAck(void);
bullet

Checks for slave Acknowledge

bullet

void stop(void);
bullet

i2c stop condition generator

Test.c is a test program written to demonstrate the use of the I2C functions.  with a serial port connected to uart1 on an atmega64 running at 7.4 Mhz (8 mhz internal RC oscillator with chip running at 3.3 volts), an i2c eeprom connected to a user specified port with pins sck and sda (all defined by modifying the header file I2C_routines.h) , a terminal open and running at 2400 baud, 8 data bits, 1 stop bit, no parity, type a letter in the terminal and the avr will get the first byte out of the eeprom, echo the typed character back and send the byte from the eeprom.  also important to note is that the 8 mhz calibration value needs to be stored in EEPROM location 0x000 in the onboard eeprom for the serial port to work properly.

 

 

Hit Counter