I2c Class Reference

#include <I2c.h>


Public Member Functions

 I2c (void)
unsigned char readByte (void)
unsigned char readByteWithoutAck (void)
void sendStart (void)
void sendStop (void)
void writeByte (unsigned char _byte)


Detailed Description

Definition at line 11 of file I2c.h.


Constructor & Destructor Documentation

I2c::I2c ( void   ) 

Definition at line 8 of file I2c.c.

References F_CPU, and TWI_CLK.

00008              {
00009 
00010   TWSR = 0x00;                            // prescale = 1
00011   TWBR = (unsigned char)(((double)((double)F_CPU / (double)TWI_CLK) - 16L) / 2L);  // 100kHz
00012 
00013 }


Member Function Documentation

unsigned char I2c::readByte ( void   ) 

Definition at line 55 of file I2c.c.

Referenced by Ram::readBytes().

00056 {
00057 
00058   TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);     // 
00059   while(!(TWCR & (1<<TWINT)));                         // wait till ready
00060   return TWDR;                          // data is in TWDR
00061 
00062 }

unsigned char I2c::readByteWithoutAck ( void   ) 

Definition at line 67 of file I2c.c.

Referenced by Ram::readBytes().

00068 {
00069 
00070   TWCR = (1 << TWINT) | (1 << TWEN);              // 
00071   while(!(TWCR & (1<<TWINT)));                         // wait till ready
00072   return TWDR;                          // data is in TWDR
00073 
00074 }

void I2c::sendStart ( void   ) 

Definition at line 19 of file I2c.c.

Referenced by Ram::readBytes(), and Ram::writeBytes().

00020 {
00021 
00022   TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);    // start condition
00023   while(!(TWCR & (1<<TWINT)));                    // wait for acknowledge
00024 
00025 }

void I2c::sendStop ( void   ) 

Definition at line 31 of file I2c.c.

Referenced by Ram::readBytes(), and Ram::writeBytes().

00032 {
00033 
00034   TWCR = (1 << TWINT) | (1 << TWSTO) | (1 << TWEN);    // stop condition =0;
00035 
00036 }

void I2c::writeByte ( unsigned char  _byte  ) 

Definition at line 42 of file I2c.c.

Referenced by Ram::readBytes(), and Ram::writeBytes().

00043 {
00044 
00045   //TWDR = 0x90;                                  // Byte
00046   TWDR = _byte;                                   // Byte
00047   TWCR = (1 << TWINT) | (1 << TWEN);                   // send
00048   while(!(TWCR & (1<<TWINT)));                    // wait until ready
00049 
00050 }


The documentation for this class was generated from the following files:

Generated on Wed Nov 25 11:27:44 2009 for Crawling Robot Microcontroller Software by  doxygen 1.5.5