SPRADD0 December 2023
Figure 1-1 demonstrates how to transfer data or commands from a UART interface to several target I2C peripherals using the MSPM0 as an I2C controller. Incoming UART packets are specifically formatted to facilitate the transition to I2C communication. Figure 1-1 can communicate errors in communication back to the host device. Code for this example is found at UART to I2C Bridge Sub-System Code.
Applying this application requires a UART and I2C peripheral.
Sub-Block Functionality | Peripheral Use | Notes |
---|---|---|
UART TX/RX Interface | UART | Called UART_Bridge_INST in code. Default 9600 baud rate. |
I2C Controller | I2C | Called I2C_Bridge_INST in code. Default 100 kHz transmission rate. |
Compatible devices are listed in Table 1-2 with corresponding EVMs based on the requirements in Table 1-1. Using other MSPM0 devices and corresponding EVMs is possible if the requirements in Table 1-1 are met.
Compatible Devices | EVM |
---|---|
MSPM0Lxxxx | LP-MSPM0L1306 |
MSPM0Gxxxx | LP-MSPM0G3507 |
Figure 1-2, Figure 1-3, and Figure 1-4 show the code flow diagrams for Main UART Bridge functionality, Main() plus UART ISR, and I2C ISR, respectively, for Figure 1-1.
Figure 1-5 shows the required UART packet for proper bridging to the I2C interface. The values shown are the default header values defined within Figure 1-1.
Figure 1-1 application uses the TI System Configuration Tool (SysConfig) graphical interface to generate the configuration code of the device peripherals. Using a graphical interface to configure the device peripherals streamlines the application prototyping process.
To change the specific values used by the UART Packet or the max I2C packet size, modify the #defines in the beginning of the document, as demonstrated in the following code block:
/* Define UART Header and Start Byte*/
#define UART_HEADER_LENGTH 0x03
#define UART_START_BYTE 0xF8
#define UART_READ_I2C_BYTE 0xFA
#define UART_WRITE_I2C_BYTE 0xFB
#define ADDRESS_INDEX 0x00
#define RW_INDEX 0x01
#define LENGTH_INDEX 0x02
/*Define max packet sizes*/
#define I2C_MAX_PACKET_SIZE 16
#define UART_MAX_PACKET_SIZE (I2C_MAX_PACKET_SIZE + UART_HEADER_LENGTH)
Several points in the code are comments around error detection. A user can add custom error handling and additional error reporting at these points in the code. For brevity, not all error handling code intersections are included here. In practice, search for comments in the code similar to what is demonstrated in the following code block:
while (DL_I2C_isControllerRXFIFOEmpty(I2C_BRIDGE_INST) != true) {
if (gI2C_Count < gI2C_Length) {
gI2C_Data[gI2C_Count++] =
DL_I2C_receiveControllerData(I2C_BRIDGE_INST);
} else {
/*
* Ignore and remove from FIFO if the buffer is full
* Optionally add error flag update
*/
DL_I2C_receiveControllerData(I2C_BRIDGE_INST);
gError = ERROR_I2C_OVERUN;
}
}