AVRly - AVR Development Resources
|
I2C communications driver for AVR MCU's. More...
#include <avr/io.h>
Go to the source code of this file.
Functions | |
void | init_i2c (uint32_t bus_speed) |
Sets pullups and initializes i2c clock to desired bus speed. More... | |
void | i2c_wait_for_complete (void) |
Loops until the i2c message is complete, as the hardware sets the TWINT flag. More... | |
void | i2c_start (void) |
Sends a start condition (sets TWSTA). More... | |
void | i2c_stop (void) |
Sends a stop condition (sets TWSTO). More... | |
void | i2c_send (uint8_t data) |
Loads data, sends it out, waiting for completion. More... | |
uint8_t | i2c_read_ack (void) |
Read in from slave, sending ACK when done (sets TWEA). More... | |
uint8_t | i2c_read_no_ack (void) |
Read in from slave, sending NOACK when done (no TWEA). More... | |
I2C communications driver for AVR MCU's.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file provides basic I2C protocol comms functionality. Please note: Blocking waits are used whilst the host waits for hardware to set flags in registers.
The symbol F_CPU must be defined for the bus timing calculations - usually defined in Makefile.
Definition in file atmega_i2c.h.
void init_i2c | ( | uint32_t | bus_speed | ) |
Sets pullups and initializes i2c clock to desired bus speed.
bus_speed | is the desired i2c clock frequency. |
Sets pullups and initializes i2c clock to desired bus speed.
Definition at line 49 of file atmega_i2c.c.
void i2c_wait_for_complete | ( | void | ) |
Loops until the i2c message is complete, as the hardware sets the TWINT flag.
Definition at line 61 of file atmega_i2c.c.
void i2c_start | ( | void | ) |
Sends a start condition (sets TWSTA).
Definition at line 70 of file atmega_i2c.c.
void i2c_stop | ( | void | ) |
Sends a stop condition (sets TWSTO).
Definition at line 80 of file atmega_i2c.c.
void i2c_send | ( | uint8_t | data | ) |
Loads data, sends it out, waiting for completion.
data | is the byte of data to be sent. |
Definition at line 90 of file atmega_i2c.c.
uint8_t i2c_read_ack | ( | void | ) |
Read in from slave, sending ACK when done (sets TWEA).
Definition at line 102 of file atmega_i2c.c.
uint8_t i2c_read_no_ack | ( | void | ) |
Read in from slave, sending NOACK when done (no TWEA).
Definition at line 115 of file atmega_i2c.c.