Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: CONTROLSUITE
Tool/software: Code Composer Studio
I need to use LAUNCHXL-F28069's I²C communication interface (asynch input GPIO32 (SDAA) and asynch input GPIO33 (SCLA)) to read and write my non-volatile parameters from/to 24C04 e²prom. I have used the same connection circuit below for 24C04.
VCC is 3.3V because its datasheet says VCC=1.8V to 5.5V. +3.3V and ground connections are from my launchxl kit. Not from a different source.
I have used the example on the attachment.
But my code is stuck here :
And my I2caRegs.I2CSTR status registers are like that :
I am new about i²c configuration and I think I read the eeprom 1 time but shouldn't I read it continuously? What is wrong with XSMT or SCD bits? Thanks for your attention.
//#############################################################################
//
// File: f2802x_examples_ccsv4/i2c_eeprom/Example_F2802xI2c_eeprom.c
//
// Title: F2802x I2C EEPROM Example
//
// Group: C2000
// Target Device: TMS320F2802x
//
//! \addtogroup example_list
//! <h1>I2C EEPROM</h1>
//!
//! This program will write 1-14 words to EEPROM and read them back.
//! The data written and the EEPROM address written to are contained
//! in the message structure, I2cMsgOut1. The data read back will be
//! contained in the message structure I2cMsgIn1.
//!
//! This program will work with the on-board I2C EEPROM supplied on
//! the F2802x eZdsp or another EEPROM connected to the devices I2C bus
//! with a slave address of 0x50
//
// (C) Copyright 2012, Texas Instruments, Inc.
//#############################################################################
// $TI Release: f2802x Support Library v210 $
// $Release Date: Mon Sep 17 09:13:31 CDT 2012 $
//#############################################################################
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Note: I2C Macros used in this example can be found in the
// DSP2802x_I2C_defines.h file
// Prototype statements for functions found within this file.
void I2CA_Init(void);
Uint16 ReadEeprom(Uint16 e2promaddress);
void WriteEeprom(Uint16 e2promaddress, Uint16 data);
Uint32 DataRead[256];//] = { 0,0,0,0,0,0,0,0,0,0};
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2802x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2802x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Setup only the GP I/O only for I2C functionality
InitI2CGpio(); // using GPIO 32 and 33
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2802x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// If running from flash copy RAM only functions to RAM
#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2802x_DefaultIsr.c.
// This function is found in DSP2802x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2802x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
I2CA_Init();
DELAY_US(100);
// Step 5. User specific code
EINT;
unsigned int j;
j =0;
// Application loop
for(;;)
{
//WriteEeprom(j, 10+j);
//WriteEeprom(j+1, 10+j+1);
DataRead[j] = ReadEeprom(j);
//DataRead[j+1] = (ReadEeprom(j+1) << 8) | DataRead[j] ;
DataRead[j+1] = ReadEeprom(j+1) ;
j=j+2;
if (j>=200)
j = 0;
} // end of for(;;)
} // end of main
void I2CA_Init(void)
{
I2caRegs.I2CMDR.all = 0x0000;
// Initialize I2C
I2caRegs.I2CSAR = 0x0050; // Slave address - EEPROM control code
// I2CCLK = SYSCLK/(I2CPSC+1)
#if (CPU_FRQ_40MHZ||CPU_FRQ_50MHZ)
I2caRegs.I2CPSC.all = 4; // Prescaler - need 7-12 Mhz on module clk
#endif
#if (CPU_FRQ_60MHZ)
I2caRegs.I2CPSC.all = 5; //6 // Prescaler - need 7-12 Mhz on module clk
#endif
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
// I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY interrupts
I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset
// Stop I2C when suspended
I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
return;
}
Uint16 ReadEeprom(Uint16 e2promaddress)
{
Uint16 addresslow;
Uint16 addresshigh;
Uint16 tempdata;
I2caRegs.I2CMDR.bit.IRS = 1; // reset I2C
while (I2caRegs.I2CSTR.bit.BB == 1); // busy loop
I2caRegs.I2CSTR.bit.SCD = 1; // Clear the SCD bit (stop condition bit)
while(I2caRegs.I2CMDR.bit.STP == 1); // stop bit loop
addresshigh = e2promaddress>>8;
addresslow = e2promaddress;
I2caRegs.I2CSAR = 0x0050;
while (I2caRegs.I2CSTR.bit.BB == 1);
I2caRegs.I2CMDR.all = 0x2620; // start, no stop bit, master, tx, reset I2C
I2caRegs.I2CCNT = 0x0002;
I2caRegs.I2CDXR = addresshigh;
I2caRegs.I2CDXR = addresslow;
while(!I2caRegs.I2CSTR.bit.ARDY); // all ready?
I2caRegs.I2CMDR.all = 0x2C20; // start, stop bit when CNT =0, master, rx, reset I2C
I2caRegs.I2CCNT = 1;
if(I2caRegs.I2CSTR.bit.NACK == 1)
{
I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT; // 0x0002
}
I2caRegs.I2CMDR.bit.STP = 1; // stop bit when CNT=0
while(!I2caRegs.I2CSTR.bit.SCD); // stop bit detected?
//tempdata = I2caRegs.I2CDRR << 8; // read data
tempdata = I2caRegs.I2CDRR;
DELAY_US(100);
return(tempdata);
}
void WriteEeprom(Uint16 e2promaddress, Uint16 data)
{
Uint16 addresslow;
Uint16 addresshigh;
I2caRegs.I2CMDR.bit.IRS = 1; // reset I2C
addresshigh = (e2promaddress>>8)&0x00FF;
addresslow = e2promaddress&0x00FF;
I2caRegs.I2CSAR = 0x0050; // EEPROM control bits + address (A0-A2). for 24LC256, 0 1 0 1 0 A0 A1 A2
while (I2caRegs.I2CSTR.bit.BB == 1);
I2caRegs.I2CCNT = 3 ;
I2caRegs.I2CMDR.all = 0x6E20; //start, stop, no rm, reset i2c
I2caRegs.I2CDXR = addresshigh;
I2caRegs.I2CDXR = addresslow;
// I2caRegs.I2CDXR = (data >> 8) & 0x00FF; // high byte data
I2caRegs.I2CDXR = data; // low byte data
I2caRegs.I2CMDR.bit.STP = 1; // stop bit when CNT=0
while(!I2caRegs.I2CSTR.bit.SCD); // stop bit detected?
DELAY_US(5000); // 5ms = write cycle time of 24LC256 - based on datasheet 24LC256
return;
}
//===========================================================================
// No more.
//===========================================================================














