4.15.3 I2C in MSSP

Inter-Integrated Circuit in the Master Synchronous Serial Port

4.15.3.1 Introduction

The Master Synchronous Serial Port (MSSP) peripheral can operate in one of two modes: Serial Peripheral Interface (SPI) and I2C, having the advantage of implementing both communication protocols with the same hardware. The 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.

4.15.3.2 Supported Device Families

PIC16F152xx PIC16(L)F153xx PIC16(L)F188xx PIC16F171xx
PIC16F181xx PIC16F180xx PIC16(L)F191xx PIC16(L)F184xx
PIC16(L)F183xx PIC16(L)F193x PIC16(L)F194x PIC16(L)F178x
PIC12(L)F182x PIC16(L)F182x PIC12(L)F184x PIC16(L)F184x
PIC12(L)F161x PIC16(L)F161x PIC12(L)F150x PIC16(L)F150x
PIC12LF155x PIC16LF155x PIC16LF156x PIC16LF152x
PIC16(L)F170x PIC16(L)F171x PIC16(L)F176x PIC16(L)F177x
PIC16(L)F151x PIC16(L)F145x
PIC18F-K20 PIC18F-K22 PIC18F-K40 PIC18F-K20
PIC18F-K50 PIC18F-K80 PIC18F-K90 PIC18F-Q10

4.15.3.4 Module Documentation

4.15.3.4.1 I2C_CLIENT_PLIB

Module description

Modules
  • I2C_CLIENT_TYPES

    This file contains other data types for I2C module.

  • MSSP_CLIENT

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

MSSP_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
Variables
  • const struct I2C_CLIENT_INTERFACE I2C_Client

    External object for I2C_Client.

  • const struct I2C_CLIENT_INTERFACE I2C_Client

    External object for I2C_Client.

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_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_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_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

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

4.15.3.4.2 I2C_HOST_PLIB

Module description

Modules
  • I2C_HOST_TYPES

    This file contains other data types for I2C module.

  • MSSP_HOST

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

MSSP_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_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_Tasks (void)

    This is polling function for non interrupt mode.

Variables
  • const i2c_host_interface_t I2C1_Host

    External object for I2C1_Host.

  • const i2c_host_interface_t I2C1_Host

    External object for I2C1_Host.

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_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_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_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_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

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

4.15.3.5 Class Documentation

4.15.3.5.1 i2c_host_transfer_setup_t Struct Reference

Structure for i2c clock change.

Detailed Description

Structure for i2c clock change.

#include <i2c_host_types.h>

Member Data Documentation

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

source/

i2c_host_types.h

clkSpeed

uint32_t i2c_host_transfer_setup_t::clkSpeed

I2C Clock Speed

4.15.3.6 File Documentation

4.15.3.6.1 source/i2c_client_types.h File Reference

Enumerations

Detailed Description

I2C Generated Driver Types Header File

4.15.3.6.3 source/mssp_client_interrupt.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../mssp1.h"

Functions

Detailed Description

This file contains the driver code for I2C1 module.

MSSP1 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

4.15.3.6.4 source/mssp_client_interrupt.h File Reference

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

Functions

Macros

Variables

  • const struct I2C_CLIENT_INTERFACE I2C_Client

    External object for I2C_Client.

Detailed Description

MSSP1 Generated Driver API Header File

Macro Definition Documentation

i2c_client_client_interface

#define i2c_client_client_interface I2C_Client

Section: Data Type Definitions

4.15.3.6.5 source/mssp_client_polling.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../mssp1.h"

Functions

Detailed Description

This file contains the driver code for I2C1 module.

MSSP1 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

4.15.3.6.6 source/mssp_client_polling.h File Reference

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

Functions

Macros

Variables

  • const struct I2C_CLIENT_INTERFACE I2C_Client

    External object for I2C_Client.

Detailed Description

MSSP1 Generated Driver API Header File

Macro Definition Documentation

i2c_client_client_interface

#define i2c_client_client_interface I2C_Client

Section: Data Type Definitions

4.15.3.6.7 source/mssp_host_interrupt.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../mssp1.h"

Functions

  • static void I2C1_ReadStart (void)

  • static void I2C1_WriteStart (void)

  • static void I2C1_Close (void)

  • static void I2C1_EventHandler (void)

  • static void I2C1_ErrorEventHandler (void)

  • static void I2C1_DefaultCallback (void)

  • static uint8_t I2C1_DataReceive (void)

  • static void I2C1_DataTransmit (uint8_t data)

  • static void I2C1_BusReset (void)

  • static void I2C1_ReceiveEnable (void)

  • static void I2C1_RestartEnable (void)

  • static void I2C1_RestartDisable (void)

  • static void I2C1_StartSend (void)

  • static void I2C1_StopSend (void)

  • static void I2C1_AckSend (void)

  • static void I2C1_NackSend (void)

  • static bool I2C1_IsNack (void)

  • static bool I2C1_IsData (void)

  • static bool I2C1_IsAddr (void)

  • static bool I2C1_IsRxBufFull (void)

  • static void I2C1_InterruptsEnable (void)

  • static void I2C1_InterruptsDisable (void)

  • static void I2C1_InterruptClear (void)

  • static void I2C1_ErrorInterruptClear (void)

  • static void I2C1_StatusFlagsClear (void)

  • static i2c_host_event_states_t I2C1_EVENT_IDLE (void)

  • static i2c_host_event_states_t I2C1_EVENT_SEND_RD_ADDR (void)

  • static i2c_host_event_states_t I2C1_EVENT_SEND_WR_ADDR (void)

  • static i2c_host_event_states_t I2C1_EVENT_TX (void)

  • static i2c_host_event_states_t I2C1_EVENT_RX (void)

  • static i2c_host_event_states_t I2C1_EVENT_NACK (void)

  • static i2c_host_event_states_t I2C1_EVENT_ERROR (void)

  • static i2c_host_event_states_t I2C1_EVENT_STOP (void)

  • static i2c_host_event_states_t I2C1_EVENT_RESET (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.

Typedefs

  • typedef i2c_host_event_states_t(* i2c1eventHandler) (void)

Variables

  • const i2c_host_interface_t I2C1_Host

    External object for I2C1_Host.

  • static void(* I2C1_Callback )(void) = NULL

  • volatile i2c_host_event_status_t i2c1Status = {0}

  • const i2c1eventHandler i2c1_eventTable []

Detailed Description

This file contains the driver code for I2C1 module.

MSSP1 Generated Driver File

Version: I2C1 Driver Version 2.1.0

Variable Documentation

i2c1_eventTable

const i2c1eventHandler i2c1_eventTable[]

Initial value:

= {
    I2C1_EVENT_IDLE,
    I2C1_EVENT_SEND_RD_ADDR,
    I2C1_EVENT_SEND_WR_ADDR,
    I2C1_EVENT_TX,
    I2C1_EVENT_RX,
    I2C1_EVENT_NACK,
    I2C1_EVENT_ERROR,
    I2C1_EVENT_STOP,
    I2C1_EVENT_RESET
}

4.15.3.6.8 source/mssp_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.

Variables

  • const i2c_host_interface_t I2C1_Host

    External object for I2C1_Host.

Detailed Description

MSSP1 Generated Driver API Header File

Macro Definition Documentation

i2c1_host_host_interface

#define i2c1_host_host_interface I2C1_Host

Section: Included FilesSection: Data Type Definitions

4.15.3.6.9 source/mssp_host_polling.c File Reference

This file contains the driver code for I2C1 module.

#include <xc.h>
#include "../mssp1.h"

Functions

  • static void I2C1_ReadStart (void)

  • static void I2C1_WriteStart (void)

  • static void I2C1_Close (void)

  • static void I2C1_EventHandler (void)

  • static void I2C1_ErrorEventHandler (void)

  • static void I2C1_DefaultCallback (void)

  • static uint8_t I2C1_DataReceive (void)

  • static void I2C1_DataTransmit (uint8_t data)

  • static void I2C1_BusReset (void)

  • static void I2C1_ReceiveEnable (void)

  • static void I2C1_RestartEnable (void)

  • static void I2C1_RestartDisable (void)

  • static void I2C1_StartSend (void)

  • static void I2C1_StopSend (void)

  • static void I2C1_AckSend (void)

  • static void I2C1_NackSend (void)

  • static bool I2C1_IsNack (void)

  • static bool I2C1_IsData (void)

  • static bool I2C1_IsAddr (void)

  • static bool I2C1_IsRxBufFull (void)

  • static void I2C1_InterruptClear (void)

  • static void I2C1_ErrorInterruptClear (void)

  • static void I2C1_StatusFlagsClear (void)

  • static i2c_host_event_states_t I2C1_EVENT_IDLE (void)

  • static i2c_host_event_states_t I2C1_EVENT_SEND_RD_ADDR (void)

  • static i2c_host_event_states_t I2C1_EVENT_SEND_WR_ADDR (void)

  • static i2c_host_event_states_t I2C1_EVENT_TX (void)

  • static i2c_host_event_states_t I2C1_EVENT_RX (void)

  • static i2c_host_event_states_t I2C1_EVENT_NACK (void)

  • static i2c_host_event_states_t I2C1_EVENT_ERROR (void)

  • static i2c_host_event_states_t I2C1_EVENT_STOP (void)

  • static i2c_host_event_states_t I2C1_EVENT_RESET (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.

Typedefs

  • typedef i2c_host_event_states_t(* i2c1eventHandler) (void)

Variables

  • const i2c_host_interface_t I2C1_Host

    External object for I2C1_Host.

  • static void(* I2C1_Callback )(void) = NULL

  • volatile i2c_host_event_status_t i2c1Status = {0}

  • const i2c1eventHandler i2c1_eventTable []

Detailed Description

This file contains the driver code for I2C1 module.

MSSP1 Generated Driver File

Version: I2C1 Driver Version 2.1.0

Variable Documentation

i2c1_eventTable

const i2c1eventHandler i2c1_eventTable[]

Initial value:

= {
    I2C1_EVENT_IDLE,
    I2C1_EVENT_SEND_RD_ADDR,
    I2C1_EVENT_SEND_WR_ADDR,
    I2C1_EVENT_TX,
    I2C1_EVENT_RX,
    I2C1_EVENT_NACK,
    I2C1_EVENT_ERROR,
    I2C1_EVENT_STOP,
    I2C1_EVENT_RESET
}

4.15.3.6.10 source/mssp_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.

Variables

  • const i2c_host_interface_t I2C1_Host

    External object for I2C1_Host.

Detailed Description

MSSP1 Generated Driver API Header File

Macro Definition Documentation

i2c1_host_host_interface

#define i2c1_host_host_interface I2C1_Host

Section: Included FilesSection: Data Type Definitions