INTRODUCTION
This example demonstrates interfacing with an external I2C EEPROM using the C2000 microcontroller. It writes 1-14 words to the EEPROM and reads them back for verification. The data to be written and the EEPROM address are stored in the i2cMsgOut structure, while the data read back is stored in the i2cMsgIn structure.
External Connections
| Board Type | EEPROM Address | SDA Pin Connection | SCL Pin Connection |
| Control Card | 0x50 | GPIO32/SDAA to SDA pin | GPIO33/SCLA to SCL pin |
| LaunchPad | 0x50 | GPIO35/SDAA to SDA pin | GPIO37/SCLA to SCL pin |
Watch Variables
| Variable Name | Description |
i2cMsgOut | Contains the data to be written to the EEPROM. |
i2cMsgIn | Contains the data read from the EEPROM. |
passCount | Tracks the number of successful data matches. |
failCount | Tracks the number of data mismatches. |
Functions
| Function Name | Description |
initI2C() | Configures the I2C module for communication. |
writeData(struct I2CMsg *msg) | Sends data to the EEPROM. |
readData(struct I2CMsg *msg) | Reads data from the EEPROM. |
i2cAISR() | Interrupt Service Routine for handling I2C events. |
pass() | Called when data written matches data read. |
fail() | Called when data written does not match data read. |
Message Structure
| Field Name | Description |
msgStatus | Indicates the current state of the message. |
targetAddr | The target I2C address. |
numBytes | Number of bytes in the message. |
memoryHighAddr | High byte of the EEPROM memory address. |
memoryLowAddr | Low byte of the EEPROM memory address. |
msgBuffer | Buffer containing the message data. |
Interrupts
| Interrupt Name | Description |
INT_I2CA | Handles I2C events such as stop condition detection and register access readiness. |
Error Codes
| Error Code | Description |
ERROR_BUS_BUSY | Indicates the I2C bus is busy. |
ERROR_STOP_NOT_READY | Indicates the stop condition is not ready. |
SUCCESS | Indicates successful operation. |
- Note
- Ensure proper pull-up resistors are connected to the I2C lines.
Steps to Run the Example
- When using CCS projects to build, import the CCS project for the required combination and build it using the CCS project menu (see CCS Build Project).
- When using makefiles to build, note the required combination and build using make command (see Makefile based Build)
- Establish connections as mentioned in External Connections section.
- Launch a CCS debug session and run the executable, see Build, Load and Run
- Note
- When running in flash configuration, it is recommended to reset and restart after loading the example to remove any stale flags or states.
See Also
I2C