hello
i want to implement an image sensor that utilizes an I2C protocal to read/write the registers.
but i wasn't successful !
when i write registers, i see no change in the sensor status. also can't read register values!
i think the sensor doesn't answer the I2C!
i couldn't find any I2C sample code that checks ACK and NACK response.
can anyone help me to write a code to realize ACK from sensor?
this is my code:
Code:
// PIOA-pin setup:
AT91F_TWI_CfgPIO();
// clk enable:
AT91F_TWI_CfgPMC();
// TWI setup:
AT91F_TWI_Configure(AT91C_BASE_TWI); // Reset peripheral(SWRST) // Set Master mode(MSEN)
// set TWI clk:
*AT91C_TWI_CWGR = (1<<16)|(45<<8)|(45);
*AT91C_TWI_MMR = 0x210100;
*AT91C_TWI_IADR = 0x11; //internal address
*AT91C_TWI_CR = AT91C_TWI_START | AT91C_TWI_STOP | AT91C_TWI_MSEN;
*AT91C_TWI_THR = 0xc0;
status = *AT91C_TWI_SR;
while(status & AT91C_TWI_NACK)
status = *AT91C_TWI_SR;
status = *AT91C_TWI_SR;
while(!(status & AT91C_TWI_TXCOMP))
status = *AT91C_TWI_SR;
i expect to have an infinite loop if the sensor doesn't ACK.
Code:
status = *AT91C_TWI_SR;
while(status & AT91C_TWI_NACK)
status = *AT91C_TWI_SR;
but doesn't! even if i change the slave address !!
please help me
thanks