4.9.2 I2C with Dual Mode Operation

I2C (also known as Two-Wire Interface (TWI)) with Dual Mode supporting simultaneous host and client operations

4.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.

4.9.2.2 Supported Device Families

AVR® Dx AVR® Ex ATmega

4.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"

4.9.2.5 Module Documentation

4.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.

Version: TWI1 Driver Version 2.0.1
Enumerations

Enumeration Type Documentation

i2c_client_ack_status_t

enum 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

4.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.

Version: TWI0 Driver Version 2.0.1
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.

4.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.

Version: TWI0 Driver Version 2.0.1
Data structures
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.

4.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.

Version: TWI1 Driver Version 1.1.0
Functions

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.

Parameters:
handler

- A pointer to a function.

Returns:

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.

Parameters:
void
Returns:

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.

Parameters:
void
Returns:

void

Parameters:
none
Returns:

none

TWI1_ErrorGet()

i2c_client_error_t TWI1_ErrorGet (void )

This function the error occurred during I2C Transmit and Receive.

Parameters:
void
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

This function get the error occurred during I2C Transmit and Receive.

Parameters:
void
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

Parameters:
none
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

TWI1_Initialize()

void TWI1_Initialize (void )

This routine initializes the TWI1 module.

This API initializes the TWI1 module.

Parameters:
void
Returns:

void

This routine initializes the TWI1 module.

This API initializes the I2C_Host driver.

Section: Public functions

Parameters:
void
Returns:

void

Parameters:
none
Returns:

none

Section: Public functions

TWI1_LastByteAckStatusGet()

i2c_client_ack_status_t TWI1_LastByteAckStatusGet (void )

This function get the I2C Host ACK status.

Parameters:
void
Return values:
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

TWI1_ReadAddr()

uint16_t TWI1_ReadAddr (void )

This function read requested address from a host on the bus.

Parameters:
void
Returns:

address byte -TWI1 client read byte

TWI1_ReadByte()

uint8_t TWI1_ReadByte (void )

This function read data from a host on the bus.

Parameters:
void
Returns:

data byte -TWI1 client read byte

TWI1_Tasks()

void TWI1_Tasks (void )

This function is common Polling function for all TWI1 client.

Parameters:
void.
Returns:

void

TWI1_TransferDirGet()

i2c_client_transfer_dir_t TWI1_TransferDirGet (void )

This function get the I2C Transfer direction.

Parameters:
void
Return values:
I2C_CLIENT_TRANSFER_DIR_WRITE

- I2C Host is writing to client

I2C_CLIENT_TRANSFER_DIR_READ

- I2C Host is reading from client

TWI1_WriteByte()

void TWI1_WriteByte (uint8_t wrByte)

This function writes data to a host on the bus.

Parameters:
in wrByte

- TWI1 client write byte

Returns:

void

4.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.

Version: TWI1 Driver Version 2.1.0
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.

Parameters:
void

*handler - Pointer to custom Callback.

Returns:

none

Parameters:
void

*CallbackHandler - Pointer to custom Callback.

Returns:

none

TWI1_Deinitialize()

void TWI1_Deinitialize (void )

This API Deinitializes the I2C_Host driver. This routine disables the I2C_Host module.

Parameters:
none
Returns:

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.

Parameters:
void
Returns:

void

Parameters:
none
Returns:

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.

Parameters:
void
Returns:

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.

Parameters:
void
Returns:

void

Parameters:
none
Returns:

none

TWI1_ErrorCallbackRegister()

void TWI1_ErrorCallbackRegister (void(*)(void) handler)

Setter function for I2C Error interrupt callback.

Parameters:
void

*handler - Pointer to custom Callback.

Returns:

none

TWI1_ErrorGet()

i2c_host_error_t TWI1_ErrorGet (void )

This function get the error occurred during I2C Transmit and Receive.

Parameters:
none
Returns:

i2c_host_error_t - I2C error code staus.

Parameters:
none
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

This function get the error occurred during I2C Transmit and Receive.

Parameters:
void
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

Parameters:
none
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

This function get the error occurred during I2C Transmit and Receive.

Parameters:
void
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

This function get the error occurred during I2C Transmit and Receive.

Parameters:
void
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

Parameters:
none
Return values:
I2C_CLIENT_ERROR_BUS_COLLISION

- I2C Bus Collision Error

I2C_CLIENT_ERROR_WRITE_COLLISION

- I2C Write Collision Error

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

- I2C Receive overflow

I2C_CLIENT_ERROR_NONE

- No Error

TWI1_Initialize()

void TWI1_Initialize (void )

This API initializes the I2C_Host driver.

Parameters:
none
Returns:

none

This routine initializes the TWI1 module.

This API initializes the I2C_Host driver.

Section: Public functions

Parameters:
void
Returns:

void

Parameters:
none
Returns:

none

This API initializes the I2C_Host driver.

Section: Public functions

This API initializes the I2C_Host driver.

This API initializes the TWI1 module.

Parameters:
void
Returns:

void

This routine initializes the TWI1 module.

This API initializes the I2C_Host driver.

Section: Public functions

Parameters:
void
Returns:

void

Parameters:
none
Returns:

none

Section: Public functions

TWI1_IsBusy()

bool TWI1_IsBusy (void )

This API checks if I2C is busy.

Parameters:
none
Return values:
true

- I2C is busy

false

- I2C is free

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.

Parameters:
in uint16_t

address - 7-bit / 10-bit Client address.

out uint8_t

*data - pointer to destination data buffer that contains the data to be received

in size_t

dataLength - length of data buffer in number of bytes. Also the number of bytes to be read.

Return values:
true

- The request was placed successfully and the bus activity was initiated

False

- The request fails,if there was already a transfer in progress when this function was called

TWI1_Tasks()

void TWI1_Tasks (void )

This is polling function for non interrupt mode.

Parameters:
none
Returns:

none

This is polling function for non interrupt mode.

Parameters:
void.
Returns:

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.

Parameters:
in uint16_t

address - 7-bit / 10-bit Client address.

in uint8_t

*data - pointer to source data buffer that contains the data to be transmitted.

in size_t

dataLength - length of data buffer in number of bytes. Also the number of bytes to be written.

Return values:
true

- The request was placed successfully and the bus activity was initiated

False

- The request fails,if there was already a transfer in progress when this function was called

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.

Parameters:
in uint16_t

address - 7-bit / 10-bit Client address.

out uint8_t

*writeData - pointer to write data buffer.

in size_t

writeLength - write data length in bytes.

in uint8_t

*readData - pointer to read data buffer.

in size_t

readLength - read data length in bytes.

Return values:
true

- The request was placed successfully and the bus activity was initiated

False

- The request fails,if there was already a transfer in progress when this function was called

4.9.2.6 Class Documentation

4.9.2.6.1 i2c_event_status_t Struct Reference

The documentation for this struct was generated from the following file:

source/

i2c_host_event_types.h

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

4.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/

i2c_host_types.h

Public Attributes
  • uint32_t clkSpeed

4.9.2.7 File Documentation

4.9.2.7.1 source/i2c_client_types.h File Reference

Enumerations

Detailed Description

TWI1 Generated Driver API Header File

4.9.2.7.2 source/i2c_host_event_types.h File Reference

#include "i2c_host_types.h"

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

4.9.2.7.3 source/i2c_host_types.h File Reference

Data structures

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

4.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

Detailed Description

This file contains the driver code for TWI1 module.

TWI1 Generated Driver File

Version: TWI1 Driver Version 1.1.0

Function Documentation

TWI1_EventHandler()

static void TWI1_EventHandler (void )[static]

Section: Private functions declaration

Variable Documentation

twi1Addr

volatile uint16_t twi1Addr[static]

Section: Private Variable Definitions

4.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

Variables

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

4.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

Detailed Description

This file contains the driver code for TWI1 module.

TWI1 Generated Driver File

Version: TWI1 Driver Version 1.1.0

Function Documentation

TWI1_EventHandler()

static void TWI1_EventHandler (void )[static]

Section: Private functions declaration

Variable Documentation

twi1Addr

volatile uint16_t twi1Addr[static]

Section: Private Variable Definitions

4.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

Macros

Variables

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

4.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)

Detailed Description

This file contains the driver code for TWI1 module.

TWI1 Generated Driver File

Version: TWI1 Driver Version 2.1.0

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

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
}

4.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.

Variables

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

4.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.

Detailed Description

This file contains the driver code for TWI1 module.

TWI1 Generated Driver File

Version: TWI1 Driver Version 2.1.0

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

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
}

4.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

Variables

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