This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/LAUNCHXL-F28377S: I2C EEPROM Code is not working.

Part Number: LAUNCHXL-F28377S

Tool/software: Code Composer Studio

Hi, 

I am using now F28377S launchpad, i connected to 24C16A eeprom launchpad's i2c communication pins and i did also pull up to 3.3V level each of communication pins.

But i cannot writing any byte to eeprom, is anyone can help me? I2C code is below;

//###########################################################################
// FILE: Example_2837xSI2c_eeprom.c
// TITLE: I2C EEPROM Example
//
//! \addtogroup cpu01_example_list
//! <h1>I2C EEPROM Example (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.
//!
//! \b External \b Connections \n
//! - This program requires an external I2C EEPROM connected to
//! the I2C bus at address 0x50.
//
//###########################################################################
// $TI Release: F2837xS Support Library v180 $
// $Release Date: Fri Nov 6 16:27:58 CST 2015 $
// $Copyright: Copyright (C) 2014-2015 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################

#include "F28x_Project.h" // Device Headerfile and Examples Include File

// Note: I2C Macros used in this example can be found in the
// F2837xS_I2C_defines.h file

// Prototype statements for functions found within this file.
void I2CA_Init(void);

Uint16 ReadEEPROM(Uint16 eepromAdress);
void WriteEEPROM(Uint16 eepromAdress, Uint16 data);

Uint16 DataRead[256];

Uint16 EEPROM_MODE;
enum EEPROM_MODES {WRITE, READ};

//__interrupt void i2c_int1a_isr(void);
void pass(void);
void fail(void);

#define I2C_SLAVE_ADDR 0x00
#define I2C_NUMBYTES 2

// Global variables
// Two bytes will be used for the outgoing address,
// thus only setup 14 bytes maximum

Uint16 PassCount;
Uint16 FailCount;

void main(void)
{
// Uint16 Error;
// Uint16 i;

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
InitSysCtrl();

// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitGpio();

// For this example, only init the pins for the SCI-A port.
// These functions are found in the F2837xS_Gpio.c file.
GPIO_SetupPinMux(42, GPIO_MUX_CPU1, 6);
GPIO_SetupPinMux(43, GPIO_MUX_CPU1, 6);

// 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 F2837xS_PieCtrl.c file.
InitPieCtrl();

// Disable CPU __interrupts and clear all CPU __interrupt flags:
IER = 0x0000;
IFR = 0x0000;

// 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 F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
//PieVectTable.I2CA_INT = &i2c_int1a_isr;
EDIS; // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize the Device Peripherals:
I2CA_Init();

// Step 5. User specific code

// Clear Counters
PassCount = 0;
FailCount = 0;

// Enable __interrupts required for this example

// Enable I2C __interrupt 1 in the PIE: Group 8 __interrupt 1
//PieCtrlRegs.PIEIER8.bit.INTx1 = 1;

// Enable CPU INT8 which is connected to PIE group 8
IER |= M_INT8;
EINT;

unsigned int j = 0;
EEPROM_MODE = WRITE;

// Application loop
for(;;)
{
if (EEPROM_MODE == WRITE)
{
WriteEEPROM(j, 10+j);
WriteEEPROM(j+1, 10+j+1);

j=j+2;

if (j>=200) {
j = 0;
EEPROM_MODE = READ;
DELAY_US(1e6); // Wait for 1sec to READ mode
}
}

if (EEPROM_MODE == READ)
{
DataRead[j] = ReadEEPROM(j);
DataRead[j+1] = ReadEEPROM(j+1) ;

j=j+2;

if (j>=200)
j = 0;
pass();
}
} // end of for(;;)
} // end of main

void I2CA_Init(void)
{
I2caRegs.I2CMDR.all = 0X0000;
// Initialize I2C
I2caRegs.I2CSAR.all = I2C_SLAVE_ADDR; // Slave address - EEPROM control code

I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk
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; //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 eepromAddress)
{
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 = eepromAddress>>8;
addresslow = eepromAddress;
I2caRegs.I2CSAR.all = I2C_SLAVE_ADDR; //0x0050;

while (I2caRegs.I2CSTR.bit.BB == 1);
I2caRegs.I2CMDR.all = 0x2620; // start, no stop bit, master, tx, reset I2C
I2caRegs.I2CCNT = 0x0002;
I2caRegs.I2CDXR.all = addresshigh;
I2caRegs.I2CDXR.all = 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.all;

DELAY_US(100);

return(tempdata);
}


void WriteEEPROM(Uint16 eepromAdress, Uint16 data)
{
Uint16 addresslow;
Uint16 addresshigh;

I2caRegs.I2CMDR.bit.IRS = 1; // reset I2C

addresshigh = (eepromAdress>>8)&0x00FF;
addresslow = eepromAdress&0x00FF;
I2caRegs.I2CSAR.all = I2C_SLAVE_ADDR; //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.all = addresshigh;
I2caRegs.I2CDXR.all = addresslow;
// I2caRegs.I2CDXR = (data >> 8) & 0x00FF; // high byte data
I2caRegs.I2CDXR.all = 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;
}


void pass()
{
asm(" ESTOP0");
for(;;);
}

void fail()
{
asm(" ESTOP0");
for(;;);
}

//===========================================================================
// No more.
//===========================================================================

for this code, in WriteEEPROM() function routine hanging up this while loop ;