40#include <avr/interrupt.h>
51 uint32_t base_frequency = (F_CPU / bus_speed);
52 TWBR = (uint8_t)((base_frequency - 16) / (2 * 1));
63 loop_until_bit_is_set(TWCR, TWINT);
72 TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTA);
82 TWCR = (1 << TWINT) | (1 << TWEN) | (1 <<TWSTO);
93 TWCR = (1 << TWINT) | (1 << TWEN);
104 TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
117 TWCR = (1 << TWINT) | (1 << TWEN);
void init_i2c(uint32_t bus_speed)
Sets pullups and initializes i2c clock to desired bus speed.
void i2c_wait_for_complete(void)
Loops until the i2c message is complete, as the hardware sets the TWINT flag.
uint8_t i2c_read_no_ack(void)
Read in from slave, sending NOACK when done (no TWEA).
uint8_t i2c_read_ack(void)
Read in from slave, sending ACK when done (sets TWEA).
void i2c_stop(void)
Sends a stop condition (sets TWSTO).
void i2c_send(uint8_t data)
Loads data, sends it out, waiting for completion.
void i2c_start(void)
Sends a start condition (sets TWSTA).
I2C communications driver for AVR MCU's.