lpc1114 problem with e2prom

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lpc1114 problem with e2prom

594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tswong on Mon Jun 29 04:47:16 MST 2015
I am connecting lpc1114 with eprom 24aa16. My code run perfectly when run line by line, but it encounter hard fault when I just run the program. I am using a switch for different states and a recursion at the end for next state.

    switch (stat){
           
    //Master Transmit State
        case 0x08://start condition has been transmitted
            LPC_I2C->DAT = con_byte;
            LPC_I2C->CONSET = I2C_CON_AA;
            LPC_I2C->CONCLR = I2C_CON_SI | I2C_CON_STA | I2C_CON_STO;
            while(LPC_I2C->STAT == stat);
            break;
        case 0x18://slave + W has been transmitted, ACK has been received
            LPC_I2C->DAT = word_addr;
            LPC_I2C->CONSET = I2C_CON_AA;
            LPC_I2C->CONCLR = I2C_CON_SI;
            while(LPC_I2C->STAT == stat);
            break;
        case 0x28://DATA has been transmitted, ACK has been received
            while(byteCnt != 0){
                    LPC_I2C->DAT = *data;
                    LPC_I2C->CONSET = I2C_CON_AA;
                    LPC_I2C->CONCLR = I2C_CON_SI;
                    data++;
                    byteCnt--;
            }
            LPC_I2C->CONSET = I2C_CON_STO | I2C_CON_AA;
                LPC_I2C->CONCLR = I2C_CON_SI;
    }
    if(case){
    e2promStateHandlerNew(rwCtl, con_byte, word_addr, data, byteCnt);
    }

Can anyone figure out the problem?
Labels (1)
0 Kudos
5 Replies

566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Jun 29 23:42:39 MST 2015
Look at your stack pointer (SP). It has an invalid value. So, you have stack coruption, or you have overflowed the stack. As you said you use recursion, you need to look at your algorithm to start with.
0 Kudos

566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tswong on Mon Jun 29 19:17:30 MST 2015
The hard fault information is like this:

Fault PC   = 0x00000228
           = e2promStateHandlerNew in section .text
           = File: ../example/src/e2promHandler.c  Line: 34

Fault status registers:
IPSR       = 0x1000003: 3  (HardFault)
CFSR       = 00000000 (Configurable Fault Status Register)
HFSR       = 00000000 (Hard Fault Status Register)
DFSR       = 00000000 (Debug Fault Status Register)
MMAR       = 00000000 [INVALID] (MemManage Fault Address Register)
BFAR       = 00000000 [INVALID] (Bus Fault Address Register)
AFSR       = 00000000 (Auxiliary Fault Status Register)

Stacked registers:
R0         = 00000000
R1         = 00000000
R2         = 00000000
R3         = 00000000
R12        = 00000000
LR         = 00000000
PC         = 00000228
PSR        = 01000000
SP         = 0fffffe8

if faults register is n/a, does it means there is overwrite?
0 Kudos

566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tswong on Mon Jun 29 18:15:49 MST 2015
It's maximum of 5ms after the STO
0 Kudos

566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 1234567890 on Mon Jun 29 12:07:23 MST 2015

Quote: tswong
My code run perfectly when run line by line, but it encounter hard fault when I just run the program.
        case 0x28://DATA has been transmitted, ACK has been received
            while(byteCnt != 0){
                    LPC_I2C->DAT = *data;
                    LPC_I2C->CONSET = I2C_CON_AA;
                    LPC_I2C->CONCLR = I2C_CON_SI;
                    data++;
                    byteCnt--;
            }



What does EEPROM datasheet say about write cycle time???? :quest:
0 Kudos

566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Jun 29 06:15:50 MST 2015
How do you expect anybody to help you debug an incomplete code snippet?

Try debugging the hard fault yourself:
http://www.lpcware.com/content/faq/lpcxpresso/debugging-hard-fault

If you are using recursion, my guess is that you are exceeding the stack and overwriting your own data.
0 Kudos