Hello everyone,
I am using MSP430F5335 to communicate with battery bq40z50 through i2c communication using pollin method. I have implemented my code as follows
uint8_t data = 0x09; void i2c_init() { UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode UCB0CTL1 = UCSSEL_2 + UCSWRST ; // Use SMCLK, keep SW reset UCB0BR0 = 10; // fSCL = SMCLK/10 = 100kHz UCB0BR1 = 0; UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation } void i2c_write() { UCB0I2CSA = 0x0b; // Slave Address is 0bh UCB0CTL1 &= ~UCTXSTP; //clear stop condition write(); } void write() { UCB0CTL1 |= UCTR; // Enable transmit UCB0CTL1 |= UCTXSTT; // i2c start while(UCB0IFG & UCNACKIFG) //if nack rx { UCB0IFG &= ~UCNACKIFG; UCB0CTL1 |= UCTXSTP; //stop condition } while(!(UCB0IFG & UCB0TXIFG)); //wait for tx begun (buffer ready) UCB0TXBUF = data; }
in this implementation i always get NACK from the slave. I also checked in the BSP code its working fine, from i concluded there is no hardware problem. in interrupt method also i tested its working fine, but my requirement is polling method only. If i put the delay in before sending byte to Tx buff its working fine. Is it correct way? Also while receiving time NACK set means whether the slave not send proper data or else problem with master.
Thanks in advance