3.15.1 I2C

Inter-Integrated Circuit

3.15.1.1 Introduction

The Inter-Integrated Circuit (I2C) bus is a multi-host serial data communication bus. Devices communicate in a host/client environment where the host devices initiate the communication. A client device is controlled through addressing.

3.15.1.2 Supported Device Families

PIC18F-K42PIC18F-K83PIC18F-Q43

3.15.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.15.1.5 Module Documentation

Enter a short description of your concept here (optional).

This is the start of your concept.

3.15.1.5.1 I2C_CLIENT_PLIB

Module description

Modules
  • I2C_CLIENT

    This file contains API prototypes and other data types for I2C1 module.

  • I2C_CLIENT_TYPES

    This file contains other data types for I2C module.

I2C_CLIENT

This file contains API prototypes and other data types for I2C1 module.

Module description

This file contains API prototypes and other data types for I2C1 module.

Version: I2C1 Driver Version 2.1.0
Functions
Function Documentation
I2C1_CallbackRegister()

void I2C1_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

I2C1_Deinitialize()

void I2C1_Deinitialize (void )

This routine Deinitializes the I2C1 module. This function disables the module.

Parameters:
void
Returns:

void

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

Parameters:
void
Returns:

void

I2C1_ErrorGet()

i2c_client_error_t I2C1_ErrorGet (void )

This function the error occurred during I2C Transmit and Receive. I2C1_Initialize() must have been called for the associated.

Parameters:
void
Returns:

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
Returns:

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:
void
Returns:

I2C_ERROR_NONE - No Error I2C_ERROR_NACK - Client returned NACK I2C_ERROR_BUS_COLLISION - Bus Collision Error

I2C1_Initialize()

void I2C1_Initialize (void )

This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

Parameters:
void
Returns:

void

This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

Section: Public functions

Parameters:
void
Returns:

void

Section: Public functions

Section: Public Interfaces

I2C1_LastByteAckStatusGet()

i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void )

This function get the I2C Host ACK status. I2C1_Initialize() must have been called for the associated.

Parameters:
void
Returns:

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

I2C1_ReadAddr()

uint16_t I2C1_ReadAddr (void )

This function read requested address from a host on the bus. I2C1_Initialize() must have been called for the associated.

Parameters:
void
Returns:

address byte -I2C1 client read byte

I2C1_ReadByte()

uint8_t I2C1_ReadByte (void )

This function read data from a host on the bus. I2C1_Initialize() must have been called for the associated.

Parameters:
void
Returns:

data byte -I2C1 client read byte

I2C1_Tasks()

void I2C1_Tasks (void )

his function is common Polling function for all I2C1 client. I2C1_Initialize() must have been called for the associated.

Parameters:
void.
Returns:

void.

I2C1_TransferDirGet()

i2c_client_transfer_dir_t I2C1_TransferDirGet (void )

This function get the I2C Transfer direction. I2C1_Initialize() must have been called for the associated.

Parameters:
void
Returns:

I2C_CLIENT_TRANSFER_DIR_WRITE - I2C Host is writing to client I2C_CLIENT_TRANSFER_DIR_READ - I2C Host is reading from client

I2C1_WriteByte()

void I2C1_WriteByte (uint8_t wrByte)

This function writes data to a host on the bus. I2C1_Initialize() must have been called for the associated.

Parameters:
in wrByte

- I2C1 client write byte

Returns:

void

Variable Documentation
I2C_Client[1/2]

const struct I2C_CLIENT_INTERFACE I2C_Client

External object for I2C_Client.

Section: Driver Interface

I2C_Client[1/2]

const struct I2C_CLIENT_INTERFACE I2C_Client

External object for I2C_Client.

Section: Driver Interface

I2C_CLIENT_TYPES

This file contains other data types for I2C module.

Module description

This file contains other data types for I2C module.

Version: I2C Driver Version 2.1.0
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_COLLISION

I2C Bus collision occurred

I2C_CLIENT_ERROR_WRITE_COLLISION

I2C Write collision occurred

I2C_CLIENT_ERROR_RECEIVE_OVERFLOW

I2C Receive overflow occurred

I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW

I2C Trasmit underflow occurred

I2C_CLIENT_ERROR_READ_UNDERFLOW

I2C Receive underflow 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.15.1.5.2 I2C_HOST_PLIB

Module description

Modules
  • I2C_HOST

    This file contains API prototypes and other data types for I2C1 module.

  • I2C_HOST_TYPES

    This file contains other data types for I2C module.

I2C_HOST_TYPES

This file contains other data types for I2C module.

Enumeration Type Documentation
i2c_host_error_t

enum i2c_host_error_t

Enumeration for I2C errors.

I2C_ERROR_NONE

No Error

I2C_ERROR_ADDR_NACK

Client returned Address NACK

I2C_ERROR_DATA_NACK

Client returned Data NACK

I2C_ERROR_BUS_COLLISION

Bus Collision Error

I2C_HOST

This file contains API prototypes and other data types for I2C1 module.

Module description

This file contains API prototypes and other data types for I2C1 module.

Version: I2C1 Driver Version 2.1.0
Functions
  • void I2C1_Initialize (void)

    This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

  • void I2C1_Deinitialize (void)

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

  • bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)

    This function writes data to a Client on the bus. The function will attempt to write length number of bytes from data buffer to a Client whose address is specified by address. The I2C Host will generate a Start condition,write the data and then generate a Stop Condition. If the Client NACK the request or a bus error was encountered on the bus, the transfer is terminated. The application can call the I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)

    This function reads the data from a Client on the bus. The function will attempt to read length number of bytes into data buffer from a Client whose address is specified as address. The I2C Host generate a Start condition, read the data and then generate a Stop Condition. If the Client NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)

    This function writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData. The function generates a Start condition on the bus and will then send writeLength number of bytes contained in writeData. The function will then insert a Repeated start condition and proceed to read readLength number of bytes from the client. The received bytes are stored in readData buffer. A Stop condition is generated after the last byte has been received.

  • i2c_host_error_t I2C1_ErrorGet (void)

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

  • bool I2C1_IsBusy (void)

    This API checks if I2C is busy. I2C must be initialized with I2C1_Initialize() before calling this API.

  • void I2C1_CallbackRegister (void(*callbackHandler)(void))

    Setter function for I2C interrupt callback, This will be called when any error is generated.

  • void I2C1_Tasks (void)

    This is polling function for non interrupt mode.

Function Documentation
I2C1_CallbackRegister()

void I2C1_CallbackRegister (void(*)(void) callbackHandler)

Setter function for I2C interrupt callback, This will be called when any error is generated.

Parameters:
CallbackHandler

- Pointer to custom Callback.

Returns:

void

void customI2CCallback(void)
{
   // Custom ISR code
}

void main(void)
{
    SYSTEM_Initialize();
    I2C1_Initialize();
    I2C1_CallbackRegister(customI2CCallback);
    while (!I2C1_WriteRead(0x50, writeData, 1, readData , 2));

    while (1)
    {
    }
}
I2C1_Deinitialize()

void I2C1_Deinitialize (void )

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

Parameters:
void
Returns:

void

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

Parameters:
void
Returns:

void

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

Parameters:
void
Returns:

void

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

Parameters:
void
Returns:

void

I2C1_ErrorGet()

i2c_host_error_t I2C1_ErrorGet (void )

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

Parameters:
void
Returns:

I2C_ERROR_NONE - No Error I2C_ERROR_NACK - Client returned NACK I2C_ERROR_BUS_COLLISION - Bus Collision Error

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

Parameters:
void
Returns:

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:
void
Returns:

I2C_ERROR_NONE - No Error I2C_ERROR_NACK - Client returned NACK I2C_ERROR_BUS_COLLISION - Bus Collision Error

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

Parameters:
void
Returns:

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
Returns:

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:
void
Returns:

I2C_ERROR_NONE - No Error I2C_ERROR_NACK - Client returned NACK I2C_ERROR_BUS_COLLISION - Bus Collision Error

I2C1_Initialize()

void I2C1_Initialize (void )

This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

Parameters:
void
Returns:

void

This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

Section: Public functions

Parameters:
void
Returns:

void

This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

Section: Public functions

This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

Section: Public Interfaces

I2C1_IsBusy()

bool I2C1_IsBusy (void )

This API checks if I2C is busy. I2C must be initialized with I2C1_Initialize() before calling this API.

Parameters:
void
Returns:

true - if I2C is busy; false - if I2C is free

I2C1_Read()

bool I2C1_Read (uint16_t address, uint8_t * data, size_t dataLength)

This function reads the data from a Client on the bus. The function will attempt to read length number of bytes into data buffer from a Client whose address is specified as address. The I2C Host generate a Start condition, read the data and then generate a Stop Condition. If the Client NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

The function is non-blocking. It initiates bus activity and returns immediately. The transfer is then completed in the peripheral interrupt. For polling mode, user has to call I2C1_Tasks in while loop. A transfer request cannot be placed when another transfer is in progress. Calling this function when another function is already in progress will cause the function to return false.

Parameters:
in address

- 7-bit / 10-bit Client address.

out data

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

in dataLength

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

Returns:

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

I2C1_Tasks()

void I2C1_Tasks (void )

This is polling function for non interrupt mode.

Parameters:
void
Returns:

void

This is polling function for non interrupt mode.

Parameters:
void.
Returns:

void.

I2C1_Write()

bool I2C1_Write (uint16_t address, uint8_t * data, size_t dataLength)

This function writes data to a Client on the bus. The function will attempt to write length number of bytes from data buffer to a Client whose address is specified by address. The I2C Host will generate a Start condition,write the data and then generate a Stop Condition. If the Client NACK the request or a bus error was encountered on the bus, the transfer is terminated. The application can call the I2C1_ErrorGet() function to know that cause of the error.

The function is non-blocking. It initiates bus activity and returns immediately. The transfer is then completed in the peripheral interrupt. For polling mode, user has to call I2C1_Tasks in while loop. A transfer request cannot be placed when another transfer is in progress. Calling this function when another function is already in progress will cause the function to return false.

Parameters:
in address

- 7-bit / 10-bit Client address.

in data

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

in dataLength

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

Returns:

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

I2C1_WriteRead()

bool I2C1_WriteRead (uint16_t address, uint8_t * writeData, size_t writeLength, uint8_t * readData, size_t readLength)

This function writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData. The function generates a Start condition on the bus and will then send writeLength number of bytes contained in writeData. The function will then insert a Repeated start condition and proceed to read readLength number of bytes from the client. The received bytes are stored in readData buffer. A Stop condition is generated after the last byte has been received.

If the Client NAKs the request or a bus error was encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

The function is non-blocking. It initiates bus activity and returns immediately. The transfer is then completed in the peripheral interrupt. For polling mode, user has to call I2C1_Tasks in while loop. A transfer request cannot be placed when another transfer is in progress. Calling this function when another function is already in progress will cause the function to return false.

Parameters:
in address

- 7-bit / 10-bit Client address.

in writeData

- pointer to write data buffer.

in writeLength

- write data length in bytes.

out readData

- pointer to read data buffer.

in readLength

- read data length in bytes.

Returns:

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

Variable Documentation
I2C_Host[1/2]

const i2c_host_interface_t I2C_Host

External object for I2C_Host.

Section: Data Type Definitions

Section: Driver Interface

I2C_Host[1/2]

const i2c_host_interface_t I2C_Host

External object for I2C_Host.

Section: Data Type Definitions

Section: Driver Interface

3.15.1.6 File Documentation

Enter a short description of your concept here (optional).

This is the start of your concept.

3.15.1.6.1 source/i2c_client_interrupt.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../../system/config_bits.h"
#include "../i2c1.h"

Functions

Detailed Description

This file contains the driver code for I2C1 module.

I2C1 Generated Driver File

Version: I2C1 Driver Version 2.1.0

Function Documentation

I2C1_ERROR_ISR()

void I2C1_ERROR_ISR (void )

This function is common ISR function for all I2C1 Error interrupts. I2C1_Initialize() must have been called for the associated.

This function is ISR function for I2C1 Error interrupts.

Parameters:
void.
Returns:

void

I2C1_EventHandler()

static void I2C1_EventHandler (void )[static]

Section: Private functions declaration

Section: Private functions

I2C1_ISR()

void I2C1_ISR (void )

This function is common ISR function for all I2C1 interrupts. I2C1_Initialize() must have been called for the associated.

This function is ISR function for I2C1 Common interrupts.

Parameters:
void.
Returns:

void

Variable Documentation

i2c1Addr

volatile uint16_t i2c1Addr[static]

Section: Private Variable Definitions

3.15.1.6.2 source/i2c_client_interrupt.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include "i2c_client_interface.h"

Functions

Macros

Detailed Description

I2C1 Generated Driver API Header File

Function Documentation

I2C1_ERROR_ISR()

void I2C1_ERROR_ISR (void )

This function is common ISR function for all I2C1 Error interrupts. I2C1_Initialize() must have been called for the associated.

Parameters:
void.
Returns:

void

I2C1_ISR()

void I2C1_ISR (void )

This function is common ISR function for all I2C1 interrupts. I2C1_Initialize() must have been called for the associated.

Parameters:
void.
Returns:

void

Macro Definition Documentation

i2c_client_client_interface

#define i2c_client_client_interface I2C_Client

Section: Data Type Definitions

3.15.1.6.3 source/i2c_client_polling.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../../system/config_bits.h"
#include "../i2c1.h"

Functions

Detailed Description

This file contains the driver code for I2C1 module.

I2C1 Generated Driver File

Version: I2C1 Driver Version 2.1.0

Function Documentation

I2C1_EventHandler()

static void I2C1_EventHandler (void )[static]

Section: Private functions declaration

Section: Private functions

Variable Documentation

i2c1Addr

volatile uint16_t i2c1Addr[static]

Section: Private Variable Definitions

3.15.1.6.4 source/i2c_client_polling.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include "i2c_client_interface.h"

Functions

Macros

Detailed Description

I2C1 Generated Driver API Header File

Macro Definition Documentation

i2c_client_client_interface

#define i2c_client_client_interface I2C_Client

Section: Data Type Definitions

3.15.1.6.5 source/i2c_client_types.h File Reference

Enumerations

Detailed Description

I2C Generated Driver Types Header File

3.15.1.6.6 source/i2c_host_interrupt.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../../system/config_bits.h"
#include "../i2c1.h"

Functions

  • static void I2C1_ReadStart (void)

  • static void I2C1_WriteStart (void)

  • static void I2C1_Close (void)

  • static void I2C1_DefaultCallback (void)

  • static void I2C1_StartSend (void)

  • static void I2C1_AddrTransmit (uint8_t addr)

  • static void I2C1_DataTransmit (uint8_t data)

  • static uint8_t I2C1_DataReceive (void)

  • static void I2C1_CounterSet (uint8_t counter)

  • static uint8_t I2C1_CounterGet (void)

  • static void I2C1_BusReset (void)

  • static void I2C1_RestartEnable (void)

  • static void I2C1_RestartDisable (void)

  • static void I2C1_StopSend (void)

  • static bool I2C1_IsNack (void)

  • static bool I2C1_IsBusCol (void)

  • static bool I2C1_IsBusTimeOut (void)

  • static bool I2C1_IsData (void)

  • static bool I2C1_IsAddr (void)

  • static void I2C1_InterruptsEnable (void)

  • static void I2C1_InterruptsDisable (void)

  • static void I2C1_InterruptsClear (void)

  • static void I2C1_ErrorFlagsClear (void)

  • static void I2C1_BufferClear (void)

  • void I2C1_Initialize (void)

    This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

  • void I2C1_Deinitialize (void)

    This routine Deinitializes the I2C1 module. This function disables the module.

  • bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)

    This function writes data to a Client on the bus. The function will attempt to write length number of bytes from data buffer to a Client whose address is specified by address. The I2C Host will generate a Start condition,write the data and then generate a Stop Condition. If the Client NACK the request or a bus error was encountered on the bus, the transfer is terminated. The application can call the I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)

    This function reads the data from a Client on the bus. The function will attempt to read length number of bytes into data buffer from a Client whose address is specified as address. The I2C Host generate a Start condition, read the data and then generate a Stop Condition. If the Client NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)

    This function writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData. The function generates a Start condition on the bus and will then send writeLength number of bytes contained in writeData. The function will then insert a Repeated start condition and proceed to read readLength number of bytes from the client. The received bytes are stored in readData buffer. A Stop condition is generated after the last byte has been received.

  • i2c_host_error_t I2C1_ErrorGet (void)

    This function the error occurred during I2C Transmit and Receive. I2C1_Initialize() must have been called for the associated.

  • bool I2C1_IsBusy (void)

    This API checks if I2C is busy. I2C must be initialized with I2C1_Initialize() before calling this API.

  • void I2C1_CallbackRegister (void(*callbackHandler)(void))

    Setter function for I2C interrupt callback, This will be called when any error is generated.

  • void I2C1_ISR ()

    This function is common ISR function for all I2C1 interrupts. I2C1_Initialize() must have been called for the associated.

  • void I2C1_ERROR_ISR ()

    This function is common ISR function for all I2C1 Error interrupts. I2C1_Initialize() must have been called for the associated.

  • void I2C1_RX_ISR ()

    This function is ISR function for I2C1 Receive interrupts.

  • void I2C1_TX_ISR ()

    This function is ISR function for I2C1 Transmit interrupts.

Detailed Description

This file contains the driver code for I2C1 module.

I2C1 Generated Driver File

Version: I2C1 Driver Version 2.1.0

Function Documentation

I2C1_ERROR_ISR()

void I2C1_ERROR_ISR (void )

This function is common ISR function for all I2C1 Error interrupts. I2C1_Initialize() must have been called for the associated.

This function is ISR function for I2C1 Error interrupts.

Parameters:
void.
Returns:

void

I2C1_ISR()

void I2C1_ISR (void )

This function is common ISR function for all I2C1 interrupts. I2C1_Initialize() must have been called for the associated.

This function is ISR function for I2C1 Common interrupts.

Parameters:
void.
Returns:

void

I2C1_ReadStart()

static void I2C1_ReadStart (void )[static]

Section: Private Interfaces

I2C1_RX_ISR()

void I2C1_RX_ISR (void )

This function is ISR function for I2C1 Receive interrupts.

Parameters:
void
Returns:

void

I2C1_StartSend()

static void I2C1_StartSend (void )[static]

Section: Register Level Interfaces

I2C1_TX_ISR()

void I2C1_TX_ISR (void )

This function is ISR function for I2C1 Transmit interrupts.

Parameters:
void
Returns:

void

Variable Documentation

I2C1_Callback

void(* I2C1_Callback) (void) = NULL[static]

Section: Private Variable Definitions

3.15.1.6.7 source/i2c_host_interrupt.h File Reference

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "i2c_host_event_types.h"
#include "i2c_host_interface.h"

Functions

  • void I2C1_Initialize (void)

    This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

  • void I2C1_Deinitialize (void)

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

  • bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)

    This function writes data to a Client on the bus. The function will attempt to write length number of bytes from data buffer to a Client whose address is specified by address. The I2C Host will generate a Start condition,write the data and then generate a Stop Condition. If the Client NACK the request or a bus error was encountered on the bus, the transfer is terminated. The application can call the I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)

    This function reads the data from a Client on the bus. The function will attempt to read length number of bytes into data buffer from a Client whose address is specified as address. The I2C Host generate a Start condition, read the data and then generate a Stop Condition. If the Client NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)

    This function writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData. The function generates a Start condition on the bus and will then send writeLength number of bytes contained in writeData. The function will then insert a Repeated start condition and proceed to read readLength number of bytes from the client. The received bytes are stored in readData buffer. A Stop condition is generated after the last byte has been received.

  • i2c_host_error_t I2C1_ErrorGet (void)

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

  • bool I2C1_IsBusy (void)

    This API checks if I2C is busy. I2C must be initialized with I2C1_Initialize() before calling this API.

  • void I2C1_CallbackRegister (void(*callbackHandler)(void))

    Setter function for I2C interrupt callback, This will be called when any error is generated.

  • void I2C1_ISR (void)

    This function is ISR function for I2C1 Common interrupts.

  • void I2C1_ERROR_ISR (void)

    This function is ISR function for I2C1 Error interrupts.

  • void I2C1_RX_ISR (void)

    This function is ISR function for I2C1 Receive interrupts.

  • void I2C1_TX_ISR (void)

    This function is ISR function for I2C1 Transmit interrupts.

Detailed Description

I2C1 Generated Driver API Header File

Function Documentation

I2C1_ERROR_ISR()

void I2C1_ERROR_ISR (void )

This function is ISR function for I2C1 Error interrupts.

Parameters:
void
Returns:

void

This function is ISR function for I2C1 Error interrupts.

Parameters:
void.
Returns:

void

I2C1_ISR()

void I2C1_ISR (void )

This function is ISR function for I2C1 Common interrupts.

Parameters:
void
Returns:

void

This function is ISR function for I2C1 Common interrupts.

Parameters:
void.
Returns:

void

I2C1_RX_ISR()

void I2C1_RX_ISR (void )

This function is ISR function for I2C1 Receive interrupts.

Parameters:
void
Returns:

void

I2C1_TX_ISR()

void I2C1_TX_ISR (void )

This function is ISR function for I2C1 Transmit interrupts.

Parameters:
void
Returns:

void

Macro Definition Documentation

i2c_host_host_interface

#define i2c_host_host_interface I2C_Host

Section: Included Files

3.15.1.6.8 source/i2c_host_polling.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../../system/config_bits.h"
#include "../i2c1.h"

Functions

  • static void I2C1_ReadStart (void)

  • static void I2C1_WriteStart (void)

  • static void I2C1_Close (void)

  • static void I2C1_DefaultCallback (void)

  • static void I2C1_StartSend (void)

  • static void I2C1_AddrTransmit (uint8_t addr)

  • static void I2C1_DataTransmit (uint8_t data)

  • static uint8_t I2C1_DataReceive (void)

  • static void I2C1_CounterSet (uint8_t counter)

  • static uint8_t I2C1_CounterGet (void)

  • static void I2C1_BusReset (void)

  • static void I2C1_RestartEnable (void)

  • static void I2C1_RestartDisable (void)

  • static void I2C1_StopSend (void)

  • static bool I2C1_IsNack (void)

  • static bool I2C1_IsBusCol (void)

  • static bool I2C1_IsBusTimeOut (void)

  • static bool I2C1_IsData (void)

  • static bool I2C1_IsAddr (void)

  • static void I2C1_InterruptsClear (void)

  • static void I2C1_ErrorFlagsClear (void)

  • static void I2C1_BufferClear (void)

  • void I2C1_Initialize (void)

    This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

  • void I2C1_Deinitialize (void)

    This routine Deinitializes the I2C1 module. This function disables the module.

  • bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)

    This function writes data to a Client on the bus. The function will attempt to write length number of bytes from data buffer to a Client whose address is specified by address. The I2C Host will generate a Start condition,write the data and then generate a Stop Condition. If the Client NACK the request or a bus error was encountered on the bus, the transfer is terminated. The application can call the I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)

    This function reads the data from a Client on the bus. The function will attempt to read length number of bytes into data buffer from a Client whose address is specified as address. The I2C Host generate a Start condition, read the data and then generate a Stop Condition. If the Client NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)

    This function writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData. The function generates a Start condition on the bus and will then send writeLength number of bytes contained in writeData. The function will then insert a Repeated start condition and proceed to read readLength number of bytes from the client. The received bytes are stored in readData buffer. A Stop condition is generated after the last byte has been received.

  • i2c_host_error_t I2C1_ErrorGet (void)

    This function the error occurred during I2C Transmit and Receive. I2C1_Initialize() must have been called for the associated.

  • bool I2C1_IsBusy (void)

    This API checks if I2C is busy. I2C must be initialized with I2C1_Initialize() before calling this API.

  • void I2C1_CallbackRegister (void(*callbackHandler)(void))

    Setter function for I2C interrupt callback, This will be called when any error is generated.

  • void I2C1_Tasks (void)

    his function is common Polling function for all I2C1 client. I2C1_Initialize() must have been called for the associated.

Detailed Description

This file contains the driver code for I2C1 module.

I2C1 Generated Driver File

Version: I2C1 Driver Version 2.1.0

Function Documentation

I2C1_ReadStart()

static void I2C1_ReadStart (void )[static]

Section: Private Interfaces

I2C1_StartSend()

static void I2C1_StartSend (void )[static]

Section: Register Level Interfaces

Variable Documentation

I2C1_Callback

void(* I2C1_Callback) (void) = NULL[static]

Section: Private Variable Definitions

3.15.1.6.9 source/i2c_host_polling.h File Reference

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "i2c_host_event_types.h"
#include "i2c_host_interface.h"

Functions

  • void I2C1_Initialize (void)

    This API initializes the I2C1 driver. This routine initializes the I2C1 module. This routine must be called before any other I2C1 routine is called. This routine should only be called once during system initialization.

  • void I2C1_Deinitialize (void)

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

  • bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)

    This function writes data to a Client on the bus. The function will attempt to write length number of bytes from data buffer to a Client whose address is specified by address. The I2C Host will generate a Start condition,write the data and then generate a Stop Condition. If the Client NACK the request or a bus error was encountered on the bus, the transfer is terminated. The application can call the I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)

    This function reads the data from a Client on the bus. The function will attempt to read length number of bytes into data buffer from a Client whose address is specified as address. The I2C Host generate a Start condition, read the data and then generate a Stop Condition. If the Client NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call I2C1_ErrorGet() function to know that cause of the error.

  • bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)

    This function writes data from the writeData to the bus and then reads data from the Client and stores the received in the readData. The function generates a Start condition on the bus and will then send writeLength number of bytes contained in writeData. The function will then insert a Repeated start condition and proceed to read readLength number of bytes from the client. The received bytes are stored in readData buffer. A Stop condition is generated after the last byte has been received.

  • i2c_host_error_t I2C1_ErrorGet (void)

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

  • bool I2C1_IsBusy (void)

    This API checks if I2C is busy. I2C must be initialized with I2C1_Initialize() before calling this API.

  • void I2C1_CallbackRegister (void(*callbackHandler)(void))

    Setter function for I2C interrupt callback, This will be called when any error is generated.

  • void I2C1_Tasks (void)

    This is polling function for non interrupt mode.

Detailed Description

I2C1 Generated Driver API Header File

Macro Definition Documentation

i2c_host_host_interface

#define i2c_host_host_interface I2C_Host

Section: Included Files

3.15.1.6.10 source/i2c_host_types.h File Reference