4.15.2 I2C with Baud Rate Prescaler
Inter-Integrated Circuit with Baud Rate Prescaler
4.15.2.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. This variant of the module features a Baud Rate Prescaler which allows you to fine-tune the clock speed for clock synchronization and compatibility, ensuring reliable and efficient data transfer.
4.15.2.2 Supported Device Families
PIC18F-Q2x | PIC18F-Q40 | PIC18F-Q41 |
PIC18F-Q71 | PIC18F-Q8x |
4.15.2.3 Required header files
#include <stdbool.h> #include <stdint.h> #include "mcc_generated_files/i2c_host/i2c_host_interface.h"
#include <stdbool.h> #include <stdint.h> #include "mcc_generated_files/i2c_client/i2c_client_interface.h"
4.15.2.4 How to Use the I2C PLIB Driver
For use-cases for the I2C, see:
The examples there use the portable API interface of the driver, but could easily be modified to directly us the PLIB API.
4.15.2.5 Module Documentation
4.15.2.5.1 I2C1_CLIENT_INTERRUPT
This header file contains API prototypes and other data types for the I2C1 driver.
This header file contains API prototypes and other data types for the I2C1 driver.
4.15.2.5.2 I2C_CLIENT
This header file provides the prototypes for the portable firmware interfaces for I2C client.
Module description
This header file provides the prototypes for the portable firmware interfaces for I2C client.
This header file contains API prototypes and other data types for the I2C1 driver.
Data structures
struct i2c_client_interface_t
This structure contains the portable interfaces for I2C client.
Enumerations
enum i2c_client_transfer_dir_t { I2C_CLIENT_TRANSFER_DIR_WRITE = 0, I2C_CLIENT_TRANSFER_DIR_READ = 1 }
Enumeration to determine the direction of data transfer initiated by the host, as determined by the I2Cx_TransferDirGet function.
enum i2c_client_ack_status_t { I2C_CLIENT_ACK_STATUS_RECEIVED_ACK = 0, I2C_CLIENT_ACK_STATUS_RECEIVED_NACK = 1 }
Enumeration for acknowledgment and non-acknowledgment status.
enum i2c_client_transfer_event_t { I2C_CLIENT_TRANSFER_EVENT_NONE = 0, I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH, I2C_CLIENT_TRANSFER_EVENT_RX_READY, I2C_CLIENT_TRANSFER_EVENT_TX_READY, I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED, I2C_CLIENT_TRANSFER_EVENT_ERROR}
Enumeration defining the various I2C event types.
enum i2c_client_error_t { I2C_CLIENT_ERROR_NONE = 0, I2C_CLIENT_ERROR_BUS_COLLISION, I2C_CLIENT_ERROR_WRITE_COLLISION, I2C_CLIENT_ERROR_RECEIVE_OVERFLOW, I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW, I2C_CLIENT_ERROR_READ_UNDERFLOW }
Enumeration that specifies the possible errors in the I2C client driver.
Functions
void I2C1_ISR (void)
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
void I2C1_ERROR_ISR (void)
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint8_t I2C1_ReadByte (void)
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint16_t I2C1_ReadAddr (void)
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_transfer_dir_t I2C1_TransferDirGet (void)
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void)
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
Registers a callback function.
void I2C1_Tasks (void)
Task to be polled I2C client events. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
Function Documentation
I2C1_CallbackRegister()
void I2C1_CallbackRegister (bool(*)(i2c_client_transfer_event_t clientEvent) callback)
Registers a callback function.
callback |
- Pointer to custom callback. |
None. |
I2C1_Deinitialize()
void I2C1_Deinitialize (void )
Resets the registers to their default Power-on Reset (POR) values.
None. |
None. |
I2C1_ERROR_ISR()
void I2C1_ERROR_ISR (void )
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
None. |
I2C1_ErrorGet()
i2c_client_error_t I2C1_ErrorGet (void )
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
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 error I2C_CLIENT_ERROR_NONE - No error |
I2C1_Initialize()
void I2C1_Initialize (void )
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
None. |
None. |
I2C1_ISR()
void I2C1_ISR (void )
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
None. |
I2C1_LastByteAckStatusGet()
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void )
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
None. |
I2C_CLIENT_ACK_STATUS_RECEIVED_ACK - An ACK was received for the most recent transaction with the host I2C_CLIENT_ACK_STATUS_RECEIVED_NACK - A NACK was received for the most recent transaction with the host |
I2C1_ReadAddr()
uint16_t I2C1_ReadAddr (void )
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
uint16_t - Last Matched address for I2C1 client |
I2C1_ReadByte()
uint8_t I2C1_ReadByte (void )
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
I2C1_Tasks()
void I2C1_Tasks (void )
Task to be polled I2C client events. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
None. |
I2C1_TransferDirGet()
i2c_client_transfer_dir_t I2C1_TransferDirGet (void )
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
I2C_CLIENT_TRANSFER_DIR_WRITE - I2C host writes to client I2C_CLIENT_TRANSFER_DIR_READ - I2C host reads from client |
I2C1_WriteByte()
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
in | data |
- I2C1 client write byte |
None. |
Enumeration Type Documentation
i2c_client_ack_status_t
enum i2c_client_ack_status_t
Enumeration for acknowledgment and non-acknowledgment status.
I2C_CLIENT_ACK_STATUS_RECEIVED_ACK | Host sent an ACK to I2C client |
I2C_CLIENT_ACK_STATUS_RECEIVED_NACK | Host sent a NACK to I2C client |
i2c_client_error_t
enum i2c_client_error_t
Enumeration that specifies the possible errors in the I2C client driver.
I2C_CLIENT_ERROR_NONE | Indicates no error |
I2C_CLIENT_ERROR_BUS_COLLISION | Indicates an error caused due to bus collision |
I2C_CLIENT_ERROR_WRITE_COLLISION | Indicates an error caused due to write collision |
I2C_CLIENT_ERROR_RECEIVE_OVERFLOW | Indicates an error due to a receive buffer overflow |
I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW | Indicates an error caused due to transmit buffer underflow |
I2C_CLIENT_ERROR_READ_UNDERFLOW | Indicates an error caused due to receive buffer underflow |
i2c_client_transfer_dir_t
enum i2c_client_transfer_dir_t
Enumeration to determine the direction of data transfer initiated by the host, as determined by the I2Cx_TransferDirGet function.
I2C_CLIENT_TRANSFER_DIR_WRITE | I2C client is writing to host |
I2C_CLIENT_TRANSFER_DIR_READ | I2C client is reading from host |
i2c_client_transfer_event_t
enum i2c_client_transfer_event_t
Enumeration defining the various I2C event types.
I2C_CLIENT_TRANSFER_EVENT_NONE | Event indicating that the I2C bus is in an idle state |
I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH | Event indicating that the I2C client has received a matching address |
I2C_CLIENT_TRANSFER_EVENT_RX_READY | Event indicating that the I2C client is prepared to receive data from the host |
I2C_CLIENT_TRANSFER_EVENT_TX_READY | Event indicating that the I2C client is ready to transmit data to the host |
I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED | Event indicating that the I2C client has received a stop bit |
I2C_CLIENT_TRANSFER_EVENT_ERROR | Event indicating an error occurred on the I2C bus |
4.15.2.5.3 I2C1_HOST_INTERRUPT
This header file contains API prototypes and various data types for the I2C1 host driver.
Module description
This header file contains API prototypes and various data types for the I2C1 host driver.
Data structures
struct i2c_host_event_status_t
Structure that defines the communication parameters for an I2C host.
struct i2c_host_transfer_setup_t
Structure for the I2C clock configuration.
Enumerations
enum i2c_host_error_t { I2C_ERROR_NONE, I2C_ERROR_ADDR_NACK, I2C_ERROR_DATA_NACK, I2C_ERROR_BUS_COLLISION}
Enumeration for the possible errors in the I2C host driver.
Functions
void I2C1_Initialize (void)
Initializes the I2C1 host module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
i2c_host_error_t I2C1_ErrorGet (void)
Retrieves the error that occurred during I2C transmission and reception. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_IsBusy (void)
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (void(*callback)(void))
Registers a callback function.
Function Documentation
I2C1_CallbackRegister()
void I2C1_CallbackRegister (void(*)(void) callback)
Registers a callback function.
handler |
- Pointer to custom callback |
None. |
I2C1_Deinitialize()
void I2C1_Deinitialize (void )
Resets the registers to their default Power-on Reset (POR) values.
None. |
None. |
I2C1_ErrorGet()
i2c_host_error_t I2C1_ErrorGet (void )
Retrieves the error that occurred during I2C transmission and reception. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
I2C_ERROR_NONE - Indicates no error I2C_ERROR_ADDR_NACK - Indicates that the I2C client did not acknowledge the address I2C_ERROR_DATA_NACK - Indicates that the I2C client did not acknowledge the data I2C_ERROR_BUS_COLLISION - Indicates an error caused due to bus collision |
I2C1_Initialize()
void I2C1_Initialize (void )
Initializes the I2C1 host module according to the settings specified in the MPLAB® Code Configurator Melody UI.
None. |
None. |
I2C1_IsBusy()
bool I2C1_IsBusy (void )
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
True - I2C bus busy False - I2C bus is idle |
I2C1_Read()
bool I2C1_Read (uint16_t address, uint8_t * data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
This function attempts to read a specified number of bytes received from the I2C client with the given address into the data buffer. The I2C Host initiates a Start condition, reads the data, and then generates a Stop condition. If the Client NAKs the request or a bus error occurs, the transfer is terminated. The application can call the I2C1_ErrorGet() function to determine the cause of the error.
This function is non-blocking; it starts the bus activity and returns immediately. The transfer is completed in the peripheral interrupt. In Polling mode, the user must call I2C1_Tasks within the while loop. A new transfer request cannot be initiated while another transfer is in progress. Calling this function during an ongoing transfer will result in the function returning false.
in | address |
- 7-bit or 10-bit client address |
out | data |
- Pointer to the destination buffer where the received data will be stored |
in | dataLength |
- The total number of bytes to be received |
True - The request was successfully placed, and bus activity has started False - The request failed as another transfer was already in progress when this function was called |
I2C1_Write()
bool I2C1_Write (uint16_t address, uint8_t * data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
This function attempts to write a specified number of bytes from the data buffer to a I2C client, identified by the provided address.
The TWI host will generate a Start condition, transmit the data, and then generate a Stop condition. If the client device responds with a NAK or if a bus error occurs, the transfer will be terminated. The application can call the I2C1_ErrorGet() function to determine the cause of the error. This function is non-blocking, meaning it initiates the bus activity and returns immediately. The transfer is then completed within the peripheral interrupt. In Polling mode, the user must call I2C1_Tasks within the while loop. A new transfer request cannot be initiated while another transfer is in progress. If this function is called while another transfer is ongoing, it will return false.
in | address |
- 7-bit or 10-bit client address |
in | data |
- Pointer to the buffer holding the data to be sent |
in | dataLength |
- The total number of bytes to be sent |
True - The request was successfully placed and bus activity has started False - The request failed as another transfer was already 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)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
If the Client responds with a NAK or a bus error occurs, the transfer is terminated. The application can call the I2C1_ErrorGet() function to determine the cause of the error.
This function is non-blocking; it initiates the bus activity and returns immediately. The transfer is then completed via the peripheral interrupt. In Polling mode, the user must call I2C1_Tasks within the while loop. A new transfer request cannot be initiated while another transfer is in progress. Calling this function during an ongoing transfer will result in the function returning false.
in | address |
- 7-bit or 10-bit client address |
in | writeData |
- Pointer to the buffer holding the data to be sent |
in | writeLength |
- The total number of bytes to be sent |
out | readData |
- Pointer to the destination buffer where the received data will be stored |
in | readLength |
- The total number of bytes to be received |
True - The request was successfully placed, and bus activity has started False - The request failed as another transfer was already in progress when this function was called |
4.15.2.5.4 I2C_HOST
This header file provides the prototypes for the portable firmware interfaces for I2C host.
Module description
This header file provides the prototypes for the portable firmware interfaces for I2C host.
This header file contains API prototypes and various data types for the I2C1 host driver.
Data structures
struct i2c_host_interface_t
This structure contains the portable interfaces for I2C host.
struct i2c_host_event_status_t
Structure that defines the communication parameters for an I2C host.
struct i2c_host_transfer_setup_t
Structure for the I2C clock configuration.
Functions
void I2C1_ISR (void)
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_ERROR_ISR (void)
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_RX_ISR (void)
Interrupt Service Routine (ISR) for I2C1 receive interrupts.
void I2C1_TX_ISR (void)
Interrupt Service Routine (ISR) for I2C1 transmit interrupts.
void I2C1_Initialize (void)
Initializes the I2C1 host module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
i2c_host_error_t I2C1_ErrorGet (void)
Retrieves the error that occurred during I2C transmission and reception. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_IsBusy (void)
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (void(*callback)(void))
Registers a callback function.
void I2C1_Tasks (void)
Task to be polled for I2C host events. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
Function Documentation
I2C1_CallbackRegister()
void I2C1_CallbackRegister (void(*)(void) callback)
Registers a callback function.
handler |
- Pointer to custom callback |
None. |
I2C1_Deinitialize()
void I2C1_Deinitialize (void )
Resets the registers to their default Power-on Reset (POR) values.
None. |
None. |
I2C1_ERROR_ISR()
void I2C1_ERROR_ISR (void )
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
None. |
I2C1_ErrorGet()
i2c_host_error_t I2C1_ErrorGet (void )
Retrieves the error that occurred during I2C transmission and reception. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
I2C_ERROR_NONE - Indicates no error I2C_ERROR_ADDR_NACK - Indicates that the I2C client did not acknowledge the address I2C_ERROR_DATA_NACK - Indicates that the I2C client did not acknowledge the data I2C_ERROR_BUS_COLLISION - Indicates an error caused due to bus collision |
I2C1_Initialize()
void I2C1_Initialize (void )
Initializes the I2C1 host module according to the settings specified in the MPLAB® Code Configurator Melody UI.
None. |
None. |
I2C1_IsBusy()
bool I2C1_IsBusy (void )
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
True - I2C bus busy False - I2C bus is idle |
I2C1_ISR()
void I2C1_ISR (void )
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
None. |
I2C1_Read()
bool I2C1_Read (uint16_t address, uint8_t * data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
This function attempts to read a specified number of bytes received from the I2C client with the given address into the data buffer. The I2C Host initiates a Start condition, reads the data, and then generates a Stop condition. If the Client NAKs the request or a bus error occurs, the transfer is terminated. The application can call the I2C1_ErrorGet() function to determine the cause of the error.
This function is non-blocking; it starts the bus activity and returns immediately. The transfer is completed in the peripheral interrupt. In Polling mode, the user must call I2C1_Tasks within the while loop. A new transfer request cannot be initiated while another transfer is in progress. Calling this function during an ongoing transfer will result in the function returning false.
in | address |
- 7-bit or 10-bit client address |
out | data |
- Pointer to the destination buffer where the received data will be stored |
in | dataLength |
- The total number of bytes to be received |
True - The request was successfully placed, and bus activity has started False - The request failed as another transfer was already in progress when this function was called |
I2C1_RX_ISR()
void I2C1_RX_ISR (void )
Interrupt Service Routine (ISR) for I2C1 receive interrupts.
None. |
None. |
I2C1_Tasks()
void I2C1_Tasks (void )
Task to be polled for I2C host events. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
None. |
None. |
I2C1_TX_ISR()
void I2C1_TX_ISR (void )
Interrupt Service Routine (ISR) for I2C1 transmit interrupts.
None. |
None. |
I2C1_Write()
bool I2C1_Write (uint16_t address, uint8_t * data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
This function attempts to write a specified number of bytes from the data buffer to a I2C client, identified by the provided address.
The TWI host will generate a Start condition, transmit the data, and then generate a Stop condition. If the client device responds with a NAK or if a bus error occurs, the transfer will be terminated. The application can call the I2C1_ErrorGet() function to determine the cause of the error. This function is non-blocking, meaning it initiates the bus activity and returns immediately. The transfer is then completed within the peripheral interrupt. In Polling mode, the user must call I2C1_Tasks within the while loop. A new transfer request cannot be initiated while another transfer is in progress. If this function is called while another transfer is ongoing, it will return false.
in | address |
- 7-bit or 10-bit client address |
in | data |
- Pointer to the buffer holding the data to be sent |
in | dataLength |
- The total number of bytes to be sent |
True - The request was successfully placed and bus activity has started False - The request failed as another transfer was already 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)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
If the Client responds with a NAK or a bus error occurs, the transfer is terminated. The application can call the I2C1_ErrorGet() function to determine the cause of the error.
This function is non-blocking; it initiates the bus activity and returns immediately. The transfer is then completed via the peripheral interrupt. In Polling mode, the user must call I2C1_Tasks within the while loop. A new transfer request cannot be initiated while another transfer is in progress. Calling this function during an ongoing transfer will result in the function returning false.
in | address |
- 7-bit or 10-bit client address |
in | writeData |
- Pointer to the buffer holding the data to be sent |
in | writeLength |
- The total number of bytes to be sent |
out | readData |
- Pointer to the destination buffer where the received data will be stored |
in | readLength |
- The total number of bytes to be received |
True - The request was successfully placed, and bus activity has started False - The request failed as another transfer was already in progress when this function was called |
Enumeration Type Documentation
i2c_host_error_t
enum i2c_host_error_t
Enumeration for the possible errors in the I2C host driver.
I2C_ERROR_NONE | Indicates no error |
I2C_ERROR_ADDR_NACK | Indicates that the I2C client did not acknowledge the address |
I2C_ERROR_DATA_NACK | Indicates that the I2C client did not acknowledge the data |
I2C_ERROR_BUS_COLLISION | Indicates an error caused due to bus collision |
4.15.2.6 Data Structure Documentation
4.15.2.6.1 i2c_client_interface_t Struct Reference
This structure contains the portable interfaces for I2C client.
Detailed Description
This structure contains the portable interfaces for I2C client.
#include <i2c_client_interface.h>
Data Fields
void(* Initialize )(void)
Pointer to the function that initializes the I2C client.
void(* Deinitialize )(void)
Pointer to the function that deinitializes the I2C client.
void(* WriteByte )(uint8_t data)
Pointer to the function that sends data to a host on bus.
uint8_t(* ReadByte )(void)
Pointer to the function that reads data from a host on bus.
i2c_client_error_t(* ErrorGet )(void)
Pointer to the function that returns the last error that occurred on the I2C bus.
i2c_client_transfer_dir_t(* TransferDirGet )(void)
Pointer to the function that returns the direction of data transfer between client and a host on bus.
i2c_client_ack_status_t(* LastByteAckStatusGet )(void)
Pointer to the function that retrieves the acknowledgment status of the last byte transferred.
void(* CallbackRegister )(bool(*handler)(i2c_client_transfer_event_t clientEvent))
Pointer to the function that registers a callback handler for I2C client.
void(* Tasks )(void)
Pointer to the function that is polled for I2C client events.
Field Documentation
The documentation for this struct was generated from the following file:
source/interrupt/i2c_client/
CallbackRegister
void(* CallbackRegister
Pointer to the function that registers a callback handler for I2C client.
Deinitialize
void(* Deinitialize
Pointer to the function that deinitializes the I2C client.
ErrorGet
i2c_client_error_t(* ErrorGet
Pointer to the function that returns the last error that occurred on the I2C bus.
Initialize
void(* Initialize
Pointer to the function that initializes the I2C client.
LastByteAckStatusGet
i2c_client_ack_status_t(* LastByteAckStatusGet
Pointer to the function that retrieves the acknowledgment status of the last byte transferred.
ReadByte
uint8_t(* ReadByte
Pointer to the function that reads data from a host on bus.
Tasks
void(* Tasks
Pointer to the function that is polled for I2C client events.
TransferDirGet
i2c_client_transfer_dir_t(* TransferDirGet
Pointer to the function that returns the direction of data transfer between client and a host on bus.
WriteByte
void(* WriteByte
Pointer to the function that sends data to a host on bus.
4.15.2.6.2 i2c_host_event_status_t Struct Reference
Structure that defines the communication parameters for an I2C host.
Detailed Description
Structure that defines the communication parameters for an I2C host.
#include <i2c_host_event_types.h>
Data Fields
bool busy
uint16_t address
uint8_t * writePtr
size_t writeLength
uint8_t * readPtr
size_t readLength
bool switchToRead
Field Documentation
The documentation for this struct was generated from the following file:
source/interrupt/i2c_host/
address
uint16_t address
I2C client address
busy
bool busy
A flag that signifies the host is currently busy
errorState
i2c_host_error_t errorState
An instance of i2c_host_error_t
readLength
size_t readLength
Number of bytes to be read from the client
readPtr
uint8_t * readPtr
Pointer to the buffer for received data
switchToRead
bool switchToRead
Boolean flag to indicate switching to read mode
writeLength
size_t writeLength
The number of bytes to be written or sent to the client
writePtr
uint8_t * writePtr
Pointer to the buffer used for transmission
4.15.2.6.3 i2c_host_interface_t Struct Reference
This structure contains the portable interfaces for I2C host.
Detailed Description
This structure contains the portable interfaces for I2C host.
#include <i2c_host_interface.h>
Data Fields
void(* Initialize )(void)
Pointer to the function that initializes the I2C host, setting up any necessary hardware or software resources.
void(* Deinitialize )(void)
Pointer to the function that deinitializes the I2C host, by resetting the I2C registers to Power On Default (POR) values.
bool(* Write )(uint16_t address, uint8_t *data, size_t dataLength)
Pointer to the write function of the I2C host.
bool(* Read )(uint16_t address, uint8_t *data, size_t dataLength)
Pointer to the read function of the I2C host.
bool(* WriteRead )(uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Pointer to the write and read function of the I2C host.
bool(* TransferSetup )(struct i2c_transfer_setup *setup, uint32_t srcClkFreq)
Pointer to the function that sets up the transfer parameters of the I2C host.
i2c_host_error_t(* ErrorGet )(void)
Pointer to the function that returns the last error that occurred on the I2C bus.
bool(* IsBusy )(void)
Pointer to the function that checks if the I2C bus is busy.
void(* CallbackRegister )(void(*callback)(void))
Pointer to the function that Registers a callback function for I2C events.
void(* Tasks )(void)
Pointer to the function that is polled for I2C host events.
Field Documentation
The documentation for this struct was generated from the following file:
source/interrupt/i2c_host/
CallbackRegister
void(* CallbackRegister
Pointer to the function that Registers a callback function for I2C events.
Deinitialize
void(* Deinitialize
Pointer to the function that deinitializes the I2C host, by resetting the I2C registers to Power On Default (POR) values.
ErrorGet
i2c_host_error_t(* ErrorGet
Pointer to the function that returns the last error that occurred on the I2C bus.
Initialize
void(* Initialize
Pointer to the function that initializes the I2C host, setting up any necessary hardware or software resources.
IsBusy
bool(* IsBusy
Pointer to the function that checks if the I2C bus is busy.
Read
bool(* Read
Pointer to the read function of the I2C host.
Tasks
void(* Tasks
Pointer to the function that is polled for I2C host events.
TransferSetup
bool(* TransferSetup
Pointer to the function that sets up the transfer parameters of the I2C host.
Write
bool(* Write
Pointer to the write function of the I2C host.
WriteRead
bool(* WriteRead
Pointer to the write and read function of the I2C host.
4.15.2.6.4 i2c_host_transfer_setup_t Struct Reference
Structure for the I2C clock configuration.
Detailed Description
Structure for the I2C clock configuration.
#include <i2c_host_types.h>
The documentation for this struct was generated from the following file:
source/interrupt/i2c_host/
4.15.2.6.5 i2c_transfer_setup Struct Reference
Detailed Description
@misradeviation{Advisory:,2.4,Advisory:,2.3} These declarations are provided by the Melody-generated drivers for the user’s application. It is up to the user if these declarations will be implemented in their application.
#include <i2c_host_types.h>
Data Fields
uint32_t clkSpeed
Field Documentation
The documentation for this struct was generated from the following file:
source/interrupt/i2c_host/
clkSpeed
uint32_t clkSpeed
4.15.2.7 File Documentation
4.15.2.7.1 source/interrupt/i2c_client/i2c1.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h" #include "i2c_client_interface.h"
Functions
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint8_t I2C1_ReadByte (void)
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint16_t I2C1_ReadAddr (void)
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_transfer_dir_t I2C1_TransferDirGet (void)
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void)
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
Registers a callback function.
void I2C1_ISR (void)
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
void I2C1_ERROR_ISR (void)
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
Macros
#define i2c2_client_interface I2C2_Client
#define I2C2_Client_WriteByte I2C1_WriteByte
#define I2C2_Client_ReadByte I2C1_ReadByte
#define I2C2_Client_ReadAddr I2C1_ReadAddr
#define I2C2_Client_ErrorGet I2C1_ErrorGet
#define I2C2_Client_LastByteAckStatusGet I2C1_LastByteAckStatusGet
#define I2C2_Client_Tasks I2C1_Tasks
Variables
const i2c_client_interface_t I2C2_Client
Represents an instance of the portable interface structure designed for I2C1 client.
Detailed Description
A header file generated by I2C1 I2C client driver.
Function Documentation
I2C1_CallbackRegister()
void I2C1_CallbackRegister (bool(*)(i2c_client_transfer_event_t clientEvent) callback)
Registers a callback function.
callback |
- Pointer to custom callback. |
None. |
I2C1_Deinitialize()
void I2C1_Deinitialize (void )
Resets the registers to their default Power-on Reset (POR) values.
None. |
None. |
I2C1_ErrorGet()
i2c_client_error_t I2C1_ErrorGet (void )
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
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 error I2C_CLIENT_ERROR_NONE - No error |
I2C1_Initialize()
void I2C1_Initialize (void )
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
None. |
None. |
I2C1_LastByteAckStatusGet()
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void )
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
None. |
I2C_CLIENT_ACK_STATUS_RECEIVED_ACK - An ACK was received for the most recent transaction with the host I2C_CLIENT_ACK_STATUS_RECEIVED_NACK - A NACK was received for the most recent transaction with the host |
I2C1_ReadAddr()
uint16_t I2C1_ReadAddr (void )
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
uint16_t - Last Matched address for I2C1 client |
I2C1_ReadByte()
uint8_t I2C1_ReadByte (void )
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
I2C1_TransferDirGet()
i2c_client_transfer_dir_t I2C1_TransferDirGet (void )
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
None. |
I2C_CLIENT_TRANSFER_DIR_WRITE - I2C host writes to client I2C_CLIENT_TRANSFER_DIR_READ - I2C host reads from client |
I2C1_WriteByte()
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
in | data |
- I2C1 client write byte |
None. |
Macro Definition Documentation
I2C2_Client_CallbackRegister
#define I2C2_Client_CallbackRegister I2C1_CallbackRegister
I2C2_Client_Deinitialize
#define I2C2_Client_Deinitialize I2C1_Deinitialize
I2C2_Client_ErrorGet
#define I2C2_Client_ErrorGet I2C1_ErrorGet
I2C2_Client_Initialize
#define I2C2_Client_Initialize I2C1_Initialize
i2c2_client_interface
#define i2c2_client_interface I2C2_Client
@misradeviation {advisory,2.5} False positive - A few macros in this file are used as arguments but are not getting recognized by the tool. This rule ID has been disabled at the project level due to numerous instances across various files. Consequently, in the application project, this rule ID must be disabled in the MPLAB-X IDE by navigation to Tools -> Options -> Embedded -> MISRA Check.
I2C2_Client_LastByteAckStatusGet
#define I2C2_Client_LastByteAckStatusGet I2C1_LastByteAckStatusGet
I2C2_Client_ReadAddr
#define I2C2_Client_ReadAddr I2C1_ReadAddr
I2C2_Client_ReadByte
#define I2C2_Client_ReadByte I2C1_ReadByte
I2C2_Client_Tasks
#define I2C2_Client_Tasks I2C1_Tasks
I2C2_Client_TransferDirGet
#define I2C2_Client_TransferDirGet I2C1_TransferDirGet
I2C2_Client_WriteByte
#define I2C2_Client_WriteByte I2C1_WriteByte
Variable Documentation
I2C2_Client
const i2c_client_interface_t I2C2_Client
Represents an instance of the portable interface structure designed for I2C1 client.
@misradeviation {Advisory:,8.7} Some Melody-generated driver APIs are made available to users through external linkage. Users have the option to add these APIs in the application.This rule ID is disabled at project level due to its multiple occurrences in several files.Therefore, in the application project, this rule ID must be disabled in the MPLAB-X IDE from Tools -> Options -> Embedded -> MISRA Check.
4.15.2.7.2 source/interrupt/i2c_host/i2c1.h File Reference
#include <stdint.h> #include <stdbool.h> #include "i2c_host_event_types.h" #include "i2c_host_interface.h"
Functions
void I2C1_Initialize (void)
Initializes the I2C1 host module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
i2c_host_error_t I2C1_ErrorGet (void)
Retrieves the error that occurred during I2C transmission and reception. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_IsBusy (void)
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (void(*callback)(void))
Registers a callback function.
void I2C1_ISR (void)
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_ERROR_ISR (void)
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_RX_ISR (void)
Interrupt Service Routine (ISR) for I2C1 receive interrupts.
void I2C1_TX_ISR (void)
Interrupt Service Routine (ISR) for I2C1 transmit interrupts.
Macros
#define i2c2_host_host_interface I2C2_Host
#define I2C2_Host_Initialize I2C1_Initialize
#define I2C2_Host_Write I2C1_Write
#define I2C2_Host_Read I2C1_Read
#define I2C2_Host_WriteRead I2C1_WriteRead
#define I2C2_Host_ErrorGet I2C1_ErrorGet
#define I2C2_Host_IsBusy I2C1_IsBusy
Variables
const i2c_host_interface_t I2C2_Host
Represents an instance of the portable interface structure designed for I2C1 host.
Detailed Description
A header file generated by I2C1 I2C host driver.
Macro Definition Documentation
I2C2_Host_CallbackRegister
#define I2C2_Host_CallbackRegister I2C1_CallbackRegister
I2C2_Host_Deinitialize
#define I2C2_Host_Deinitialize I2C1_Deinitialize
I2C2_Host_ErrorGet
#define I2C2_Host_ErrorGet I2C1_ErrorGet
i2c2_host_host_interface
#define i2c2_host_host_interface I2C2_Host
@misradeviation {advisory,2.5} False positive - A few macros in this file are used as arguments but are not getting recognized by the tool. This rule ID has been disabled at the project level due to numerous instances across various files. Consequently, in the application project, this rule ID must be disabled in the MPLAB-X IDE by navigating to Tools>Options>Embedded>MISRA Check.
I2C2_Host_Initialize
#define I2C2_Host_Initialize I2C1_Initialize
I2C2_Host_IsBusy
#define I2C2_Host_IsBusy I2C1_IsBusy
I2C2_Host_Read
#define I2C2_Host_Read I2C1_Read
I2C2_Host_Write
#define I2C2_Host_Write I2C1_Write
I2C2_Host_WriteRead
#define I2C2_Host_WriteRead I2C1_WriteRead
Variable Documentation
I2C2_Host
const i2c_host_interface_t I2C2_Host
Represents an instance of the portable interface structure designed for I2C1 host.
4.15.2.7.3 source/polling/i2c_client/i2c1.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h" #include "i2c_client_interface.h"
Functions
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint8_t I2C1_ReadByte (void)
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint16_t I2C1_ReadAddr (void)
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_transfer_dir_t I2C1_TransferDirGet (void)
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void)
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
Registers a callback function.
void I2C1_Tasks (void)
Task to be polled I2C client events. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
Macros
-
#define i2c2_client_interface I2C2_Client
-
#define I2C2_Client_WriteByte I2C1_WriteByte
-
#define I2C2_Client_ReadByte I2C1_ReadByte
-
#define I2C2_Client_ReadAddr I2C1_ReadAddr
-
#define I2C2_Client_ErrorGet I2C1_ErrorGet
-
#define I2C2_Client_LastByteAckStatusGet I2C1_LastByteAckStatusGet
-
#define I2C2_Client_Tasks I2C1_Tasks
Variables
const i2c_client_interface_t I2C1_Client
Represents an instance of the portable interface structure designed for I2C1 client.
Detailed Description
A header file generated by I2C1 I2C client driver.
Macro Definition Documentation
I2C1_Client_CallbackRegister
#define I2C1_Client_CallbackRegister I2C1_CallbackRegister
I2C1_Client_Deinitialize
#define I2C1_Client_Deinitialize I2C1_Deinitialize
I2C1_Client_ErrorGet
#define I2C1_Client_ErrorGet I2C1_ErrorGet
I2C1_Client_Initialize
#define I2C1_Client_Initialize I2C1_Initialize
i2c1_client_interface
#define i2c1_client_interface I2C1_Client
@misradeviation {advisory,2.5} False positive - A few macros in this file are used as arguments but are not getting recognized by the tool. This rule ID has been disabled at the project level due to numerous instances across various files. Consequently, in the application project, this rule ID must be disabled in the MPLAB-X IDE by navigation to Tools -> Options -> Embedded -> MISRA Check.
I2C1_Client_LastByteAckStatusGet
#define I2C1_Client_LastByteAckStatusGet I2C1_LastByteAckStatusGet
I2C1_Client_ReadAddr
#define I2C1_Client_ReadAddr I2C1_ReadAddr
I2C1_Client_ReadByte
#define I2C1_Client_ReadByte I2C1_ReadByte
I2C1_Client_Tasks
#define I2C1_Client_Tasks I2C1_Tasks
I2C1_Client_TransferDirGet
#define I2C1_Client_TransferDirGet I2C1_TransferDirGet
I2C1_Client_WriteByte
#define I2C1_Client_WriteByte I2C1_WriteByte
Variable Documentation
I2C1_Client
const i2c_client_interface_t I2C1_Client
Represents an instance of the portable interface structure designed for I2C1 client.
@misradeviation {Advisory:,8.7} Some Melody-generated driver APIs are made available to users through external linkage. Users have the option to add these APIs in the application.This rule ID is disabled at project level due to its multiple occurrences in several files.Therefore, in the application project, this rule ID must be disabled in the MPLAB-X IDE from Tools -> Options -> Embedded -> MISRA Check.
4.15.2.7.4 source/polling/i2c_host/i2c1.h File Reference
#include <stdint.h> #include <stdbool.h> #include "i2c_host_event_types.h" #include "i2c_host_interface.h"
Functions
void I2C1_Initialize (void)
Initializes the I2C1 host module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
i2c_host_error_t I2C1_ErrorGet (void)
Retrieves the error that occurred during I2C transmission and reception. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_IsBusy (void)
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (void(*callback)(void))
Registers a callback function.
void I2C1_Tasks (void)
Task to be polled for I2C host events. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
Macros
#define i2c1_host_host_interface I2C1_Host
#define I2C1_Host_Initialize I2C1_Initialize
#define I2C1_Host_Write I2C1_Write
#define I2C1_Host_Read I2C1_Read
#define I2C1_Host_WriteRead I2C1_WriteRead
#define I2C1_Host_ErrorGet I2C1_ErrorGet
#define I2C1_Host_IsBusy I2C1_IsBusy
#define I2C1_Host_Tasks I2C1_Tasks
Variables
const i2c_host_interface_t I2C1_Host
Represents an instance of the portable interface structure designed for I2C1 host.
Detailed Description
A header file generated by I2C1 I2C host driver.
Macro Definition Documentation
I2C1_Host_CallbackRegister
#define I2C1_Host_CallbackRegister I2C1_CallbackRegister
I2C1_Host_Deinitialize
#define I2C1_Host_Deinitialize I2C1_Deinitialize
I2C1_Host_ErrorGet
#define I2C1_Host_ErrorGet I2C1_ErrorGet
i2c1_host_host_interface
#define i2c1_host_host_interface I2C1_Host
@misradeviation {advisory,2.5} False positive - A few macros in this file are used as arguments but are not getting recognized by the tool. This rule ID has been disabled at the project level due to numerous instances across various files. Consequently, in the application project, this rule ID must be disabled in the MPLAB-X IDE by navigating to Tools>Options>Embedded>MISRA Check.
I2C1_Host_Initialize
#define I2C1_Host_Initialize I2C1_Initialize
I2C1_Host_IsBusy
#define I2C1_Host_IsBusy I2C1_IsBusy
I2C1_Host_Read
#define I2C1_Host_Read I2C1_Read
I2C1_Host_Tasks
#define I2C1_Host_Tasks I2C1_Tasks
I2C1_Host_Write
#define I2C1_Host_Write I2C1_Write
I2C1_Host_WriteRead
#define I2C1_Host_WriteRead I2C1_WriteRead
Variable Documentation
I2C1_Host
const i2c_host_interface_t I2C1_Host
Represents an instance of the portable interface structure designed for I2C1 host.
4.15.2.7.5 source/interrupt/i2c_client/i2c_client_interface.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h"
Data structures
struct i2c_client_interface_t
This structure contains the portable interfaces for I2C client.
Detailed Description
A header file generated by I2C client driver
4.15.2.7.6 source/polling/i2c_client/i2c_client_interface.h File Reference
#include <stdbool.h> #include <stdint.h> #include "i2c_client_types.h"
Data structures
struct i2c_client_interface_t
This structure contains the portable interfaces for I2C client.
Detailed Description
A header file generated by I2C client driver
4.15.2.7.7 source/interrupt/i2c_client/i2c_client_types.h File Reference
This header file contains helper structures for the implementation of the I2C client driver.
Enumerations
-
enum i2c_client_transfer_dir_t { I2C_CLIENT_TRANSFER_DIR_WRITE = 0, I2C_CLIENT_TRANSFER_DIR_READ = 1 }
Enumeration to determine the direction of data transfer initiated by the host, as determined by the I2Cx_TransferDirGet function.
-
enum i2c_client_ack_status_t { I2C_CLIENT_ACK_STATUS_RECEIVED_ACK = 0, I2C_CLIENT_ACK_STATUS_RECEIVED_NACK = 1 }
Enumeration for acknowledgment and non-acknowledgment status.
-
enum i2c_client_transfer_event_t { I2C_CLIENT_TRANSFER_EVENT_NONE = 0, I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH, I2C_CLIENT_TRANSFER_EVENT_RX_READY, I2C_CLIENT_TRANSFER_EVENT_TX_READY, I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED, I2C_CLIENT_TRANSFER_EVENT_ERROR}
Enumeration defining the various I2C event types.
-
enum i2c_client_error_t { I2C_CLIENT_ERROR_NONE = 0, I2C_CLIENT_ERROR_BUS_COLLISION, I2C_CLIENT_ERROR_WRITE_COLLISION, I2C_CLIENT_ERROR_RECEIVE_OVERFLOW, I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW, I2C_CLIENT_ERROR_READ_UNDERFLOW }
Enumeration that specifies the possible errors in the I2C client driver.
Detailed Description
This header file contains helper structures for the implementation of the I2C client driver.
I2C Generated Driver Types Header File
4.15.2.7.8 source/polling/i2c_client/i2c_client_types.h File Reference
This header file contains helper structures for the implementation of the I2C client driver.
Enumerations
enum i2c_client_transfer_dir_t { I2C_CLIENT_TRANSFER_DIR_WRITE = 0, I2C_CLIENT_TRANSFER_DIR_READ = 1 }
enum i2c_client_ack_status_t { I2C_CLIENT_ACK_STATUS_RECEIVED_ACK = 0, I2C_CLIENT_ACK_STATUS_RECEIVED_NACK = 1}
enum i2c_client_transfer_event_t { I2C_CLIENT_TRANSFER_EVENT_NONE = 0, I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH, I2C_CLIENT_TRANSFER_EVENT_RX_READY, I2C_CLIENT_TRANSFER_EVENT_TX_READY, I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED, I2C_CLIENT_TRANSFER_EVENT_ERROR }
enum i2c_client_error_t { I2C_CLIENT_ERROR_NONE = 0, I2C_CLIENT_ERROR_BUS_COLLISION, I2C_CLIENT_ERROR_WRITE_COLLISION, I2C_CLIENT_ERROR_RECEIVE_OVERFLOW, I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW, I2C_CLIENT_ERROR_READ_UNDERFLOW }
Detailed Description
This header file contains helper structures for the implementation of the I2C client driver.
I2C Generated Driver Types Header File
Enumeration Type Documentation
i2c_client_ack_status_t
enum i2c_client_ack_status_t
I2C_CLIENT_ACK_STATUS_RECEIVED_ACK | Host sent an ACK to I2C client |
I2C_CLIENT_ACK_STATUS_RECEIVED_NACK | Host sent a NACK to I2C client |
i2c_client_error_t
enum i2c_client_error_t
I2C_CLIENT_ERROR_NONE |
Indicates no error |
I2C_CLIENT_ERROR_BUS_COLLISION |
Indicates an error caused due to bus collision |
I2C_CLIENT_ERROR_WRITE_COLLISION |
Indicates an error caused due to write collision |
I2C_CLIENT_ERROR_RECEIVE_OVERFLOW |
Indicates an error due to a receive buffer overflow |
I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW |
Indicates an error caused due to transmit buffer underflow |
I2C_CLIENT_ERROR_READ_UNDERFLOW |
Indicates an error caused due to receive buffer underflow |
I2C_CLIENT_ERROR_NONE |
Indicates no error |
I2C_CLIENT_ERROR_BUS_COLLISION |
Indicates an error caused due to bus collision |
I2C_CLIENT_ERROR_WRITE_COLLISION |
Indicates an error caused due to write collision |
I2C_CLIENT_ERROR_RECEIVE_OVERFLOW |
Indicates an error due to a receive buffer overflow |
I2C_CLIENT_ERROR_TRANSMIT_UNDERFLOW |
Indicates an error caused due to transmit buffer underflow |
I2C_CLIENT_ERROR_READ_UNDERFLOW |
Indicates an error caused due to receive buffer underflow |
i2c_client_transfer_dir_t
enum i2c_client_transfer_dir_t
I2C_CLIENT_TRANSFER_DIR_WRITE | I2C client is writing to host |
I2C_CLIENT_TRANSFER_DIR_READ | I2C client is reading from host |
i2c_client_transfer_event_t
enum i2c_client_transfer_event_t
I2C_CLIENT_TRANSFER_EVENT_NONE |
Event indicating that the I2C bus is in an idle state |
I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH |
Event indicating that the I2C client has received a matching address |
I2C_CLIENT_TRANSFER_EVENT_RX_READY |
Event indicating that the I2C client is prepared to receive data from the host |
I2C_CLIENT_TRANSFER_EVENT_TX_READY |
Event indicating that the I2C client is ready to transmit data to the host |
I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED |
Event indicating that the I2C client has received a stop bit |
I2C_CLIENT_TRANSFER_EVENT_ERROR |
Event indicating an error occurred on the I2C bus |
I2C_CLIENT_TRANSFER_EVENT_NONE |
Event indicating that the I2C bus is in an idle state |
I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH |
Event indicating that the I2C client has received a matching address |
I2C_CLIENT_TRANSFER_EVENT_RX_READY |
Event indicating that the I2C client is prepared to receive data from the host |
I2C_CLIENT_TRANSFER_EVENT_TX_READY |
Event indicating that the I2C client is ready to transmit data to the host |
I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED |
Event indicating that the I2C client has received a stop bit |
I2C_CLIENT_TRANSFER_EVENT_ERROR |
Event indicating an error occurred on the I2C bus |
4.15.2.7.9 source/interrupt/i2c_client/src/i2c1.c File Reference
This file contains API implementation for the I2C1 driver.
#include <xc.h> #include "../../system/config_bits.h" #include "../i2c1.h"
Functions
static void I2C1_EventHandler (void)
static void I2C1_ErrorEventHandler (void)
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint8_t I2C1_ReadByte (void)
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
uint16_t I2C1_ReadAddr (void)
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_transfer_dir_t I2C1_TransferDirGet (void)
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void)
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
Registers a callback function.
void I2C1_ISR (void)
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
void I2C1_ERROR_ISR (void)
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
Variables
const i2c_client_interface_t I2C2_Client
Represents an instance of the portable interface structure designed for I2C1 client.
static volatile i2c_client_error_t i2c1ErrorState
static bool(* I2C1_InterruptHandler )(i2c_client_transfer_event_t clientEvent)
Detailed Description
This file contains API implementation for the I2C1 driver.
A source file generated by I2C1 I2C client driver.
Function Documentation
I2C1_ErrorEventHandler()
static void I2C1_ErrorEventHandler (void )[static]
I2C1_EventHandler()
static void I2C1_EventHandler (void )[static]
Variable Documentation
I2C1_InterruptHandler
bool(* I2C1_InterruptHandler) (i2c_client_transfer_event_t clientEvent)[static]
i2c1ErrorState
volatile i2c_client_error_t i2c1ErrorState[static]
I2C2_Client
const i2c_client_interface_t I2C2_Client
Initial value:
= { .Initialize = I2C1_Initialize, .Deinitialize = I2C1_Deinitialize, .WriteByte = I2C1_WriteByte, .ReadByte = I2C1_ReadByte, .TransferDirGet = I2C1_TransferDirGet, .LastByteAckStatusGet = I2C1_LastByteAckStatusGet, .ErrorGet = I2C1_ErrorGet, .CallbackRegister = I2C1_CallbackRegister, .Tasks = NULL }
Represents an instance of the portable interface structure designed for I2C1 client.
@misradeviation {Advisory:,8.7} Some Melody-generated driver APIs are made available to users through external linkage. Users have the option to add these APIs in the application.This rule ID is disabled at project level due to its multiple occurrences in several files.Therefore, in the application project, this rule ID must be disabled in the MPLAB-X IDE from Tools -> Options -> Embedded -> MISRA Check.
4.15.2.7.10 source/interrupt/i2c_host/src/i2c1.c File Reference
This file contains the API implementation for the I2C1 driver.
#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_BusReset (void)
static void I2C1_InterruptsEnable (void)
static void I2C1_InterruptsDisable (void)
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
i2c_host_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_IsBusy (void)
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (void(*callbackHandler)(void))
Registers a callback function.
void I2C1_ISR (void)
Interrupt Service Routine (ISR) function for all I2C1 interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
void I2C1_ERROR_ISR (void)
Interrupt Service Routine (ISR) for error interrupts. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
void I2C1_RX_ISR (void)
Interrupt Service Routine (ISR) for I2C1 receive interrupts.
void I2C1_TX_ISR (void)
Interrupt Service Routine (ISR) for I2C1 transmit interrupts.
Variables
const i2c_host_interface_t I2C2_Host
Represents an instance of the portable interface structure designed for I2C1 host.
static void(* I2C1_Callback )(void)
volatile i2c_host_event_status_t i2c1Status = {0}
Detailed Description
This file contains the API implementation for the I2C1 driver.
A source file generated by I2C1 I2C host driver.
Function Documentation
I2C1_BusReset()
inline static void I2C1_BusReset (void )
I2C1_Close()
static void I2C1_Close (void )[static]
I2C1_InterruptsDisable()
inline static void I2C1_InterruptsDisable (void )
I2C1_InterruptsEnable()
inline static void I2C1_InterruptsEnable (void )
I2C1_ReadStart()
static void I2C1_ReadStart (void )[static]
@misradeviation {Advisory:,8.7} Some Melody-generated driver APIs are made available to users through external linkage. Users have the option to add these APIs in the application.This rule ID is disabled at project level due to its multiple occurrences in several files.Therefore, in the application project, this rule ID must be disabled in the MPLAB-X IDE from Tools -> Options -> Embedded -> MISRA Check.
I2C1_WriteStart()
static void I2C1_WriteStart (void )[static]
Variable Documentation
I2C1_Callback
void(* I2C1_Callback) (void)[static]
i2c1Status
volatile i2c_host_event_status_t i2c1Status = {0}
I2C2_Host
const i2c_host_interface_t I2C2_Host
Initial value:
= { .Initialize = I2C1_Initialize, .Deinitialize = I2C1_Deinitialize, .Write = I2C1_Write, .Read = I2C1_Read, .WriteRead = I2C1_WriteRead, .TransferSetup = NULL, .ErrorGet = I2C1_ErrorGet, .IsBusy = I2C1_IsBusy, .CallbackRegister = I2C1_CallbackRegister, .Tasks = NULL }
Represents an instance of the portable interface structure designed for I2C1 host.
4.15.2.7.11 source/polling/i2c_client/src/i2c1.c File Reference
This file contains API implementation for the I2C1 driver.
#include <xc.h> #include "../../system/config_bits.h" #include "../i2c1.h"
Functions
-
static void I2C1_EventHandler (void)
-
static void I2C1_ErrorEventHandler (void)
-
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
-
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
-
void I2C1_WriteByte (uint8_t data)
Sends data to a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
-
uint8_t I2C1_ReadByte (void)
Reads data from a host on the bus. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
-
uint16_t I2C1_ReadAddr (void)
Retrieves the most recently matched address received from the host. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
-
i2c_client_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
-
i2c_client_transfer_dir_t I2C1_TransferDirGet (void)
Retrieves the data transfer direction. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
-
i2c_client_ack_status_t I2C1_LastByteAckStatusGet (void)
Retrieves the acknowledgement status from host. Ensure I2C1 is initialized using I2C1_Initialize() before invoking this function.
-
void I2C1_CallbackRegister (bool(*callback)(i2c_client_transfer_event_t clientEvent))
Registers a callback function.
void I2C1_Tasks (void)
Task to be polled I2C client events. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
Variables
const i2c_client_interface_t I2C1_Client
Represents an instance of the portable interface structure designed for I2C1 client.
static volatile i2c_client_error_t i2c1ErrorState
static bool(* I2C1_InterruptHandler )(i2c_client_transfer_event_t clientEvent)
Detailed Description
This file contains API implementation for the I2C1 driver.
A source file generated by I2C1 I2C client driver.
Function Documentation
I2C1_ErrorEventHandler()
static void I2C1_ErrorEventHandler (void )[static]
I2C1_EventHandler()
static void I2C1_EventHandler (void )[static]
Variable Documentation
I2C1_Client
const i2c_client_interface_t I2C1_Client
Initial value:
= { .Initialize = I2C1_Initialize, .Deinitialize = I2C1_Deinitialize, .WriteByte = I2C1_WriteByte, .ReadByte = I2C1_ReadByte, .TransferDirGet = I2C1_TransferDirGet, .LastByteAckStatusGet = I2C1_LastByteAckStatusGet, .ErrorGet = I2C1_ErrorGet, .CallbackRegister = I2C1_CallbackRegister, .Tasks = I2C1_Tasks }
Represents an instance of the portable interface structure designed for I2C1 client.
@misradeviation {Advisory:,8.7} Some Melody-generated driver APIs are made available to users through external linkage. Users have the option to add these APIs in the application.This rule ID is disabled at project level due to its multiple occurrences in several files.Therefore, in the application project, this rule ID must be disabled in the MPLAB-X IDE from Tools -> Options -> Embedded -> MISRA Check.
I2C1_InterruptHandler
bool(* I2C1_InterruptHandler) (i2c_client_transfer_event_t clientEvent)[static]
i2c1ErrorState
volatile i2c_client_error_t i2c1ErrorState[static]
4.15.2.7.12 source/polling/i2c_host/src/i2c1.c File Reference
This file contains the API implementation for the I2C1 driver.
#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_BusReset (void)
void I2C1_Initialize (void)
Initializes the I2C1 client module according to the settings specified in the MPLAB® Code Configurator Melody UI.
void I2C1_Deinitialize (void)
Resets the registers to their default Power-on Reset (POR) values.
bool I2C1_Write (uint16_t address, uint8_t *data, size_t dataLength)
Sends data to a client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_Read (uint16_t address, uint8_t *data, size_t dataLength)
Reads data from an I2C client on the bus. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_WriteRead (uint16_t address, uint8_t *writeData, size_t writeLength, uint8_t *readData, size_t readLength)
Initiates a data transfer by writing data from the writeData function to the bus and subsequently reads data from the Client, storing the received data in the readData parameter. The function generates a Start condition on the bus and transmits the specified number of bytes (writeLength) from the writeData buffer. Following this, a Repeated Start condition is inserted, and the function proceeds to read the specified number of bytes (readLength) from the client, storing them in the readData buffer. A Stop condition is generated after the final byte is received.
i2c_host_error_t I2C1_ErrorGet (void)
Retrieves the type of error that occurred during I2C communication. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
bool I2C1_IsBusy (void)
Determines if the I2C bus is currently busy. Ensure I2C1 host is initialized using I2C1_Initialize() before invoking this function.
void I2C1_CallbackRegister (void(*callbackHandler)(void))
Registers a callback function.
void I2C1_Tasks (void)
Task to be polled I2C client events. Ensure I2C1 client is initialized using I2C1_Initialize() before invoking this function.
Variables
const i2c_host_interface_t I2C1_Host
Represents an instance of the portable interface structure designed for I2C1 host.
static void(* I2C1_Callback )(void)
volatile i2c_host_event_status_t i2c1Status = {0}
Detailed Description
This file contains the API implementation for the I2C1 driver.
A source file generated by I2C1 I2C host driver.
Function Documentation
I2C1_BusReset()
inline static void I2C1_BusReset (void )
I2C1_Close()
static void I2C1_Close (void )[static]
I2C1_ReadStart()
static void I2C1_ReadStart (void )[static]
@misradeviation {Advisory:,8.7} Some Melody-generated driver APIs are made available to users through external linkage. Users have the option to add these APIs in the application.This rule ID is disabled at project level due to its multiple occurrences in several files.Therefore, in the application project, this rule ID must be disabled in the MPLAB-X IDE from Tools -> Options -> Embedded -> MISRA Check.
I2C1_WriteStart()
static void I2C1_WriteStart (void )[static]
Variable Documentation
I2C1_Callback
void(* I2C1_Callback) (void)[static]
I2C1_Host
const i2c_host_interface_t I2C1_Host
Initial value:
= { .Initialize = I2C1_Initialize, .Deinitialize = I2C1_Deinitialize, .Write = I2C1_Write, .Read = I2C1_Read, .WriteRead = I2C1_WriteRead, .TransferSetup = NULL, .ErrorGet = I2C1_ErrorGet, .IsBusy = I2C1_IsBusy, .CallbackRegister = I2C1_CallbackRegister, .Tasks = I2C1_Tasks }
Represents an instance of the portable interface structure designed for I2C1 host.
i2c1Status
volatile i2c_host_event_status_t i2c1Status = {0}
4.15.2.7.13 source/interrupt/i2c_host/i2c_host_event_types.h File Reference
This header file contains helper structures for the implementation of the I2C host driver.
#include "i2c_host_types.h"
Data structures
struct i2c_host_event_status_t
Structure that defines the communication parameters for an I2C host.
Variables
volatile i2c_host_event_status_t i2c1Status
Detailed Description
This header file contains helper structures for the implementation of the I2C host driver.
A header file generated by I2C host driver.
Variable Documentation
i2c1Status
volatile i2c_host_event_status_t i2c1Status
4.15.2.7.14 source/polling/i2c_host/i2c_host_event_types.h File Reference
This header file contains helper structures for the implementation of the I2C host driver.
#include "i2c_host_types.h"
Data structures
struct i2c_host_event_status_t
Structure that defines the communication parameters for an I2C host.
Variables
volatile i2c_host_event_status_t i2c1Status
Detailed Description
This header file contains helper structures for the implementation of the I2C host driver.
A header file generated by I2C host driver.
Variable Documentation
i2c1Status
volatile i2c_host_event_status_t i2c1Status
4.15.2.7.15 source/interrupt/i2c_host/i2c_host_interface.h File Reference
#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include "i2c_host_types.h"
Data structures
struct i2c_host_interface_t
This structure contains the portable interfaces for I2C host.
Detailed Description
A header file generated by I2C host driver
4.15.2.7.16 source/polling/i2c_host/i2c_host_interface.h File Reference
#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include "i2c_host_types.h"
Data structures
struct i2c_host_interface_t
This structure contains the portable interfaces for I2C host.
Detailed Description
A header file generated by I2C host driver
4.15.2.7.17 source/interrupt/i2c_host/i2c_host_types.h File Reference
This header file provides helper structures for the implementation of the I2C host driver.
Data structures
struct i2c_transfer_setup
Typedefs
typedef struct i2c_transfer_setup i2c_host_transfer_setup_t
Enumerations
enum i2c_host_error_t { I2C_ERROR_NONE, I2C_ERROR_ADDR_NACK, I2C_ERROR_DATA_NACK, I2C_ERROR_BUS_COLLISION}
Enumeration for the possible errors in the I2C host driver.
Detailed Description
This header file provides helper structures for the implementation of the I2C host driver.
Types Header File generated by I2C host driver
Typedef Documentation
i2c_host_transfer_setup_t
typedef struct i2c_transfer_setup i2c_host_transfer_setup_t
@misradeviation{Advisory:,2.4,Advisory:,2.3} These declarations are provided by the Melody-generated drivers for the user’s application. It is up to the user if these declarations will be implemented in their application.
4.15.2.7.18 source/polling/i2c_host/i2c_host_types.h File Reference
This header file provides helper structures for the implementation of the I2C host driver.
Data structures
struct i2c_transfer_setup
Typedefs
typedef struct i2c_transfer_setup i2c_host_transfer_setup_t
Enumerations
Detailed Description
This header file provides helper structures for the implementation of the I2C host driver.
Types Header File generated by I2C host driver
Typedef Documentation
i2c_host_transfer_setup_t
typedef struct i2c_transfer_setup i2c_host_transfer_setup_t
@misradeviation{Advisory:,2.4,Advisory:,2.3} These declarations are provided by the Melody-generated drivers for the user’s application. It is up to the user if these declarations will be implemented in their application.
Enumeration Type Documentation
i2c_host_error_t
enum i2c_host_error_t
I2C_ERROR_NONE | Indicates no error |
I2C_ERROR_ADDR_NACK | Indicates that the I2C client did not acknowledge the address |
I2C_ERROR_DATA_NACK | Indicates that the I2C client did not acknowledge the data |
I2C_ERROR_BUS_COLLISION | Indicates an error caused due to bus collision |