PCA9536 I2C i/o expander
Posted: Wed Aug 03, 2011 4:11 pm
Hello,
I'm working on an application that will use the PCA9536 I2C i/o expander. It seems pretty straightforward, but all of the I2C transactions are timing out. This is the first time I've used the I2C library, so I could be missing something basic. The outline of what I'm doing and the code for reading and writing is shown below. If anyone can comment on what I might be doing wrong, I'd appreciate it. The status value returned by all of the I2C functions is 4 (I2C_TIMEOUT).
Joe
Platform is SB70LC.
Pins[16].function( PIN16_SDA )
Pins[17].function( PIN17_SCL )
7-bit I2C address is 65.
#include <i2cmaster.h>
I2CInit() is called before any other I2C function.
Write to DIRECTION register (3) to set i/o function.
Write to OUTPUT register (1) to set output values.
Read from INPUT register (0) to read input values.
BYTE PCA9536_GetRegister( BYTE regnum )
{
BYTE data = 0;
int status;
status = I2CStart( 65, I2C_START_WRITE );
status = I2CSend( regnum );
status = I2CRestart( 65, I2C_START_READ );
status = I2CRead( &data );
I2CStop();
return data;
}
void PCA9536_SetRegister( BYTE regnum, BYTE data )
{
int status;
status = I2CStart( 65, I2C_START_WRITE );
status = I2CSend( regnum );
status = I2CSend( data );
I2CStop();
}
I'm working on an application that will use the PCA9536 I2C i/o expander. It seems pretty straightforward, but all of the I2C transactions are timing out. This is the first time I've used the I2C library, so I could be missing something basic. The outline of what I'm doing and the code for reading and writing is shown below. If anyone can comment on what I might be doing wrong, I'd appreciate it. The status value returned by all of the I2C functions is 4 (I2C_TIMEOUT).
Joe
Platform is SB70LC.
Pins[16].function( PIN16_SDA )
Pins[17].function( PIN17_SCL )
7-bit I2C address is 65.
#include <i2cmaster.h>
I2CInit() is called before any other I2C function.
Write to DIRECTION register (3) to set i/o function.
Write to OUTPUT register (1) to set output values.
Read from INPUT register (0) to read input values.
BYTE PCA9536_GetRegister( BYTE regnum )
{
BYTE data = 0;
int status;
status = I2CStart( 65, I2C_START_WRITE );
status = I2CSend( regnum );
status = I2CRestart( 65, I2C_START_READ );
status = I2CRead( &data );
I2CStop();
return data;
}
void PCA9536_SetRegister( BYTE regnum, BYTE data )
{
int status;
status = I2CStart( 65, I2C_START_WRITE );
status = I2CSend( regnum );
status = I2CSend( data );
I2CStop();
}