Atmel AVR156: TWI Master bit bang driver  100
TWI_master.c File Reference

Bit bang TWI master driver. More...

#include "TWI_master.h"

Functions

void twi_init ()
 initialize twi master mode
void twi_disable ()
 disables twi master mode
char twi_start_cond (void)
 Sends start condition.
char send_slave_address (unsigned char read)
 Sends slave address.
char write_data (unsigned char *indata, char bytes)
 Writes data from buffer.
char i2c_write_byte (unsigned char byte)
 Writes a byte on TWI.
char read_bytes (unsigned char *data, char bytes)
 Reads data into buffer.
char i2c_read_byte (unsigned char *rcvdata, unsigned char bytes, unsigned char index)
 Reads one byte into buffer.
void write_scl (char x)
 Writes SCL.
void write_sda (char x)
 Writes SDA.
void toggle_scl ()
 Toggles SCL.

Detailed Description

Bit bang TWI master driver.

This file contains the function prototypes and enumerator definitions for various configuration parameters for the AVR TWI master driver.

The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the AVR TWI master.

For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.

Date:
2012-06-01 13:03:43


Copyright (c) 2012, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author: gary.grewal


Function Documentation

char i2c_read_byte ( unsigned char *  rcvdata,
unsigned char  bytes,
unsigned char  index 
)

Reads one byte into buffer.

Parameters:
rcvdataPointer to data buffer
bytesNumber of bytes to read
indexPosition of the incoming byte in hte receive buffer
Returns:
1 if successful, otherwise 0
char i2c_write_byte ( unsigned char  byte)

Writes a byte on TWI.

Parameters:
byteData
Returns:
1 if successful, otherwise 0
char read_bytes ( unsigned char *  data,
char  bytes 
)

Reads data into buffer.

Parameters:
dataPointer to data buffer
bytesNumber of bytes to read
Returns:
1 if successful, otherwise 0
char write_data ( unsigned char *  indata,
char  bytes 
)

Writes data from buffer.

Parameters:
indataPointer to data buffer
bytesNumber of bytes to transfer
Returns:
1 if successful, otherwise 0
void write_scl ( char  x)

Writes SCL.

Parameters:
xtristates SCL when x = 1, other wise 0
void write_sda ( char  x)

Writes SDA.

Parameters:
xtristates SDA when x = 1, other wise 0