Other Parts Discussed in Thread: MSP430F4784,
Hi,
I'm currently using PCA9539 I/O expander. interfacing with MSP430F4784, using I2C.
when the IC power up (3.3), does INT pin initially low ? even though pull up is connected (10k).
Does INT pin gets High only after reading input register ?.
below is the program .
here whenever I'm reading input register 1 the UCB0RXBUF gives 2 bytes
but in a loop bytes of data[0] & data[1] are swaping continuously.
So that I can't read a particular bit of a byte.
what would be the issue?
please kindly help me with this
uint8_t data[2]; void i2c_beginTx(uint8_t address) { UCB0I2CSA = address; UCB0CTL1 |= UCTR + UCTXSTT; while((UCB0STAT & UCNACKIFG)); } void i2c_write(uint8_t byte) { UCB0TXBUF = byte; while((UCB0STAT & UCNACKIFG)); __delay_cycles(5000); } void i2c_read(uint8_t address, uint8_t reg, uint8_t len) { int i; UCB0I2CSA = address; UCB0CTL1 |= UCTR + UCTXSTT; while((UCB0STAT & UCNACKIFG)); UCB0TXBUF = reg; __delay_cycles(5000); UCB0CTL1 |= UCTXSTP; UCB0I2CSA = address; UCB0CTL1 &= ~UCTR; UCB0CTL1 |= UCTXSTT; while((UCB0STAT & UCNACKIFG)); for(i=0;i<len;i++) { data[i] = UCB0RXBUF; __delay_cycles(5000); } UCB0CTL1 |= UCTXNACK; UCB0CTL1 |= UCTXSTP; } void read(uint8_t address, uint8_t len) { UCB0I2CSA = address; UCB0CTL1 &= ~UCTR; UCB0CTL1 |= UCTXSTT; while((UCB0STAT & UCNACKIFG)); for(i=0;i<len;i++) { data[i] = UCB0RXBUF; __delay_cycles(5000); } UCB0CTL1 |= UCTXNACK; UCB0CTL1 |= UCTXSTP; } void i2c_stop() { UCB0CTL1 |= UCTXSTP; } int main() { WDTCTL = WDTPW | WDTHOLD; SCFQCTL |= SCFQ_4M; SCFI0 |= FN_2; FLL_CTL0 |= DCOPLUS; do { IFG1 &= ~OFIFG; __delay_cycles(5000); }while(IFG1 & OFIFG); P1DIR |= BIT1; P1SEL |= BIT1; P1DIR |= BIT4; P1SEL |= BIT4; P3SEL |= BIT1 + BIT2; // i2c pins basic_tmr(); P9DIR |= BIT5; //LED blink P9OUT &= ~BIT5; P5DIR |= BIT5; // led P5OUT &= ~BIT5; P5DIR |= BIT4; // led P5OUT &= ~BIT4; P10DIR |= BIT6; // reset IO EXP P10OUT &= ~BIT6; __delay_cycles(500); P10OUT |= BIT6; UCB0CTL1 |= UCSWRST; UCB0CTL0 |= UCMST + UCMODE_3 + UCSYNC; UCB0CTL1 |= UCSSEL_2 + UCSWRST; UCB0BR0 = 20; UCB0BR1 = 0; UCB0CTL1 &= ~UCSWRST; __delay_cycles(100000); i2c_beginTx(0x77); i2c_write(0x06); i2c_write(0x60); i2c_write(0xFF); i2c_stop(); __delay_cycles(50000); i2c_read(0x77, 0x01, 2); /** interrupt pin **/ P1DIR &= ~BIT5; P1IE |= BIT5; P1IES |= BIT5; __bis_SR_register(GIE); while(1) { P5OUT ^= BIT4; __delay_cycles(1000000); if(a == 1) { read(0x77, 2); if((data[0] & (1<<5)) == 1) { a = 0; P9OUT ^= BIT5; __delay_cycles(1000000); } } } } #pragma vector=PORT1_VECTOR __interrupt void port_1_ISR(void) { if(P1IFG & BIT5) { read(0x77, 2); if((data[0] & (1<<5)) == 0) { __delay_cycles(10000000); P5OUT |= BIT5; __delay_cycles(10000000); P5OUT &= ~BIT5; a = 1; } P1IFG &= ~BIT5; } }