lpcware

lpc1114 problem with e2prom

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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?

Outcomes