I2C function using version 2.5.2

Discussion to talk about software related topics only.
Post Reply
bstark
Posts: 10
Joined: Thu Jun 26, 2008 10:36 am

I2C function using version 2.5.2

Post by bstark »

I wrote some generic functions for reading and writing the I2C bus that seem to have broken from the previous release of the NNDK release and release 2.5.2. Has anyone else had such an experience? The source for the read function is below:

int I2CGenericRead(BYTE address,BYTE offset,BYTE length,BYTE *data)
{
BYTE buffer[I2C_MAX_BUF_SIZE];
BYTE I2CStat;

*buffer = offset;

if((I2CStat = I2CSendBuf(address, buffer, 1)) == I2C_OK)
I2CStat = ( I2CReadBuf(address, data,length));

if( I2CStat != I2C_OK )
{
iprintf("Generic Failed to read due to error: %d\r\n", I2CStat);
return(0);
}
return(1);
}

The function above always returns 0, I think I2CStat is getting set to 9, but I will have to verify this today. The wierd thing is I have another function I use in more specific situations that works. The source to that is below:

char ReadFanController(BYTE address,BYTE *buffer,BYTE offset,BYTE length)
{
BYTE I2CStat;
if((I2CStat = I2CSendBuf(address,&offset, 1)) == I2C_OK);
I2CStat = ( I2CReadBuf(address, buffer, length));
if( I2CStat != I2C_OK )
{
iprintf("Failed to read address %x due to error: %d\r\n",address, I2CStat);
return 0;
}

return buffer[0];
}

I can't figure out what the difference is that could cause the problem.
Post Reply