3.9.2 I2C with Dual Mode Operation
I2C (also known as Two-Wire Interface (TWI)) with Dual Mode supporting simultaneous host and client operations
3.9.2.1 Introduction
MCC Melody I2C Driver with Host and Client Interfaces
The Inter-Integrated Circuit (I2C) bus is a multi-host serial data communication bus, supported by a Two Wire Interface (TWI) peripheral on AVR MCUs. Devices communicate in a host/client environment where the host devices initiate the communication. A client device is controlled through addressing.
3.9.2.2 Supported Device Families
AVR® Dx | AVR® Ex | ATmega |
3.9.2.3 Required header files:
For host mode, include the following files in your application to use the I2C abstract driver:
#include <stdbool.h>
#include <stdint.h>
#include "mcc_generated_files/i2c_host/i2c_host_interface.h"
For client mode, include the following files in your application to use the I2C abstract driver:
#include <stdbool.h>
#include <stdint.h>
#include "mcc_generated_files/i2c_client/i2c_client_interface.h"
3.9.2.4 How to Use the TWI PLIB Driver
For use-cases for the TWI, see:
The examples there use the portable API interface of the driver, but could easily be modified to directly us the PLIB API.
3.9.2.5 Module Documentation
3.9.2.5.1 TWI1_CLIENT_TYPES
This header file provides APIs for the TWI1 driver.
Module description
This header file provides APIs for the TWI1 driver.
Enumerations
-
enum i2c_client_transfer_dir_t { I2C_CLIENT_TRANSFER_DIR_WRITE = 0, I2C_CLIENT_TRANSFER_DIR_READ = 1 }
I2C_CLIENT_TRANSFER_DIR Enumeration.
-
enum i2c_client_ack_status_t { I2C_CLIENT_ACK_STATUS_RECEIVED_ACK = 0, I2C_CLIENT_ACK_STATUS_RECEIVED_NACK = 1 }
I2C Ack/Nack status enumeration.
-
enum i2c_client_transfer_event_t { I2C_CLIENT_TRANSFER_EVENT_NONE = 0, I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH, I2C_CLIENT_TRANSFER_EVENT_RX_READY, I2C_CLIENT_TRANSFER_EVENT_TX_READY, I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED, I2C_CLIENT_TRANSFER_EVENT_ERROR }
I2C notification event type.
-
enum i2c_client_error_t { I2C_CLIENT_ERROR_NONE = 0, I2C_CLIENT_ERROR_BUS_ERROR, I2C_CLIENT_ERROR_COLLISION }
I2C client error type indicator.
Enumeration Type Documentation
i2c_client_ack_status_t
I2C Ack/Nack status enumeration.
I2C_CLIENT_ACK_STATUS_RECEIVED_ACK |
I2C Host is send ACK to client | |
I2C_CLIENT_ACK_STATUS_RECEIVED_NACK |
I2C Host is send NACK to client |
i2c_client_error_t
enum i2c_client_error_t
I2C client error type indicator.
I2C_CLIENT_ERROR_NONE |
I2C error none | |
I2C_CLIENT_ERROR_BUS_ERROR |
I2C Bus Error occurred | |
I2C_CLIENT_ERROR_COLLISION |
I2C Collision occurred |
i2c_client_transfer_dir_t
enum i2c_client_transfer_dir_t
I2C_CLIENT_TRANSFER_DIR Enumeration.
I2C_CLIENT_TRANSFER_DIR_WRITE |
I2C Host is writing to client | |
I2C_CLIENT_TRANSFER_DIR_READ |
I2C Host is reading from client |
i2c_client_transfer_event_t
enum i2c_client_transfer_event_t
I2C notification event type.
I2C_CLIENT_TRANSFER_EVENT_NONE |
I2C Bus Idle state | |
I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH |
Address match event | |
I2C_CLIENT_TRANSFER_EVENT_RX_READY |
Data sent by I2C Host is available | |
I2C_CLIENT_TRANSFER_EVENT_TX_READY |
I2C client can respond to data read request from I2C Host | |
I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED |
I2C stop bit received | |
I2C_CLIENT_TRANSFER_EVENT_ERROR |
I2C Bus error occurred |
3.9.2.5.2 TWI0_HOST_EVENT
This header file provides APIs for the TWI0 driver.
Module description
This header file provides APIs for the TWI0 driver.
Enumerations
-
enum i2c_event_states_t { I2C_STATE_IDLE = 0, I2C_STATE_SEND_RD_ADDR, I2C_STATE_SEND_WR_ADDR, I2C_STATE_TX, I2C_STATE_RX, I2C_STATE_NACK, I2C_STATE_ERROR, I2C_STATE_STOP, I2C_STATE_RESET }
Enumeration for I2C states.
3.9.2.5.3 TWI_HOST_TYPES
This header file provides APIs for the TWI0 driver.
Module description
This header file provides APIs for the TWI0 driver.
Data structures
-
struct I2C_TRANSFER_SETUP
Structure for I2C Clock Speed (100KHZ to 1MHZ)
Enumerations
-
enum i2c_host_error_t { I2C_ERROR_NONE, I2C_ERROR_ADDR_NACK, I2C_ERROR_DATA_NACK, I2C_ERROR_BUS_COLLISION }
Enumeration for I2C_ERROR code.
3.9.2.5.4 TWI_CLIENT
This header file provides APIs for the TWI1 driver.
Module description
This header file provides APIs for the TWI1 driver.
Functions
-
void TWI1_Initialize (void)
This routine initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This routine Deinitializes the TWI1 module. This function disables the module.
-
void TWI1_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI1_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI1_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI1_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
This function sets the pointer to be called "back" when the given I2C transfer events, Bus collision and Write collision occur.
-
void TWI1_Tasks (void)
This function is common Polling function for all TWI1 client.
Function Documentation
TWI1_CallbackRegister()
void TWI1_CallbackRegister (bool(*)(i2c_client_transfer_event_t clientEvent) callback)
This function sets the pointer to be called "back" when the given I2C transfer events, Bus collision and Write collision occur.
|
void |
TWI1_Deinitialize()
void TWI1_Deinitialize (void )
This routine Deinitializes the TWI1 module. This function disables the module.
This API Deinitializes the TWI1 module. This routine disables the TWI1 module.
|
void |
This routine Deinitializes the TWI1 module. This function disables the module.
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
void |
|
none |
TWI1_ErrorGet()
i2c_client_error_t TWI1_ErrorGet (void )
This function the error occurred during I2C Transmit and Receive.
|
|
This function get the error occurred during I2C Transmit and Receive.
|
|
|
|
TWI1_Initialize()
void TWI1_Initialize (void )
This routine initializes the TWI1 module.
This API initializes the TWI1 module.
|
void |
This routine initializes the TWI1 module.
This API initializes the I2C_Host driver.
Section: Public functions
|
void |
|
none |
Section: Public functions
TWI1_LastByteAckStatusGet()
i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void )
This function get the I2C Host ACK status.
|
|
TWI1_ReadAddr()
uint16_t TWI1_ReadAddr (void )
This function read requested address from a host on the bus.
|
address byte -TWI1 client read byte |
TWI1_ReadByte()
uint8_t TWI1_ReadByte (void )
This function read data from a host on the bus.
|
data byte -TWI1 client read byte |
TWI1_Tasks()
void TWI1_Tasks (void )
This function is common Polling function for all TWI1 client.
|
void |
TWI1_TransferDirGet()
i2c_client_transfer_dir_t TWI1_TransferDirGet (void )
This function get the I2C Transfer direction.
|
|
TWI1_WriteByte()
void TWI1_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
|
void |
3.9.2.5.5 TWI_HOST
This header file provides APIs for the TWI1 driver.
Module description
This header file provides APIs for the TWI1 driver.
Functions
-
void TWI1_Initialize (void)
This API initializes the I2C_Host driver.
-
void TWI1_Deinitialize (void)
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
-
bool TWI1_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI1_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
This API writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData.
-
i2c_host_error_t TWI1_ErrorGet (void)
This function get the error occurred during I2C Transmit and Receive.
-
bool TWI1_IsBusy (void)
This API checks if I2C is busy.
-
void TWI1_CallbackRegister (void(*handler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
void TWI1_ErrorCallbackRegister (void(*handler)(void))
Setter function for I2C Error interrupt callback.
-
void TWI1_Tasks (void)
This is polling function for non interrupt mode.
Function Documentation
TWI1_CallbackRegister()
void TWI1_CallbackRegister (void(*)(void) handler)
Setter function for I2C interrupt callback, This will be called when any error is generated.
|
none |
|
none |
TWI1_Deinitialize()
void TWI1_Deinitialize (void )
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
none |
This routine Deinitializes the TWI1 module. This function disables the module.
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
void |
|
none |
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
This API Deinitializes the TWI1 module. This routine disables the TWI1 module.
|
void |
This routine Deinitializes the TWI1 module. This function disables the module.
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
void |
|
none |
TWI1_ErrorCallbackRegister()
void TWI1_ErrorCallbackRegister (void(*)(void) handler)
Setter function for I2C Error interrupt callback.
|
none |
TWI1_ErrorGet()
i2c_host_error_t TWI1_ErrorGet (void )
This function get the error occurred during I2C Transmit and Receive.
|
i2c_host_error_t - I2C error code staus. |
|
|
This function get the error occurred during I2C Transmit and Receive.
|
|
|
|
This function get the error occurred during I2C Transmit and Receive.
|
|
This function get the error occurred during I2C Transmit and Receive.
|
|
|
|
TWI1_Initialize()
void TWI1_Initialize (void )
This API initializes the I2C_Host driver.
|
none |
This routine initializes the TWI1 module.
This API initializes the I2C_Host driver.
Section: Public functions
|
void |
|
none |
This API initializes the I2C_Host driver.
Section: Public functions
This API initializes the I2C_Host driver.
This API initializes the TWI1 module.
|
void |
This routine initializes the TWI1 module.
This API initializes the I2C_Host driver.
Section: Public functions
|
void |
|
none |
Section: Public functions
TWI1_IsBusy()
bool TWI1_IsBusy (void )
This API checks if I2C is busy.
|
|
TWI1_Read()
bool TWI1_Read (uint16_t address, uint8_t * data, size_t dataLength)
This API reads the data from a client on the bus.
|
|
TWI1_Tasks()
void TWI1_Tasks (void )
This is polling function for non interrupt mode.
|
none |
This is polling function for non interrupt mode.
|
void |
TWI1_Write()
bool TWI1_Write (uint16_t address, uint8_t * data, size_t dataLength)
This API writes data to a Client on the bus.
|
|
TWI1_WriteRead()
bool TWI1_WriteRead (uint16_t address, uint8_t * writeData, size_t writeLength, uint8_t * readData, size_t readLength)
This API writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData.
|
|
3.9.2.6 Class Documentation
3.9.2.6.1 i2c_event_status_t Struct Reference
The documentation for this struct was generated from the following file:
source/
Public Attributes
-
bool busy
-
uint16_t address
-
uint8_t * writePtr
-
size_t writeLength
-
uint8_t * readPtr
-
size_t readLength
-
bool switchToRead
-
i2c_host_error_t errorState
-
i2c_event_states_t state
3.9.2.6.2 I2C_TRANSFER_SETUP Struct Reference
Structure for I2C Clock Speed (100KHZ to 1MHZ)
Detailed Description
Structure for I2C Clock Speed (100KHZ to 1MHZ)
The documentation for this struct was generated from the following file:
source/
Public Attributes
-
uint32_t clkSpeed
3.9.2.7 File Documentation
3.9.2.7.1 source/i2c_client_types.h File Reference
Enumerations
-
enum i2c_client_transfer_dir_t { I2C_CLIENT_TRANSFER_DIR_WRITE = 0, I2C_CLIENT_TRANSFER_DIR_READ = 1 }
I2C_CLIENT_TRANSFER_DIR Enumeration.
-
enum i2c_client_ack_status_t { I2C_CLIENT_ACK_STATUS_RECEIVED_ACK = 0, I2C_CLIENT_ACK_STATUS_RECEIVED_NACK = 1 }
I2C Ack/Nack status enumeration.
-
enum i2c_client_transfer_event_t { I2C_CLIENT_TRANSFER_EVENT_NONE = 0, I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH, I2C_CLIENT_TRANSFER_EVENT_RX_READY, I2C_CLIENT_TRANSFER_EVENT_TX_READY, I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED, I2C_CLIENT_TRANSFER_EVENT_ERROR }
I2C notification event type.
-
enum i2c_client_error_t { I2C_CLIENT_ERROR_NONE = 0, I2C_CLIENT_ERROR_BUS_ERROR, I2C_CLIENT_ERROR_COLLISION }
I2C client error type indicator.
Detailed Description
TWI1 Generated Driver API Header File
3.9.2.7.2 source/i2c_host_event_types.h File Reference
#include "i2c_host_types.h"
Data structures
-
struct i2c_event_status_t
Enumerations
-
enum i2c_event_states_t { I2C_STATE_IDLE = 0, I2C_STATE_SEND_RD_ADDR, I2C_STATE_SEND_WR_ADDR, I2C_STATE_TX, I2C_STATE_RX, I2C_STATE_NACK, I2C_STATE_ERROR, I2C_STATE_STOP, I2C_STATE_RESET }
Enumeration for I2C states.
Detailed Description
TWI0 Generated Driver API Header File
3.9.2.7.3 source/i2c_host_types.h File Reference
Data structures
-
struct I2C_TRANSFER_SETUP
Structure for I2C Clock Speed (100KHZ to 1MHZ)
Enumerations
-
enum i2c_host_error_t { I2C_ERROR_NONE, I2C_ERROR_ADDR_NACK, I2C_ERROR_DATA_NACK, I2C_ERROR_BUS_COLLISION }
Enumeration for I2C_ERROR code.
Detailed Description
TWI0 Generated Driver API Header File
3.9.2.7.4 source/twi1_client_interrupt.c File Reference
This file contains the driver code for TWI1 module.
#include "../twi1.h" #include <stdbool.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI1_EventHandler ()
-
static void TWI1_ErrorEventHandler ()
-
static bool TWI1_DefaultCallback (i2c_client_transfer_event_t event)
-
void TWI1_Initialize (void)
This API initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This API Deinitializes the TWI1 module. This routine disables the TWI1 module.
-
void TWI1_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI1_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI1_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI1_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
This function sets the pointer to be called "back" when the given I2C transfer events, Bus collision and Write collision occur.
-
ISR (TWI1_TWIS_vect)
Variables
-
const struct I2C_CLIENT_INTERFACE I2C1_Client
-
static volatile uint16_t twi1Addr
-
static volatile i2c_client_error_ttwi1ErrorState
-
static bool(* TWI1_InterruptHandler )(i2c_client_transfer_event_t clientEvent) = NULL
Detailed Description
This file contains the driver code for TWI1 module.
TWI1 Generated Driver File
Function Documentation
TWI1_EventHandler()
static void TWI1_EventHandler (void )[static]
Section: Private functions declaration
Variable Documentation
I2C1_Client
const struct I2C_CLIENT_INTERFACE I2C1_Client
Initial value:
= { .Initialize = TWI1_Initialize, .Deinitialize = TWI1_Deinitialize, .WriteByte = TWI1_WriteByte, .ReadByte = TWI1_ReadByte, .TransferDirGet = TWI1_TransferDirGet, .LastByteAckStatusGet = TWI1_LastByteAckStatusGet, .ErrorGet = TWI1_ErrorGet, .CallbackRegister = TWI1_CallbackRegister, .Tasks = NULL }
Section: Driver Interface
twi1Addr
volatile uint16_t twi1Addr[static]
Section: Private Variable Definitions
3.9.2.7.5 source/twi1_client_interrupt.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h" #include "i2c_client_interface.h"
Functions
-
void TWI1_Initialize (void)
This routine initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This routine Deinitializes the TWI1 module. This function disables the module.
-
void TWI1_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI1_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI1_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI1_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
This function sets the pointer to be called "back" when the given I2C transfer events, Bus collision and Write collision occur.
Macros
-
#define I2C1_Client_InitializeTWI1_Initialize
-
#define I2C1_Client_DeinitializeTWI1_Deinitialize
-
#define I2C1_Client_WriteByteTWI1_WriteByte
-
#define I2C1_Client_ReadByteTWI1_ReadByte
-
#define I2C1_Client_ReadAddrTWI1_ReadAddr
-
#define I2C1_Client_ErrorGetTWI1_ErrorGet
-
#define I2C1_Client_TransferDirGetTWI1_TransferDirGet
-
#define I2C1_Client_LastByteAckStatusGetTWI1_LastByteAckStatusGet
-
#define I2C1_Client_CallbackRegisterTWI1_CallbackRegister
Variables
-
const struct I2C_CLIENT_INTERFACE I2C1_Client
Detailed Description
TWI1 Generated Driver API Header File
Macro Definition Documentation
i2c1_client_client_interface
#define i2c1_client_client_interface I2C1_Client
Section: Data Type Definitions
Variable Documentation
I2C1_Client
const struct I2C_CLIENT_INTERFACE I2C1_Client
Section: Driver Interface
3.9.2.7.6 source/twi1_client_polling.c File Reference
This file contains the driver code for TWI1 module.
#include "../twi1.h" #include <stdbool.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI1_EventHandler ()
-
static void TWI1_ErrorEventHandler ()
-
static bool TWI1_DefaultCallback (i2c_client_transfer_event_t event)
-
void TWI1_Initialize (void)
This routine initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This routine Deinitializes the TWI1 module. This function disables the module.
-
void TWI1_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI1_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI1_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI1_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
This function sets the pointer to be called "back" when the given I2C transfer events, Bus collision and Write collision occur.
-
void TWI1_Tasks (void)
This function is common Polling function for all TWI1 client.
Variables
-
const struct I2C_CLIENT_INTERFACE I2C1_Client
-
static volatile uint16_t twi1Addr
-
static volatile i2c_client_error_ttwi1ErrorState
-
static bool(* TWI1_InterruptHandler )(i2c_client_transfer_event_t clientEvent) = NULL
Detailed Description
This file contains the driver code for TWI1 module.
TWI1 Generated Driver File
Function Documentation
TWI1_EventHandler()
static void TWI1_EventHandler (void )[static]
Section: Private functions declaration
Variable Documentation
I2C1_Client
const struct I2C_CLIENT_INTERFACE I2C1_Client
Initial value:
= { .Initialize = TWI1_Initialize, .Deinitialize = TWI1_Deinitialize, .WriteByte = TWI1_WriteByte, .ReadByte = TWI1_ReadByte, .TransferDirGet = TWI1_TransferDirGet, .LastByteAckStatusGet = TWI1_LastByteAckStatusGet, .ErrorGet = TWI1_ErrorGet, .CallbackRegister = TWI1_CallbackRegister, .Tasks = TWI1_Tasks }
Section: Driver Interface
twi1Addr
volatile uint16_t twi1Addr[static]
Section: Private Variable Definitions
3.9.2.7.7 source/twi1_client_polling.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h" #include "i2c_client_interface.h"
Functions
-
void TWI1_Initialize (void)
This routine initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This routine Deinitializes the TWI1 module. This function disables the module.
-
void TWI1_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI1_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI1_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI1_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
This function sets the pointer to be called "back" when the given I2C transfer events, Bus collision and Write collision occur.
-
void TWI1_Tasks (void)
This function is common Polling function for all TWI1 client.
Macros
-
#define I2C1_Client_InitializeTWI1_Initialize
-
#define I2C1_Client_DeinitializeTWI1_Deinitialize
-
#define I2C1_Client_WriteByteTWI1_WriteByte
-
#define I2C1_Client_ReadByteTWI1_ReadByte
-
#define I2C1_Client_ReadAddrTWI1_ReadAddr
-
#define I2C1_Client_ErrorGetTWI1_ErrorGet
-
#define I2C1_Client_TransferDirGetTWI1_TransferDirGet
-
#define I2C1_Client_LastByteAckStatusGetTWI1_LastByteAckStatusGet
-
#define I2C1_Client_CallbackRegisterTWI1_CallbackRegister
-
#define I2C1_Client_TasksTWI1_Tasks
Variables
-
const struct I2C_CLIENT_INTERFACE I2C1_Client
Detailed Description
TWI1 Generated Driver API Header File
Macro Definition Documentation
i2c1_client_client_interface
#define i2c1_client_client_interface I2C1_Client
Section: Data Type Definitions
Variable Documentation
I2C1_Client
const struct I2C_CLIENT_INTERFACE I2C1_Client
Section: Driver Interface
3.9.2.7.8 source/twi1_host_interrupt.c File Reference
This file contains the driver code for TWI1 module.
#include "../twi1.h" #include <stdbool.h> #include <stdlib.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI1_Close (void)
-
static void TWI1_ReadStart (void)
-
static void TWI1_WriteStart (void)
-
static void TWI1_EventHandler (void)
-
static void TWI1_ErrorEventHandler (void)
-
static void TWI1_DefaultCallback (void)
-
static uint8_t TWI1_GetRxData (void)
-
static void TWI1_SendTxData (uint8_t data)
-
static void TWI1_SendTxAddr (uint8_t data)
-
static void TWI1_ClearInterruptFlag (void)
-
static void TWI1_ResetBus (void)
-
static void TWI1_EnableRestart (void)
-
static void TWI1_DisableRestart (void)
-
static void TWI1_SendStop (void)
-
static bool TWI1_IsNack (void)
-
static bool TWI1_IsBusError (void)
-
static bool TWI1_IsData (void)
-
static bool TWI1_IsAddr (void)
-
static void TWI1_ClearErrorFlags (void)
-
static void TWI1_EnableInterrupts (void)
-
static void TWI1_DisableInterrupts (void)
-
static void TWI1_ClearInterrupts (void)
-
static void TWI1_HostSendAck (void)
-
static void TWI1_HostSendNack (void)
-
static bool TWI1_IsArbitrationlostOverride (void)
-
static i2c_event_states_tI2C_EVENT_IDLE (void)
-
static i2c_event_states_tI2C_EVENT_SEND_RD_ADDR (void)
-
static i2c_event_states_tI2C_EVENT_SEND_WR_ADDR (void)
-
static i2c_event_states_tI2C_EVENT_TX (void)
-
static i2c_event_states_tI2C_EVENT_RX (void)
-
static i2c_event_states_tI2C_EVENT_NACK (void)
-
static i2c_event_states_tI2C_EVENT_ERROR (void)
-
static i2c_event_states_tI2C_EVENT_STOP (void)
-
static i2c_event_states_tI2C_EVENT_RESET (void)
-
void TWI1_Initialize (void)
This routine initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This routine Deinitializes the TWI1 module. This function disables the module.
-
bool TWI1_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI1_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
This API writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData.
-
i2c_host_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
bool TWI1_IsBusy (void)
This API checks if I2C is busy.
-
void TWI1_CallbackRegister (void(*callbackHandler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
ISR (TWI1_TWIM_vect)
Typedefs
-
typedef i2c_event_states_t(* twi1eventHandler) (void)
Variables
-
const i2c_host_interface_t I2C_Host
-
static void(* TWI1_Callback )(void) = NULL
-
volatile i2c_event_status_ttwi1_Status = {0}
-
const twi1eventHandler twi1_eventTable []
Detailed Description
This file contains the driver code for TWI1 module.
TWI1 Generated Driver File
Function Documentation
TWI1_GetRxData()
static uint8_t TWI1_GetRxData (void )[static]
Section: Register Level Interfaces
TWI1_ReadStart()
static void TWI1_ReadStart (void )[static]
Section: Private Interfaces
Variable Documentation
I2C_Host
const i2c_host_interface_t I2C_Host
Initial value:
= { .Initialize = TWI1_Initialize, .Deinitialize = TWI1_Deinitialize, .Write = TWI1_Write, .Read = TWI1_Read, .WriteRead = TWI1_WriteRead, .TransferSetup = NULL, .ErrorGet = TWI1_ErrorGet, .IsBusy = TWI1_IsBusy, .CallbackRegister = TWI1_CallbackRegister, .Tasks = NULL }
Section: Driver Interface
TWI1_Callback
void(* TWI1_Callback) (void) = NULL[static]
Section: Private Variable Definitions
twi1_eventTable
const twi1eventHandler twi1_eventTable[]
Initial value:
= { I2C_EVENT_IDLE, I2C_EVENT_SEND_RD_ADDR, I2C_EVENT_SEND_WR_ADDR, I2C_EVENT_TX, I2C_EVENT_RX, I2C_EVENT_NACK, I2C_EVENT_ERROR, I2C_EVENT_STOP, I2C_EVENT_RESET }
3.9.2.7.9 source/twi1_host_interrupt.h File Reference
#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include "i2c_host_types.h" #include "i2c_host_interface.h" #include "i2c_host_event_types.h"
Functions
-
void TWI1_Initialize (void)
This API initializes the I2C_Host driver.
-
void TWI1_Deinitialize (void)
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
-
bool TWI1_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI1_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
This API writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData.
-
i2c_host_error_t TWI1_ErrorGet (void)
This function get the error occurred during I2C Transmit and Receive.
-
bool TWI1_IsBusy (void)
This API checks if I2C is busy.
-
void TWI1_CallbackRegister (void(*handler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
void TWI1_ErrorCallbackRegister (void(*handler)(void))
Setter function for I2C Error interrupt callback.
Macros
-
#define i2c_host_host_interfaceI2C_Host
-
#define I2C_Host_InitializeTWI1_Initialize
-
#define I2C_Host_DeinitializeTWI1_Deinitialize
-
#define I2C_Host_WriteTWI1_Write
-
#define I2C_Host_ReadTWI1_Read
-
#define I2C_Host_WriteReadTWI1_WriteRead
-
#define I2C_Host_ErrorGetTWI1_ErrorGet
-
#define I2C_Host_IsBusyTWI1_IsBusy
-
#define I2C_Host_CallbackRegisterTWI1_CallbackRegister
-
#define TWI1_BAUD(F_SCL, T_RISE) ((((((float) 4000000 / (float)F_SCL)) - 10 - ((float)4000000 * T_RISE / 1000000))) / 2)
Variables
-
const i2c_host_interface_t I2C_Host
Detailed Description
TWI1 Generated Driver API Header File
Macro Definition Documentation
i2c_host_host_interface
#define i2c_host_host_interface I2C_Host
Section: Included FilesSection: Data Type Definitions
Variable Documentation
I2C_Host
const i2c_host_interface_t I2C_Host
Section: Driver Interface
3.9.2.7.10 source/twi1_host_polling.c File Reference
This file contains the driver code for TWI1 module.
#include "../twi1.h" #include <stdbool.h> #include <stdlib.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI1_Close (void)
-
static void TWI1_ReadStart (void)
-
static void TWI1_WriteStart (void)
-
static void TWI1_EventHandler (void)
-
static void TWI1_ErrorEventHandler (void)
-
static void TWI1_DefaultCallback (void)
-
static uint8_t TWI1_GetRxData (void)
-
static void TWI1_SendTxData (uint8_t data)
-
static void TWI1_SendTxAddr (uint8_t data)
-
static void TWI1_ClearInterruptFlag (void)
-
static void TWI1_ResetBus (void)
-
static void TWI1_EnableRestart (void)
-
static void TWI1_DisableRestart (void)
-
static void TWI1_SendStop (void)
-
static bool TWI1_IsNack (void)
-
static bool TWI1_IsBusError (void)
-
static bool TWI1_IsData (void)
-
static bool TWI1_IsAddr (void)
-
static void TWI1_ClearErrorFlags (void)
-
static void TWI1_EnableInterrupts (void)
-
static void TWI1_DisableInterrupts (void)
-
static void TWI1_ClearInterrupts (void)
-
static void TWI1_HostSendAck (void)
-
static void TWI1_HostSendNack (void)
-
static bool TWI1_IsArbitrationlostOverride (void)
-
static i2c_event_states_tI2C_EVENT_IDLE (void)
-
static i2c_event_states_tI2C_EVENT_SEND_RD_ADDR (void)
-
static i2c_event_states_tI2C_EVENT_SEND_WR_ADDR (void)
-
static i2c_event_states_tI2C_EVENT_TX (void)
-
static i2c_event_states_tI2C_EVENT_RX (void)
-
static i2c_event_states_tI2C_EVENT_NACK (void)
-
static i2c_event_states_tI2C_EVENT_ERROR (void)
-
static i2c_event_states_tI2C_EVENT_STOP (void)
-
static i2c_event_states_tI2C_EVENT_RESET (void)
-
void TWI1_Initialize (void)
This routine initializes the TWI1 module.
-
void TWI1_Deinitialize (void)
This routine Deinitializes the TWI1 module. This function disables the module.
-
bool TWI1_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI1_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
This API writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData.
-
i2c_host_error_t TWI1_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
bool TWI1_IsBusy (void)
This API checks if I2C is busy.
-
void TWI1_CallbackRegister (void(*callbackHandler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
void TWI1_Tasks (void)
This function is common Polling function for all TWI1 client.
Typedefs
-
typedef i2c_event_states_t(* twi1eventHandler) (void)
Variables
-
const i2c_host_interface_t I2C_Host
-
static void(* TWI1_Callback )(void) = NULL
-
volatile i2c_event_status_ttwi1_Status = {0}
-
const twi1eventHandler twi1_eventTable []
Detailed Description
This file contains the driver code for TWI1 module.
TWI1 Generated Driver File
Function Documentation
TWI1_GetRxData()
static uint8_t TWI1_GetRxData (void )[static]
Section: Register Level Interfaces
TWI1_ReadStart()
static void TWI1_ReadStart (void )[static]
Section: Private Interfaces
Variable Documentation
I2C_Host
const i2c_host_interface_t I2C_Host
Initial value:
= { .Initialize = TWI1_Initialize, .Deinitialize = TWI1_Deinitialize, .Write = TWI1_Write, .Read = TWI1_Read, .WriteRead = TWI1_WriteRead, .TransferSetup = NULL, .ErrorGet = TWI1_ErrorGet, .IsBusy = TWI1_IsBusy, .CallbackRegister = TWI1_CallbackRegister, .Tasks = TWI1_Tasks }
Section: Driver Interface
TWI1_Callback
void(* TWI1_Callback) (void) = NULL[static]
Section: Private Variable Definitions
twi1_eventTable
const twi1eventHandler twi1_eventTable[]
Initial value:
= { I2C_EVENT_IDLE, I2C_EVENT_SEND_RD_ADDR, I2C_EVENT_SEND_WR_ADDR, I2C_EVENT_TX, I2C_EVENT_RX, I2C_EVENT_NACK, I2C_EVENT_ERROR, I2C_EVENT_STOP, I2C_EVENT_RESET }
3.9.2.7.11 source/twi1_host_polling.h File Reference
#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include "i2c_host_types.h" #include "i2c_host_interface.h" #include "i2c_host_event_types.h"
Functions
-
void TWI1_Initialize (void)
This API initializes the I2C_Host driver.
-
void TWI1_Deinitialize (void)
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
-
bool TWI1_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI1_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
This API writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData.
-
i2c_host_error_t TWI1_ErrorGet (void)
This function get the error occurred during I2C Transmit and Receive.
-
bool TWI1_IsBusy (void)
This API checks if I2C is busy.
-
void TWI1_Tasks (void)
This is polling function for non interrupt mode.
-
void TWI1_CallbackRegister (void(*handler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
Macros
-
#define i2c_host_host_interfaceI2C_Host
-
#define I2C_Host_InitializeTWI1_Initialize
-
#define I2C_Host_DeinitializeTWI1_Deinitialize
-
#define I2C_Host_WriteTWI1_Write
-
#define I2C_Host_ReadTWI1_Read
-
#define I2C_Host_WriteReadTWI1_WriteRead
-
#define I2C_Host_ErrorGetTWI1_ErrorGet
-
#define I2C_Host_IsBusyTWI1_IsBusy
-
#define I2C_Host_CallbackRegisterTWI1_CallbackRegister
-
#define I2C_Host_TasksTWI1_Tasks
-
#define TWI1_BAUD(F_SCL, T_RISE) ((((((float)4000000 / (float)F_SCL)) - 10 - ((float)4000000 * T_RISE / 1000000))) / 2)
Variables
-
const i2c_host_interface_t I2C_Host
Detailed Description
TWI1 Generated Driver API Header File
Variable Documentation
I2C_Host
const i2c_host_interface_t I2C_Host
Section: Data Type Definitions
Section: Driver Interface