Using the I2C Bus to Access a Connected EEPROM
This example shows how to use the I2C blocks to access an EEPROM connected to the chip using the I2C bus.
Required Hardware:
- Spectrum Digital F2808/F28335 eZdsp board
Note: Any C2000 (except c281x) controlSTICK or ControlCARD with Docking Station board is not equipped with I2C EEPROM. You must add I2C EEPROM to this board to run the example.
Available versions of this example:
- All c28x Processors: c28x_i2ctest.mdl
Contents
Model
The following figure shows the example model.
Description
This example shows how to access the EEPROM connected to the I2C bus at I2C slave address 0x50 on an F2808/F28335 eZdsp board.
This program writes 4 bytes to EEPROM and reads back the data from the corresponding EEPROM address to show successful communication.
The I2C Transmit block in the "EEPROM Write" subsystem writes the free-running counter data from the "EEPROM Data" subsystem to the address specified by "EEPROM Memory Addr" subsystem.
When an I2C interrupt is detected, "I2C SYS INTR" subsystem function is executed. As a result, the I2C Receive block reads the EEPROM data in "I2C SYS INTR:ARDY Subsystem:Subsystem". The global array "EEPROM_DATA" contains the received data. You can monitor the value of this array in Code Composer Studio™ Watch Window.
How to Run the Example
The following sections explain how to configure, build, and deploy the executable.
With Code Composer Studio v3.3 (CCSv3.3) - Default
- Open this model c28x_i2ctest.mdl.
- The model is configured for a default processor F28335. Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources" dialog to select a different processor.
- Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources" dialog. In the "Peripherals" tab, select I2C, and check Enable system interrupt.
- Once editable, check Enable SCD Interrupt and Enable ARDY interrupt.
- Click OK.
- Click Build Model on the Simulink® toolbar or press Ctrl+B to generate, build, load and run the program.
With Code Composer Studio v4 (CCSv4)
CCSv4 support is provided via a makefile based approach. This requires running xmakefilesetup to set the environment. You can ignore the following if you have already gone through these steps. For more information, please refer to the Xmakefile Documentation
- Run XMakefile User Configuration.
- Set the Template parameter to gmake.
- Uncheck the Display operational configuration only checkbox.
- Set the Configuration parameter to ticcs_c2000_ccsv4, click Apply, if you haven't used this tool before, a dialog will ask you to browse to your CCSv4 installation folder. Pick the right folder and click OK.
- Click on the Tool Directories and make sure that the paths are pointing to directories matching your installation. For example:
- C:\Program Files\Texas Instruments\ccsv4\ for CCS Installation.
- C:\Program Files\Texas Instruments\ccsv4\tools\compiler\C2000\ for Code Generation Tools.
- C:\Program Files\Texas Instruments\bios_5_41_10_36\ for DSP/BIOS Installation.
Code Generation and Creation of an .out file using CCSv4:
- Open the model c28x_i2ctest.mdl.
- Open the Target Hardware Resources dialog and set the IDE/Tool chain parameter to Texas Instruments Code Composer Studio v4 (makefile generation only).
- In the Peripherals tab, select I2C, and check Enable system interrupt.
- Once editable, check Enable SCD Interrupt and Enable ARDY interrupt.
- Click OK.
- Click Build Model on the Simulink® toolbar or press Ctrl+B to generate and build an .out executable file.
- Open CCSv4 and connect to the Hardware. Load the program on to the Hardware using CCSv4 and run.
With Code Composer Studio v5 (CCSv5)
CCSv5 support is provided via a makefile based approach. This requires running xmakefilesetup to set the environment. You can ignore the following if you have already gone through these steps. For more information, please refer to the Xmakefile Documentation
- Run XMakefile User Configuration.
- Set the Template parameter to gmake.
- Uncheck the Display operational configuration only checkbox.
- Set the Configuration parameter to ticcs_c2000_ccsv5, click Apply, if you haven't used this tool before, a dialog will ask you to browse to your CCSv5 installation folder. Pick the right folder and click OK.
- Click on the Tool Directories and make sure that the paths are pointing to directories matching your installation. For example:
- C:\ti\ccsv5\ for CCS Installation.
- C:\ti\ccsv5\tools\compiler\c2000\ for Code Generation Tools.
- C:\ti\bios_5_41_11_38\ for DSP/BIOS Installation.
Code Generation and Creation of an .out file using CCSv5:
- Open the model c28x_i2ctest.mdl.
- Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources" dialog. Set the IDE/Tool chain parameter to Texas Instruments Code Composer Studio v5 (makefile generation only).
- Change the selected board and processor to match your hardware.
- In the Peripherals tab, select I2C, and check Enable system interrupt.
- Once editable, check Enable SCD Interrupt and Enable ARDY interrupt.
- Click OK.
- Click Build Model on the Simulink® toolbar or press Ctrl+B to generate and build an .out executable file.
- Open CCSv5 and connect to the Hardware. Load the program on to the Hardware using CCSv5 and run.