37#include <avr/interrupt.h>
47 uint32_t base_frequency = (F_CPU / bus_speed);
48 TWBR = (uint8_t)((base_frequency - 16) / (2 * 1));
54 loop_until_bit_is_set(TWCR, TWINT);
59 TWCR = (_BV(TWINT) | _BV(TWEN) | _BV(TWSTA));
65 TWCR = (_BV(TWINT) | _BV(TWEN) | _BV(TWSTO));
71 TWCR = (_BV(TWINT) | _BV(TWEN));
78 TWCR = (_BV(TWINT) | _BV(TWEN) | _BV(TWEA));
85 TWCR = (_BV(TWINT) | _BV(TWEN));
void init_i2c(uint32_t bus_speed)
SCL frequency = F_CPU / (16 + (2 * TWBR) * PRESCALER)
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.