at24cm0x 1.0
at24cm0x driver 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_PER
31 #define F_PER 10000000UL
32 #endif
33
34 #ifndef F_TWI
42 #define F_TWI 100000UL
43 #endif
44
45 #ifndef T_RISE
46 #define T_RISE 1/(float)10000000.0
47 #endif
48
49 #ifndef TWI_BITRATE_CALCULATION
59 #define TWI_BITRATE_CALCULATION (unsigned char)(((float)F_PER)/(float)((F_TWI<<1)) - 5UL - ((unsigned int)(F_PER * (T_RISE))>>1))
60 #endif
61
62 #ifndef TWI_TIMEOUT
78 #define TWI_TIMEOUT TWI_TIMEOUT_DISABLED_gc
79 #endif
80
81 #ifndef TWI_PORTMUX
98 //#define TWI_PORTMUX PORTMUX_TWI0_ALT2_gc
99
100 #ifdef _DOXYGEN_ // Used for documentation, can be ignored
101 #define TWI_PORTMUX PORTMUX_TWI0_ALT2_gc
102 #endif
103 #endif
104
105 #ifndef TWI_TWIE
117 // #define TWI_TWIE
118 #endif
119
120 #include <avr/io.h>
121
122 #ifndef TWI_TWIE
123 #include <avr/interrupt.h>
124 #endif
125
126 #include "../common/defines/TWI_defines.h"
127 #include "../common/enums/TWI_enums.h"
128
129 unsigned char twi_init(void);
130 void twi_disable(void);
131 unsigned char twi_status(void);
132
133 #ifndef TWI_TWIE
134 TWI_Error twi_start(void);
135 void twi_stop(void);
136 TWI_Error twi_address(unsigned char address, TWI_Operation operation);
137 TWI_Error twi_set(unsigned char data);
138 TWI_Error twi_get(unsigned char *data, TWI_Acknowledge acknowledge);
139 #endif
140
141#endif /* TWI_H_ */
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:162
void twi_disable(void)
Disable the TWI (I2C) interface.
Definition twi.c:64
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:86
TWI_Error twi_set(unsigned char data)
Transmit a data byte over the TWI (I2C) bus.
Definition twi.c:193
void twi_stop(void)
Stop the TWI (I2C) transmission by generating a stop condition.
Definition twi.c:140
TWI_Error twi_get(unsigned char *data, TWI_Acknowledge acknowledge)
Receive a data byte from the TWI (I2C) bus.
Definition twi.c:230
TWI_Error twi_start(void)
Initiates a TWI (I2C) (repeated) start condition on the bus.
Definition twi.c:127