Page 1 of 1

PCA9536 I2C i/o expander

Posted: Wed Aug 03, 2011 4:11 pm
by joepasquariello
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();
}

Re: PCA9536 I2C i/o expander

Posted: Thu Aug 04, 2011 11:48 am
by joepasquariello
I was able to get the driver for PCA9536 working by using what NB calls the simple I2C functions rather than the advanced ones. I don't know what I was doing wrong with the advanced functions, which seem pretty straightforward, but I guess that's why they provide the simple ones. Thanks, NB. Note that I2CInit() must be called before calling any other I2C function.

Joe

Re: PCA9536 I2C i/o expander

Posted: Thu Aug 04, 2011 12:00 pm
by joepasquariello
One note about using NB's standard RTC with the SB70LC. Our board has both the PCA9536 i/o expander and also the NB standard PCF8563 real-time clock. For some reason, the RTC module is not included in the SB70LC library. I simply copied system/rtc.cpp and include/rtc.h from the MOD5270 folder to my project folder, added #include <rtc.h> in main.cpp, and it builds and runs fine.

Joe