Part Number: PCA9539
Other Parts Discussed in Thread: MSP430F4784,
Hi,
I'm trying use additional GPIOs for my board ( MSP430F4784), So I'm using PCA9539 I/O expander 16 bit.
As per the datasheet I programmed using I2C.
I'm using 0x74 as slave address as I grounded A0 and A1.
I'm able to read and write data in PCA9539 on step by step debugging.
For interrupt pin I used controller's interrupt pin. But when I run the below program after POR the interrupt pin is not getting high and I'm not even changing pin state in I/O expander.
also interrupt is not happening even though the pin in low condition.
Can you provide any example for PCA9539 other than arduino example. Like MSP430 series.
Or please provide me procedure to work on PCA9539.
void i2c_beginTx(uint8_t address)
{
UCB1I2CSA = address;
UCB1CTL1 |= UCTR + UCTXSTT;
while((UCB1STAT & UCNACKIFG));
}
void i2c_write(uint8_t byte)
{
__delay_cycles(500);
UCB1TXBUF = byte;
while((UCB1STAT & UCNACKIFG));
}
void i2c_read(uint8_t address, uint8_t reg, uint8_t len)
{
int i;
UCB1I2CSA = address;
UCB1CTL1 |= UCTR + UCTXSTT;
while((UCB1STAT & UCNACKIFG));
UCB1TXBUF = reg;
__delay_cycles(500);
UCB1CTL1 |= UCTXSTP;
UCB1I2CSA = address;
UCB1CTL1 &= ~UCTR;
UCB1CTL1 |= UCTXSTT;
while((UCB1STAT & UCNACKIFG));
for(i=0;i<len;i++)
{
data[i] = UCB1RXBUF;
__delay_cycles(500);
}
UCB1CTL1 |= UCTXNACK;
UCB1CTL1 |= UCTXSTP;
}
void read(uint8_t address, uint8_t len)
{
UCB1I2CSA = address;
UCB1CTL1 &= ~UCTR;
UCB1CTL1 |= UCTXSTT;
while((UCB1STAT & UCNACKIFG));
for(i=0;i<len;i++)
{
//delay_in_sec(1);
data[i] = UCB1RXBUF;
__delay_cycles(500);
}
UCB1CTL1 |= UCTXNACK;
UCB1CTL1 |= UCTXSTP;
}
void i2c_stop()
{
UCB1CTL1 |= UCTXSTP;
}
int main()
{
WDTCTL = WDTPW | WDTHOLD;
P4SEL |= BIT3 + BIT4; // i2c pins
/** interrupt pin **/
P1DIR &= ~BIT7;
P1IE |= BIT7;
P1IES |= BIT7;
P9DIR |= BIT5; //LED blink
UCB1CTL1 |= UCSWRST;
UCB1CTL0 |= UCMST + UCMODE_3 + UCSYNC;
UCB1CTL1 |= UCSSEL_2 + UCSWRST;
UCB1BR0 = 11;
UCB1BR1 = 0;
UCB1CTL1 &= ~UCSWRST;
__delay_cycles(100);
i2c_beginTx(0x74);
i2c_write(0x06);
i2c_write(0xFF);
i2c_write(0xFF);
i2c_stop();
while(1)
{
i2c_read(0x74, 0x01, 2);
}
}
#pragma vector=PORT1_VECTOR
__interrupt void port_1_ISR(void)
{
if(P1IFG & BIT7)
{
read(0x74, 2);
if((data[0] & 0) == 0)
{
P9OUT |= BIT5;
__delay_cycles(1000000);
P9OUT &= ~BIT5;
__delay_cycles(1000000);
}
P1IFG &= ~BIT7;
}
}