This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC1768 + AT24C08 - Timeout problem

Hello, I am using a AT24C08 for store some datas and I'm having trouble. I am using code sample for I2C. The data is being written and read perfectly, but the function I2CStart() return always "timeout". This "problem" causes a delay in my routines of W/R. I believe it is necessary some modification in I2C0_IRQHandler() function. Someone could review my code?

I implemented a matricial keypad for tests of write and read.

Parents
  • main.c

    int main (void)
    {
            char temp[16];
            unsigned char c = 0;
            unsigned int i = 0;
    
            SystemInit();
            SysTick_Config(SystemFrequency/100);  /* Generate interrupt each 10 ms      */
    
            if ( I2CInit( (uint32_t)I2CMASTER ) == FALSE )  /* initialize I2c */
            {
                    while ( 1 );                            /* Fatal error */
            }
    
            /* Initialize RTC with RTCCAL and RTCDIR values */
            InitRTC();
            /* start RTC */
            StartRTC();
    
            init_KEYPAD();
            lcd_clear();
    
            while(1)
            {
                    c = get_KEYPAD();
                    if(c == '1')
                    {
                            for ( i = 0; i < BUFSIZE; i++ )      /* clear buffer */
                            {
                                    I2CMasterBuffer[i] = 0;
                            }
    
                            I2CWriteLength = 5;
                            I2CReadLength = 0;
                            I2CMasterBuffer[0] = AT24C08_ADDR;
                            I2CMasterBuffer[1] = 0x00;              /* address offset for user seq. */
    
                            I2CMasterBuffer[2] = LPC_RTC->HOUR;
                            I2CMasterBuffer[3] = LPC_RTC->MIN;
                            I2CMasterBuffer[4] = LPC_RTC->SEC;
                            I2CEngine();
                    }
                    if(c == '2')
                    {
                            for ( i = 0; i < BUFSIZE; i++ )
                            {
                                    I2CSlaveBuffer[i] = 0x00;
                            }
                            /* Write SLA(W), address, SLA(R), and read one byte back. */
                            I2CWriteLength = 2;
                            I2CReadLength = 20;
                            I2CMasterBuffer[0] = AT24C08_ADDR;
                            I2CMasterBuffer[1] = 0x00;              /* address */
                            I2CMasterBuffer[2] = AT24C08_ADDR | RD_BIT;
                            I2CEngine();
    
                    }
                    lcd_gotoxy(0,0);
                    sprintf(temp,"%d:%d:%d",I2CSlaveBuffer[0],I2CSlaveBuffer[1],I2CSlaveBuffer[2]);
                    lcd_print(temp);
            }
    
            return 0;
    

Reply
  • main.c

    int main (void)
    {
            char temp[16];
            unsigned char c = 0;
            unsigned int i = 0;
    
            SystemInit();
            SysTick_Config(SystemFrequency/100);  /* Generate interrupt each 10 ms      */
    
            if ( I2CInit( (uint32_t)I2CMASTER ) == FALSE )  /* initialize I2c */
            {
                    while ( 1 );                            /* Fatal error */
            }
    
            /* Initialize RTC with RTCCAL and RTCDIR values */
            InitRTC();
            /* start RTC */
            StartRTC();
    
            init_KEYPAD();
            lcd_clear();
    
            while(1)
            {
                    c = get_KEYPAD();
                    if(c == '1')
                    {
                            for ( i = 0; i < BUFSIZE; i++ )      /* clear buffer */
                            {
                                    I2CMasterBuffer[i] = 0;
                            }
    
                            I2CWriteLength = 5;
                            I2CReadLength = 0;
                            I2CMasterBuffer[0] = AT24C08_ADDR;
                            I2CMasterBuffer[1] = 0x00;              /* address offset for user seq. */
    
                            I2CMasterBuffer[2] = LPC_RTC->HOUR;
                            I2CMasterBuffer[3] = LPC_RTC->MIN;
                            I2CMasterBuffer[4] = LPC_RTC->SEC;
                            I2CEngine();
                    }
                    if(c == '2')
                    {
                            for ( i = 0; i < BUFSIZE; i++ )
                            {
                                    I2CSlaveBuffer[i] = 0x00;
                            }
                            /* Write SLA(W), address, SLA(R), and read one byte back. */
                            I2CWriteLength = 2;
                            I2CReadLength = 20;
                            I2CMasterBuffer[0] = AT24C08_ADDR;
                            I2CMasterBuffer[1] = 0x00;              /* address */
                            I2CMasterBuffer[2] = AT24C08_ADDR | RD_BIT;
                            I2CEngine();
    
                    }
                    lcd_gotoxy(0,0);
                    sprintf(temp,"%d:%d:%d",I2CSlaveBuffer[0],I2CSlaveBuffer[1],I2CSlaveBuffer[2]);
                    lcd_print(temp);
            }
    
            return 0;
    

Children