oled 1.0
OLED Graphics Control Library
|
Source file with implementation of hardware TWI/I2C functions and macros. More...
#include "twi.h"
Functions | |
unsigned char | twi_init (void) |
Initialize the TWI (I2C) hardware interface in master mode. | |
void | twi_disable (void) |
Disable the TWI (I2C) interface. | |
unsigned char | twi_status (void) |
Retrieves the current TWI status byte. | |
TWI_Error | twi_start (void) |
Initiates a TWI (I2C) (repeated) start condition on the bus. | |
void | twi_stop (void) |
Stop the TWI (I2C) transmission by generating a stop condition. | |
TWI_Error | twi_address (unsigned char address, TWI_Operation operation) |
Send a TWI (I2C) slave address combined with the read/write operation bit. | |
TWI_Error | twi_set (unsigned char data) |
Transmit a data byte over the TWI (I2C) bus. | |
TWI_Error | twi_get (unsigned char *data, TWI_Acknowledge acknowledge) |
Receive a data byte from the TWI (I2C) bus. |
Source file with implementation of hardware TWI/I2C functions and macros.
This file contains the definitions of function implementations and macros for hardware-based TWI (I2C) communication on AVR-0/1/2-Series microcontrollers.
|
inline |
Send a TWI (I2C) slave address combined with the read/write operation bit.
address | 7-bit slave address to be transmitted. |
operation | Specifies the operation type: 0 for write, 1 for read. |
This inline function constructs the address byte by shifting the 7-bit slave address left by one and combining it with the least significant bit representing the operation (read/write). It then calls twi_set to transmit this address byte over the TWI bus and returns the transmission status.
|
inline |
Disable the TWI (I2C) interface.
This inline function disables the hardware TWI module. This effectively releases control of the TWI lines and sets the pins to reset state. Use this function to safely deactivate the TWI bus when it is no longer needed.
TWI_Error twi_get | ( | unsigned char * | data, |
TWI_Acknowledge | acknowledge ) |
Receive a data byte from the TWI (I2C) bus.
data | Pointer to a variable where the received data byte will be stored. |
acknowledge | Specifies whether the master should send an ACK or NACK after receiving the byte:
|
This function configures the TWI hardware to receive a byte from the bus and decides whether to send an ACK or NACK based on the acknowledge parameter.
Depending on the acknowledge mode, the function sets the MCTRLB register to either send an ACK and prepare for more data reception or send a NACK and stop the communication.
Finally, the function returns the status code from the reception process.
unsigned char twi_init | ( | void | ) |
Initialize the TWI (I2C) hardware interface in master mode.
This function configures the TWI hardware registers to initialize the bus exclusively in master mode.
It sets the bitrate and activates the TWI controller using the predefined macros.
The function returns the initial TWI status for further status checking after initialization.
TWI_Error twi_set | ( | unsigned char | data | ) |
Transmit a data byte over the TWI (I2C) bus.
data | The data byte to be transmitted to the bus. |
This function writes the provided data byte into the TWI data register. It then waits for the transmission to complete by repeatedly checking the TWI status.
The function returns the final TWI status code indicating the result of the transmission.
|
inline |
Initiates a TWI (I2C) (repeated) start condition on the bus.
It does not perform any operation.
On modern AVR hardware, start conditions are managed internally by the TWI module, so this function is no longer necessary and does not initiate any bus activity.
|
inline |
Retrieves the current TWI status byte.
Reads and returns the TWI status byte from the TWSR register, including the write collision flag.
void twi_stop | ( | void | ) |
Stop the TWI (I2C) transmission by generating a stop condition.
This function initiates the TWI stop condition on the bus, signaling the end of the current communication frame. It sets the appropriate bits in the MCTRLB register to transmit the stop signal.