AVRly - AVR Development Resources
|
I2C communications driver for AVR MCU's. More...
Go to the source code of this file.
Functions | |
void | init_i2c (uint32_t bus_speed) |
SCL frequency = F_CPU / (16 + (2 * TWBR) * PRESCALER) 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 bits in registers.
Definition in file i2c.c.
void init_i2c | ( | uint32_t | bus_speed | ) |
SCL frequency = F_CPU / (16 + (2 * TWBR) * PRESCALER)
Sets pullups and initializes bus speed to desired bus speed.
Sets pullups and initializes i2c clock to desired bus speed.
Definition at line 45 of file i2c.c.
void i2c_wait_for_complete | ( | void | ) |
void i2c_start | ( | void | ) |
Sends a start condition (sets TWSTA).
Definition at line 57 of file i2c.c.
void i2c_stop | ( | void | ) |
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 68 of file i2c.c.
uint8_t i2c_read_ack | ( | void | ) |
Read in from slave, sending ACK when done (sets TWEA).
Definition at line 76 of file i2c.c.
uint8_t i2c_read_no_ack | ( | void | ) |
Read in from slave, sending NOACK when done (no TWEA).