31 #define F_CPU 12000000UL
42 #define F_TWI 100000UL
57 #define TWI_PRESCALER 0
71 #define TWI_BITRATE ((F_CPU/F_TWI) - 16UL) / (2 * (1<<TWI_PRESCALER) * (1<<TWI_PRESCALER))
85 #define TWI_ADDRESS 0x42
98 #define TWI_BROADCAST 0x00
108 #ifndef TWI_STATUS_START
113 #define TWI_STATUS_START 0x08
116 #ifndef TWI_STATUS_REPEATED_START
121 #define TWI_STATUS_REPEATED_START 0x10
124 #ifndef TWI_STATUS_ADDRESS_WRITE_NACK
129 #define TWI_STATUS_ADDRESS_WRITE_NACK 0x18
132 #ifndef TWI_STATUS_ADDRESS_WRITE_ACK
137 #define TWI_STATUS_ADDRESS_WRITE_ACK 0x20
140 #ifndef TWI_STATUS_DATA_WRITE_NACK
145 #define TWI_STATUS_DATA_WRITE_NACK 0x28
148 #ifndef TWI_STATUS_DATA_WRITE_ACK
153 #define TWI_STATUS_DATA_WRITE_ACK 0x30
156 #ifndef TWI_STATUS_ARBITRATION_LOST
161 #define TWI_STATUS_ARBITRATION_LOST 0x38
164 #ifndef TWI_STATUS_ADDRESS_READ_ACK
169 #define TWI_STATUS_ADDRESS_READ_ACK 0x40
172 #ifndef TWI_STATUS_ADDRESS_READ_NACK
177 #define TWI_STATUS_ADDRESS_READ_NACK 0x48
180 #ifndef TWI_STATUS_DATA_READ_ACK
185 #define TWI_STATUS_DATA_READ_ACK 0x50
188 #ifndef TWI_STATUS_DATA_READ_NACK
193 #define TWI_STATUS_DATA_READ_NACK 0x58
215 #include <avr/interrupt.h>
Macro definitions for TWI/I2C communication flags and operations.
Enumerations for TWI/I2C interface modes, operations, acknowledgment, and error codes.
enum TWI_Acknowledge_t TWI_Acknowledge
Alias for enum TWI_Acknowledge_t representing TWI acknowledge mode.
Definition TWI_enums.h:66
enum TWI_Operation_t TWI_Operation
Alias for enum TWI_Operation_t representing TWI operation modes.
Definition TWI_enums.h:48
enum TWI_Error_t TWI_Error
Alias for enum TWI_Error_t representing TWI error status.
Definition TWI_enums.h:89
TWI_Error twi_address(unsigned char address, TWI_Operation operation)
Send a TWI (I2C) slave address combined with the read/write operation bit.
Definition twi.c:145
void twi_disable(void)
Disable the TWI (I2C) interface.
Definition twi.c:56
unsigned char twi_init(void)
Initialize the TWI (I2C) hardware interface in master mode.
Definition twi.c:36
unsigned char twi_status(void)
Retrieves the current TWI status byte.
Definition twi.c:78
TWI_Error twi_set(unsigned char data)
Transmit a data byte over the TWI (I2C) bus.
Definition twi.c:168
void twi_stop(void)
Stop the TWI (I2C) transmission by generating a stop condition.
Definition twi.c:120
TWI_Error twi_get(unsigned char *data, TWI_Acknowledge acknowledge)
Receive a data byte from the TWI (I2C) bus.
Definition twi.c:210
TWI_Error twi_start(void)
Initiates a TWI (I2C) (repeated) start condition on the bus.
Definition twi.c:96