We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hii, I am Working on LPC2368 I2C ,I am facing problem in Start Condition i.e,after setting Start Condition bit ,it is not switching to Interrupt Handler,I am first time writing code for I2c ,Is there any other thing to do in that.
Code :
int main (void) { DWORD i;
if ( I2CInit( (DWORD)I2CMASTER ) == FALSE ) /* initialize I2c */ { while ( 1 ); /* Fatal error */ }
I2Cstart(); }
DWORD I2CInit( DWORD I2cMode ) { PCONP |= (1 << 19); PINSEL1 &= ~0x03C00000; PINSEL1 |= 0x01400000; /* set PIO0.27 and PIO0.28 to I2C0 SDA and SCK */ /* function to 01 on both SDA and SCK. */ /*--- Clear flags ---*/ I20CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC | I2CONCLR_I2ENC;
/*--- Reset registers ---*/ I20SCLL = I2SCLL_SCLL; I20SCLH = I2SCLH_SCLH;
/* Install interrupt handler */ if (install_irq( I2C0_INT, (void *)I2C0MasterHandler, HIGHEST_PRIORITY ) == FALSE ) { return( FALSE ); } I20CONSET = I2CONSET_I2EN; //I2C interface is enabled. return( TRUE ); }
DWORD I2CStart( void ) { DWORD timeout = 0; DWORD retVal = FALSE;
/*--- Issue a start condition ---*/ I20CONSET = I2CONSET_STA; /* Set Start flag */
/*--- Wait until START transmitted ---*/ while( 1 ) { if ( I2CMasterState == I2C_STARTED ) { retVal = TRUE; break; } if ( timeout >= MAX_TIMEOUT ) { retVal = FALSE; break; } timeout++; } return( retVal ); }
www.danlhenry.com/.../keil_code.png