Hi there, thanks for the info from my previous posing. It helped a lot!
Now, I like to use the Microchip MCP 3021 (A/D converter) on my I2C bus. I can see the address of the chip, I can partially communicate with the chip but, get a time-out (Erorcode #4) and the same data back 2x 0x02.
The data sheet says, the master has to send an Ackn to the slave to get the next data set, how do I do that?
Thank's alot.
Josh
Here is my code:
// ------------------------- READ FROM MCP 3021 ------------------------------//
// Reads data from the A/D converter MCP3021
// Address = base address of chip 0x4D
int AD_Read_3021(BYTE Address)
{
BYTE Read_buffer[4]; // a little big larger - just in case
int i2cStatus;
I2CInit(0x16); // just in case re-init
i2cStatus = I2CStart( Address, 1 ); // read from address
if(i2cStatus > 4) // >4 = error
{
iprintf( "Bad I2CStatus after start conversation : %x\r\n", i2cStatus );
}
i2cStatus = I2CReadBuf(Address,Read_buffer,2);
iprintf( "Bad I2CStatus after reading data back : %x\r\n", i2cStatus );
iprintf( "Read Data A/D hex: %x ", Read_buffer[0]);
iprintf( "Read Data A/D hex: %x ", Read_buffer[1]);
// iprintf( "Read Data A/D hex: %x\r\n ", Read_buffer[2]);
I2CStop();
return(i2cStatus);
}
I2C with MCP3021
Re: I2C with MCP3021
i think you're mixing two types of I2C functions (well, at least on the
5270 or 5282 they would be).
if you only want to grab a single sample at a time, your best bet would
be just use the simple one function call with:
i2cStatus = I2CReadBuf(Address,Read_buffer,2);
or if you want to use the advanced functions, then use all 3:
I2CStart, I2CRead, and I2CStop
I2CRead and I2CReadBuf aren't equivalent.
5270 or 5282 they would be).
if you only want to grab a single sample at a time, your best bet would
be just use the simple one function call with:
i2cStatus = I2CReadBuf(Address,Read_buffer,2);
or if you want to use the advanced functions, then use all 3:
I2CStart, I2CRead, and I2CStop
I2CRead and I2CReadBuf aren't equivalent.