I have a Serial EEPROM that wants me to issue a faux write before doing a read. So in order to do a Random Read(of any address) I have to issue a START-Write Control Byte-Word Address-Start-Read Control Byte-Data-Stop.
Does anybody know how to accomplish this using the IAR IDE with an at91sam7s as the target?
thanks
james
dont have time right now to explain it & its not IAR compatable. but it should give you an idea how to do what your asking.
//*********************************************************************
//*********************** HANDLE ERROR ********************************
//*********************************************************************
int Read_PCA9555(unsigned int address)
{
int status;
unsigned int port_data;
unsigned char p[2];
char x=0;
unsigned int error=0;
if(!twi_error)
{
TWI_IADR = 0x00; // Read Command
TWI_MMR = (address << TWI_MMR_DADR_BIT) |
(0x01 << TWI_MMR_MREAD_BIT) |
(0x01 << TWI_MMR_IADRSZ_BIT);
TWI_CR = TWI_CR_START | TWI_CR_MSEN;
do
{
status = TWI_SR;
if(status & TWI_SR_RXRDY)
{
p = TWI_RHR;
if(++x==1)
{
TWI_STOP();
}
}
if(error++ > TWI_TIMEOUT)
{
printf(“Set TWI Error\r\n”);
twi_error=1;
return 0;
}
}while(!(status & TWI_SR_TXCOMP));
port_data = p[1];
port_data <<= 8;
port_data +=p[0];
return port_data;
}
else
{
return 0;
}
}
Not to belabour the point but I don’t see how this code snippet sends the “partial” Write Command before the Read command.
The reason for the need for this is the SErial EEPROM has an internal address register. So to do a “random” read of any address, you need to set the address register (with the partial Write Command) prior to issuing a read.
I am just trying to understand all this. By trade I am a Windows programmer but I always get sucked into these embedded projects.