TwiceAsNice  2019-02-18
i2cmaster.h File Reference
#include <avr/io.h>
Include dependency graph for i2cmaster.h:
This graph shows which files directly or indirectly include this file:
#define I2C_READ   1
 defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() More...
 
#define I2C_WRITE   0
 defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() More...
 
#define i2c_read(ack)   (ack) ? i2c_readAck() : i2c_readNak();
 
void i2c_init (void)
 
initialize the I2C master interace. More...
 
void i2c_stop (void)
 
Terminates the data transfer and releases the I2C bus More...
 
unsigned char i2c_start (unsigned char addr)
 
Issues a start condition and sends address and transfer direction More...
 
unsigned char i2c_rep_start (unsigned char addr)
 
Issues a repeated start condition and sends address and transfer direction More...
 
void i2c_start_wait (unsigned char addr)
 
Issues a start condition and sends address and transfer direction More...
 
unsigned char i2c_write (unsigned char data)
 
Send one byte to I2C device More...
 
unsigned char i2c_readAck (void)
 
read one byte from the I2C device, request more data from device More...
 
unsigned char i2c_readNak (void)
 
read one byte from the I2C device, read is followed by a stop condition More...
 
unsigned char i2c_read (unsigned char ack)
 
read one byte from the I2C device More...
 

Macro Definition Documentation

◆ I2C_READ

#define I2C_READ   1

defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start()

◆ i2c_read

#define i2c_read (   ack)    (ack) ? i2c_readAck() : i2c_readNak();

◆ I2C_WRITE

#define I2C_WRITE   0

defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start()

Function Documentation

◆ i2c_init()

void i2c_init ( void  )


initialize the I2C master interace.

Need to be called only once

Parameters
void
Returns
none

◆ i2c_read()

unsigned char i2c_read ( unsigned char  ack)


read one byte from the I2C device

Implemented as a macro, which calls either i2c_readAck or i2c_readNak

Parameters
ack1 send ack, request more data from device
0 send nak, read is followed by a stop condition
Returns
byte read from I2C device

◆ i2c_readAck()

unsigned char i2c_readAck ( void  )


read one byte from the I2C device, request more data from device

Returns
byte read from I2C device

◆ i2c_readNak()

unsigned char i2c_readNak ( void  )


read one byte from the I2C device, read is followed by a stop condition

Returns
byte read from I2C device

◆ i2c_rep_start()

unsigned char i2c_rep_start ( unsigned char  addr)


Issues a repeated start condition and sends address and transfer direction

Parameters
addraddress and transfer direction of I2C device
Return values
0device accessible
1failed to access device

◆ i2c_start()

unsigned char i2c_start ( unsigned char  addr)


Issues a start condition and sends address and transfer direction

Parameters
addraddress and transfer direction of I2C device
Return values
0device accessible
1failed to access device

◆ i2c_start_wait()

void i2c_start_wait ( unsigned char  addr)


Issues a start condition and sends address and transfer direction

If device is busy, use ack polling to wait until device ready

Parameters
addraddress and transfer direction of I2C device
Returns
none

◆ i2c_stop()

void i2c_stop ( void  )


Terminates the data transfer and releases the I2C bus

Parameters
void
Returns
none

◆ i2c_write()

unsigned char i2c_write ( unsigned char  data)


Send one byte to I2C device

Parameters
databyte to be transfered
Return values
0write successful
1write failed