![]() |
Atmel AVR156: TWI Master bit bang driver
100
|
Bit bang TWI master driver. More...
#include "ioavr.h"#include "inavr.h"Go to the source code of this file.
Defines | |
| #define | SCL PC1 |
| Definition of pin used as SCL. | |
| #define | SDA PC4 |
| Definition of pin used as SDA. | |
| #define | PORT_SCL PORTC |
| Definition of PORT used as SCL. | |
| #define | DDR_SCL DDRC |
| Definition of DDR used as SCL. | |
| #define | PIN_SCL PINC |
| Definition of PIN used as SCL. | |
| #define | PORT_SDA PORTC |
| Definition of PORT used as SDA. | |
| #define | DDR_SDA DDRC |
| Definition of DDR used as SDA. | |
| #define | PIN_SDA PINC |
| Definition of PIN used as SDA. | |
| #define | SLAVE_ADDRESS 0xA0 |
| Slave 8 bit address (shifted). | |
| #define | READ_SDA() (PIN_SDA & (1 << SDA)) |
| #define | SET_SDA_OUT() DDR_SDA |= (1 << SDA) |
| #define | SET_SDA_IN() DDR_SDA &= ~(1 << SDA) |
| #define | READ_SCL() (PIN_SCL & (1 << SCL))?1:0 |
| #define | WRITE 0x0 |
| #define | READ 0x1 |
| #define | DELAY 2 |
| Delay used to generate clock. | |
| #define | SCL_SDA_DELAY 1 |
| Delay used for STOP condition. | |
Functions | |
| void | twi_disable () |
| disables twi master mode | |
| void | twi_init () |
| initialize twi master mode | |
| void | toggle_scl () |
| Toggles SCL. | |
| void | write_scl (char x) |
| Writes SCL. | |
| char | twi_start_cond (void) |
| Sends start condition. | |
| char | send_slave_address (unsigned char read) |
| Sends slave address. | |
| char | write_data (unsigned char *data, 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 *data, unsigned char bytes, unsigned char index) |
| Reads one byte into buffer. | |
| void | write_sda (char x) |
| Writes SDA. | |
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.
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
| char i2c_read_byte | ( | unsigned char * | rcvdata, |
| unsigned char | bytes, | ||
| unsigned char | index | ||
| ) |
Reads one byte into buffer.
| rcvdata | Pointer to data buffer |
| bytes | Number of bytes to read |
| index | Position of the incoming byte in hte receive buffer |
| char i2c_write_byte | ( | unsigned char | byte | ) |
Writes a byte on TWI.
| byte | Data |
| char read_bytes | ( | unsigned char * | data, |
| char | bytes | ||
| ) |
Reads data into buffer.
| data | Pointer to data buffer |
| bytes | Number of bytes to read |
| char write_data | ( | unsigned char * | indata, |
| char | bytes | ||
| ) |
Writes data from buffer.
| indata | Pointer to data buffer |
| bytes | Number of bytes to transfer |
| void write_scl | ( | char | x | ) |
Writes SCL.
| x | tristates SCL when x = 1, other wise 0 |
| void write_sda | ( | char | x | ) |
Writes SDA.
| x | tristates SDA when x = 1, other wise 0 |