3.9.1 I2C
I2C (also known as Two-Wire Interface (TWI))
3.9.1.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.1.2 Supported Device Families
ATtiny |
3.9.1.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.1.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.1.5 Module Documentation
3.9.1.5.1 TWI0_CLIENT_TYPES
This header file provides APIs for the TWI0 driver.
Module description
This header file provides APIs for the TWI0 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.1.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.1.5.3 TWI0
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.1.5.4 TWI_CLIENT
This header file provides APIs for the TWI0 driver.
Module description
This header file provides APIs for the TWI0 driver.
Functions
-
void TWI0_Initialize (void)
This routine initializes the TWI0 module.
-
void TWI0_Deinitialize (void)
This routine Deinitializes the TWI0 module. This function disables the module.
-
void TWI0_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI0_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI0_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI0_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI0_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI0_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI0_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 TWI0_Tasks (void)
This function is common Polling function for all TWI0 client.
Function Documentation
TWI0_CallbackRegister()
void TWI0_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 |
TWI0_Deinitialize()
void TWI0_Deinitialize (void )
This routine Deinitializes the TWI0 module. This function disables the module.
This API Deinitializes the TWI0 module. This routine disables the TWI0 module.
|
void |
This routine Deinitializes the TWI0 module. This function disables the module.
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
void |
|
none |
TWI0_ErrorGet()
i2c_client_error_t TWI0_ErrorGet (void )
This function the error occurred during I2C Transmit and Receive.
|
|
This function get the error occurred during I2C Transmit and Receive.
|
|
|
|
TWI0_Initialize()
void TWI0_Initialize (void )
This routine initializes the TWI0 module.
This API initializes the TWI0 module.
|
void |
This routine initializes the TWI0 module.
This API initializes the I2C_Host driver.
Section: Public functions
|
void |
|
none |
Section: Public functions
TWI0_LastByteAckStatusGet()
i2c_client_ack_status_t TWI0_LastByteAckStatusGet (void )
This function get the I2C Host ACK status.
|
|
TWI0_ReadAddr()
uint16_t TWI0_ReadAddr (void )
This function read requested address from a host on the bus.
|
address byte -TWI0 client read byte |
TWI0_ReadByte()
uint8_t TWI0_ReadByte (void )
This function read data from a host on the bus.
|
data byte -TWI0 client read byte |
TWI0_Tasks()
void TWI0_Tasks (void )
This function is common Polling function for all TWI0 client.
|
void |
TWI0_TransferDirGet()
i2c_client_transfer_dir_t TWI0_TransferDirGet (void )
This function get the I2C Transfer direction.
|
|
TWI0_WriteByte()
void TWI0_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
|
void |
3.9.1.5.5 TWI_HOST
This header file provides APIs for the TWI0 driver.
Module description
This header file provides APIs for the TWI0 driver.
Functions
-
void TWI0_Initialize (void)
This API initializes the I2C_Host driver.
-
void TWI0_Deinitialize (void)
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
-
bool TWI0_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI0_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI0_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 TWI0_ErrorGet (void)
This function get the error occurred during I2C Transmit and Receive.
-
bool TWI0_IsBusy (void)
This API checks if I2C is busy.
-
void TWI0_CallbackRegister (void(*handler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
void TWI0_ErrorCallbackRegister (void(*handler)(void))
Setter function for I2C Error interrupt callback.
-
void TWI0_Tasks (void)
This is polling function for non interrupt mode.
Function Documentation
TWI0_CallbackRegister()
void TWI0_CallbackRegister (void(*)(void) handler)
Setter function for I2C interrupt callback, This will be called when any error is generated.
|
none |
|
none |
TWI0_Deinitialize()
void TWI0_Deinitialize (void )
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
none |
This routine Deinitializes the TWI0 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 TWI0 module. This routine disables the TWI0 module.
|
void |
This routine Deinitializes the TWI0 module. This function disables the module.
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
|
void |
|
none |
TWI0_ErrorCallbackRegister()
void TWI0_ErrorCallbackRegister (void(*)(void) handler)
Setter function for I2C Error interrupt callback.
|
none |
TWI0_ErrorGet()
i2c_host_error_t TWI0_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.
|
|
|
|
TWI0_Initialize()
void TWI0_Initialize (void )
This API initializes the I2C_Host driver.
|
none |
This routine initializes the TWI0 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 TWI0 module.
|
void |
This routine initializes the TWI0 module.
This API initializes the I2C_Host driver.
Section: Public functions
|
void |
|
none |
Section: Public functions
TWI0_IsBusy()
bool TWI0_IsBusy (void )
This API checks if I2C is busy.
|
|
TWI0_Read()
bool TWI0_Read (uint16_t address, uint8_t * data, size_t dataLength)
This API reads the data from a client on the bus.
|
|
TWI0_Tasks()
void TWI0_Tasks (void )
This is polling function for non interrupt mode.
|
none |
This is polling function for non interrupt mode.
|
void |
TWI0_Write()
bool TWI0_Write (uint16_t address, uint8_t * data, size_t dataLength)
This API writes data to a Client on the bus.
|
|
TWI0_WriteRead()
bool TWI0_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.1.6 Class Documentation
3.9.1.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.1.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/i2c_host_types.h
Public Attributes
-
uint32_t clkSpeed
3.9.1.7 File Documentation
3.9.1.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
TWI0 Generated Driver API Header File
3.9.1.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.1.7.3 source/twi_client_interrupt.c File Reference
This file contains the driver code for TWI0 module.
#include "../twi0.h" #include <stdbool.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI0_EventHandler ()
-
static void TWI0_ErrorEventHandler ()
-
static bool TWI0_DefaultCallback (i2c_client_transfer_event_t event)
-
void TWI0_Initialize (void)
This API initializes the TWI0 module.
-
void TWI0_Deinitialize (void)
This API Deinitializes the TWI0 module. This routine disables the TWI0 module.
-
void TWI0_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI0_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI0_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI0_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI0_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI0_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI0_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 (TWI0_TWIS_vect)
Variables
-
const struct I2C_CLIENT_INTERFACE I2C_Client
-
static volatile uint16_t twi0Addr
-
static volatile i2c_client_error_ttwi0ErrorState
-
static bool(* TWI0_InterruptHandler )(i2c_client_transfer_event_t clientEvent) = NULL
Detailed Description
This file contains the driver code for TWI0 module.
TWI0 Generated Driver File
Function Documentation
TWI0_EventHandler()
static void TWI0_EventHandler (void )[static]
Section: Private functions declaration
Variable Documentation
I2C_Client
const struct I2C_CLIENT_INTERFACE I2C_Client
Initial value:
= { .Initialize = TWI0_Initialize, .Deinitialize = TWI0_Deinitialize, .WriteByte = TWI0_WriteByte, .ReadByte = TWI0_ReadByte, .TransferDirGet = TWI0_TransferDirGet, .LastByteAckStatusGet = TWI0_LastByteAckStatusGet, .ErrorGet = TWI0_ErrorGet, .CallbackRegister = TWI0_CallbackRegister, .Tasks = NULL }
Section: Driver Interface
twi0Addr
volatile uint16_t twi0Addr[static]
Section: Private Variable Definitions
3.9.1.7.4 source/twi_client_interrupt.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h" #include "i2c_client_interface.h"
Functions
-
void TWI0_Initialize (void)
This routine initializes the TWI0 module.
-
void TWI0_Deinitialize (void)
This routine Deinitializes the TWI0 module. This function disables the module.
-
void TWI0_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI0_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI0_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI0_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI0_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI0_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI0_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 I2C_Client_InitializeTWI0_Initialize
-
#define I2C_Client_DeinitializeTWI0_Deinitialize
-
#define I2C_Client_WriteByteTWI0_WriteByte
-
#define I2C_Client_ReadByteTWI0_ReadByte
-
#define I2C_Client_ReadAddrTWI0_ReadAddr
-
#define I2C_Client_ErrorGetTWI0_ErrorGet
-
#define I2C_Client_TransferDirGetTWI0_TransferDirGet
-
#define I2C_Client_LastByteAckStatusGetTWI0_LastByteAckStatusGet
-
#define I2C_Client_CallbackRegisterTWI0_CallbackRegister
Variables
-
const struct I2C_CLIENT_INTERFACE I2C_Client
Detailed Description
TWI0 Generated Driver API Header File
Macro Definition Documentation
i2c_client_client_interface
#define i2c_client_client_interface I2C_Client
Section: Data Type Definitions
Variable Documentation
I2C_Client
const struct I2C_CLIENT_INTERFACE I2C_Client
Section: Driver Interface
3.9.1.7.5 source/twi_client_polling.c File Reference
This file contains the driver code for TWI0 module.
#include "../twi0.h" #include <stdbool.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI0_EventHandler ()
-
static void TWI0_ErrorEventHandler ()
-
static bool TWI0_DefaultCallback (i2c_client_transfer_event_t event)
-
void TWI0_Initialize (void)
This routine initializes the TWI0 module.
-
void TWI0_Deinitialize (void)
This routine Deinitializes the TWI0 module. This function disables the module.
-
void TWI0_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI0_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI0_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI0_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI0_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI0_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI0_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 TWI0_Tasks (void)
This function is common Polling function for all TWI0 client.
Variables
-
const struct I2C_CLIENT_INTERFACE I2C_Client
-
static volatile uint16_t twi0Addr
-
static volatile i2c_client_error_ttwi0ErrorState
-
static bool(* TWI0_InterruptHandler )(i2c_client_transfer_event_t clientEvent) = NULL
Detailed Description
This file contains the driver code for TWI0 module.
TWI0 Generated Driver File
Function Documentation
TWI0_EventHandler()
static void TWI0_EventHandler (void )[static]
Section: Private functions declaration
Variable Documentation
I2C_Client
const struct I2C_CLIENT_INTERFACE I2C_Client
Initial value:
= { .Initialize = TWI0_Initialize, .Deinitialize = TWI0_Deinitialize, .WriteByte = TWI0_WriteByte, .ReadByte = TWI0_ReadByte, .TransferDirGet = TWI0_TransferDirGet, .LastByteAckStatusGet = TWI0_LastByteAckStatusGet, .ErrorGet = TWI0_ErrorGet, .CallbackRegister = TWI0_CallbackRegister, .Tasks = TWI0_Tasks }
Section: Driver Interface
twi0Addr
volatile uint16_t twi0Addr[static]
Section: Private Variable Definitions
3.9.1.7.6 source/twi_client_polling.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h" #include "i2c_client_interface.h"
Functions
-
void TWI0_Initialize (void)
This routine initializes the TWI0 module.
-
void TWI0_Deinitialize (void)
This routine Deinitializes the TWI0 module. This function disables the module.
-
void TWI0_WriteByte (uint8_t wrByte)
This function writes data to a host on the bus.
-
uint8_t TWI0_ReadByte (void)
This function read data from a host on the bus.
-
uint16_t TWI0_ReadAddr (void)
This function read requested address from a host on the bus.
-
i2c_client_error_t TWI0_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
i2c_client_transfer_dir_t TWI0_TransferDirGet (void)
This function get the I2C Transfer direction.
-
i2c_client_ack_status_t TWI0_LastByteAckStatusGet (void)
This function get the I2C Host ACK status.
-
void TWI0_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 TWI0_Tasks (void)
This function is common Polling function for all TWI0 client.
Macros
-
#define I2C_Client_InitializeTWI0_Initialize
-
#define I2C_Client_DeinitializeTWI0_Deinitialize
-
#define I2C_Client_WriteByteTWI0_WriteByte
-
#define I2C_Client_ReadByteTWI0_ReadByte
-
#define I2C_Client_ReadAddrTWI0_ReadAddr
-
#define I2C_Client_ErrorGetTWI0_ErrorGet
-
#define I2C_Client_TransferDirGetTWI0_TransferDirGet
-
#define I2C_Client_LastByteAckStatusGetTWI0_LastByteAckStatusGet
-
#define I2C_Client_CallbackRegisterTWI0_CallbackRegister
-
#define I2C_Client_TasksTWI0_Tasks
Variables
-
const struct I2C_CLIENT_INTERFACE I2C_Client
Detailed Description
TWI0 Generated Driver API Header File
Macro Definition Documentation
i2c_client_client_interface
#define i2c_client_client_interface I2C_Client
Section: Data Type Definitions
Variable Documentation
I2C_Client
const struct I2C_CLIENT_INTERFACE I2C_Client
Section: Driver Interface
3.9.1.7.7 source/twi_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 TWI0_Initialize (void)
This API initializes the I2C_Host driver.
-
void TWI0_Deinitialize (void)
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
-
bool TWI0_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI0_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI0_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 TWI0_ErrorGet (void)
This function get the error occurred during I2C Transmit and Receive.
-
bool TWI0_IsBusy (void)
This API checks if I2C is busy.
-
void TWI0_CallbackRegister (void(*handler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
void TWI0_ErrorCallbackRegister (void(*handler)(void))
Setter function for I2C Error interrupt callback.
Macros
-
#define i2c_host_host_interfaceI2C_Host
-
#define I2C_Host_InitializeTWI0_Initialize
-
#define I2C_Host_DeinitializeTWI0_Deinitialize
-
#define I2C_Host_WriteTWI0_Write
-
#define I2C_Host_ReadTWI0_Read
-
#define I2C_Host_WriteReadTWI0_WriteRead
-
#define I2C_Host_ErrorGetTWI0_ErrorGet
-
#define I2C_Host_IsBusyTWI0_IsBusy
-
#define I2C_Host_CallbackRegisterTWI0_CallbackRegister
-
#define TWI0_BAUD(F_SCL, T_RISE) ((((((float) 3333333 / (float)F_SCL)) - 10 - ((float)3333333 * T_RISE / 1000000))) / 2)
Variables
-
const i2c_host_interface_t I2C_Host
Detailed Description
TWI0 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.1.7.8 source/twi_host_polling.c File Reference
This file contains the driver code for TWI0 module.
#include "../twi0.h" #include <stdbool.h> #include <stdlib.h> #include "../../system/utils/compiler.h"
Functions
-
static void TWI0_Close (void)
-
static void TWI0_ReadStart (void)
-
static void TWI0_WriteStart (void)
-
static void TWI0_EventHandler (void)
-
static void TWI0_ErrorEventHandler (void)
-
static void TWI0_DefaultCallback (void)
-
static uint8_t TWI0_GetRxData (void)
-
static void TWI0_SendTxData (uint8_t data)
-
static void TWI0_SendTxAddr (uint8_t data)
-
static void TWI0_ClearInterruptFlag (void)
-
static void TWI0_ResetBus (void)
-
static void TWI0_EnableRestart (void)
-
static void TWI0_DisableRestart (void)
-
static void TWI0_SendStop (void)
-
static bool TWI0_IsNack (void)
-
static bool TWI0_IsBusError (void)
-
static bool TWI0_IsData (void)
-
static bool TWI0_IsAddr (void)
-
static void TWI0_ClearErrorFlags (void)
-
static void TWI0_EnableInterrupts (void)
-
static void TWI0_DisableInterrupts (void)
-
static void TWI0_ClearInterrupts (void)
-
static void TWI0_HostSendAck (void)
-
static void TWI0_HostSendNack (void)
-
static bool TWI0_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 TWI0_Initialize (void)
This routine initializes the TWI0 module.
-
void TWI0_Deinitialize (void)
This routine Deinitializes the TWI0 module. This function disables the module.
-
bool TWI0_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI0_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI0_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 TWI0_ErrorGet (void)
This function the error occurred during I2C Transmit and Receive.
-
bool TWI0_IsBusy (void)
This API checks if I2C is busy.
-
void TWI0_CallbackRegister (void(*callbackHandler)(void))
Setter function for I2C interrupt callback, This will be called when any error is generated.
-
void TWI0_Tasks (void)
This function is common Polling function for all TWI0 client.
Typedefs
-
typedef i2c_event_states_t(* twi0eventHandler) (void)
Variables
-
const i2c_host_interface_t I2C_Host
-
static void(* TWI0_Callback )(void) = NULL
-
volatile i2c_event_status_ttwi0_Status = {0}
-
const twi0eventHandler twi0_eventTable []
Detailed Description
This file contains the driver code for TWI0 module.
TWI0 Generated Driver File
Function Documentation
TWI0_GetRxData()
static uint8_t TWI0_GetRxData (void )[static]
Section: Register Level Interfaces
TWI0_ReadStart()
static void TWI0_ReadStart (void )[static]
Section: Private Interfaces
Variable Documentation
I2C_Host
const i2c_host_interface_t I2C_Host
Initial value:
= { .Initialize = TWI0_Initialize, .Deinitialize = TWI0_Deinitialize, .Write = TWI0_Write, .Read = TWI0_Read, .WriteRead = TWI0_WriteRead, .TransferSetup = NULL, .ErrorGet = TWI0_ErrorGet, .IsBusy = TWI0_IsBusy, .CallbackRegister = TWI0_CallbackRegister, .Tasks = TWI0_Tasks }
Section: Driver Interface
TWI0_Callback
void(* TWI0_Callback) (void) = NULL[static]
Section: Private Variable Definitions
twi0_eventTable
const twi0eventHandler twi0_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.1.7.9 source/twi_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 TWI0_Initialize (void)
This API initializes the I2C_Host driver.
-
void TWI0_Deinitialize (void)
This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.
-
bool TWI0_Write (uint16_t address, uint8_t *data, size_t dataLength)
This API writes data to a Client on the bus.
-
bool TWI0_Read (uint16_t address, uint8_t *data, size_t dataLength)
This API reads the data from a client on the bus.
-
bool TWI0_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 TWI0_ErrorGet (void)
This function get the error occurred during I2C Transmit and Receive.
-
bool TWI0_IsBusy (void)
This API checks if I2C is busy.
-
void TWI0_Tasks (void)
This is polling function for non interrupt mode.
-
void TWI0_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_InitializeTWI0_Initialize
-
#define I2C_Host_DeinitializeTWI0_Deinitialize
-
#define I2C_Host_WriteTWI0_Write
-
#define I2C_Host_ReadTWI0_Read
-
#define I2C_Host_WriteReadTWI0_WriteRead
-
#define I2C_Host_ErrorGetTWI0_ErrorGet
-
#define I2C_Host_IsBusyTWI0_IsBusy
-
#define I2C_Host_CallbackRegisterTWI0_CallbackRegister
-
#define I2C_Host_TasksTWI0_Tasks
-
#define TWI0_BAUD(F_SCL, T_RISE) ((((((float)3333333 / (float)F_SCL)) - 10 - ((float)3333333 * T_RISE / 1000000))) / 2)
Variables
-
const i2c_host_interface_t I2C_Host
Detailed Description
TWI0 Generated Driver API Header File
Variable Documentation
I2C_Host
const i2c_host_interface_t I2C_Host
Section: Data Type Definitions
Section: Driver Interface