oled 1.0
OLED Graphics Control Library
Loading...
Searching...
No Matches
twi.h
Go to the documentation of this file.
1
19
20#ifndef TWI_H_
21#define TWI_H_
22
23 #ifndef F_CPU
31 #define F_CPU 12000000UL
32 #endif
33
34 #ifndef F_TWI
42 #define F_TWI 100000UL
43 #endif
44
45 #ifndef TWI_PRESCALER
57 #define TWI_PRESCALER 0
58 #endif
59
60 #ifndef TWI_BITRATE
61 #ifdef TWI_PRESCALER
71 #define TWI_BITRATE ((F_CPU/F_TWI) - 16UL) / (2 * (1<<TWI_PRESCALER) * (1<<TWI_PRESCALER))
72 #endif
73 #endif
74
75 #ifndef TWI_ADDRESS
85 #define TWI_ADDRESS 0x42
86 #endif
87
88 #ifndef TWI_BROADCAST
98 #define TWI_BROADCAST 0x00
99 #endif
100
108 #ifndef TWI_STATUS_START
113 #define TWI_STATUS_START 0x08
114 #endif
115
116 #ifndef TWI_STATUS_REPEATED_START
121 #define TWI_STATUS_REPEATED_START 0x10
122 #endif
123
124 #ifndef TWI_STATUS_ADDRESS_WRITE_NACK
129 #define TWI_STATUS_ADDRESS_WRITE_NACK 0x18
130 #endif
131
132 #ifndef TWI_STATUS_ADDRESS_WRITE_ACK
137 #define TWI_STATUS_ADDRESS_WRITE_ACK 0x20
138 #endif
139
140 #ifndef TWI_STATUS_DATA_WRITE_NACK
145 #define TWI_STATUS_DATA_WRITE_NACK 0x28
146 #endif
147
148 #ifndef TWI_STATUS_DATA_WRITE_ACK
153 #define TWI_STATUS_DATA_WRITE_ACK 0x30
154 #endif
155
156 #ifndef TWI_STATUS_ARBITRATION_LOST
161 #define TWI_STATUS_ARBITRATION_LOST 0x38
162 #endif
163
164 #ifndef TWI_STATUS_ADDRESS_READ_ACK
169 #define TWI_STATUS_ADDRESS_READ_ACK 0x40
170 #endif
171
172 #ifndef TWI_STATUS_ADDRESS_READ_NACK
177 #define TWI_STATUS_ADDRESS_READ_NACK 0x48
178 #endif
179
180 #ifndef TWI_STATUS_DATA_READ_ACK
185 #define TWI_STATUS_DATA_READ_ACK 0x50
186 #endif
187
188 #ifndef TWI_STATUS_DATA_READ_NACK
193 #define TWI_STATUS_DATA_READ_NACK 0x58
194 #endif
196
197 #ifndef TWI_TWIE
209 // #define TWI_TWIE
210 #endif
211
212 #include <avr/io.h>
213
214 #ifdef TWI_TWIE
215 #include <avr/interrupt.h>
216 #endif
217
220
221 unsigned char twi_init(void);
222 void twi_disable(void);
223 unsigned char twi_status(void);
224
225 #ifndef TWI_TWIE
226 TWI_Error twi_start(void);
227 void twi_stop(void);
228 TWI_Error twi_address(unsigned char address, TWI_Operation operation);
229 TWI_Error twi_set(unsigned char data);
230 TWI_Error twi_get(unsigned char *data, TWI_Acknowledge acknowledge);
231 #endif
232
233
234#endif /* TWI_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