Hello, i am trying to read a register of drv10983 from msp430g2553 but it is not working ,so please
let me know where i am going wrong.
here is my code :
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 24; //SMCLK/24 = 50 kHz
UCB0BR1 = 0;
UCB0I2CSA = DRV10983; // Slave Address is 0x52
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
// IE2 |= UCB0RXIE + UCB0TXIE; // Enable TX interrupt
//SALVE ID
while (UCB0CTL1 & UCTXSTP) {;} // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
while (UCB0CTL1 & UCTXSTT) {;} //wait for transmission to finish
// REFRESH eeprom
//ADDRESS
UCB0TXBUF = 0x03;
while(!(UCB0TXIFG)) {;}
//DATA
UCB0TXBUF = 0x20;
while(!(UCB0TXIFG)) {;}
UCB0CTL1 |= UCTXSTP; // I2C stop condition
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0I2CSA = DRV10983; // Slave Address is 0x52h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
//READ REGISTER
//SALVE ID
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
while (UCB0CTL1 & UCTXSTT) {; } //wait for transmission to finish // Load TX buffer
//read register ADDRESS
UCB0TXBUF = 0X10;
while(!(UCB0TXIFG)) {;}
//I2C STOP
UCB0CTL1 |= UCTXSTP; // I2C stop condition
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0I2CSA = DRV10983; // Slave Address is 048h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
//READ REGISTER
//SALVE ID
//UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start conditionUCB0CTL1 &= ~UCTR; // I2C Rx
UCB0CTL1 |= UCTXSTT + UCTXNACK; // I2C start condition
while (UCB0CTL1 & UCTXSTT) {; } //wait for transmission to finish
RX_DATA = UCB0RXBUF;
while(!(UCB0RXIFG)) {;}
UCB0CTL1 |= UCTXSTP; // I2C stop condition
UARTSendChar(RX_DATA);
for(t=0;t<=100;t++); //small delay
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
for(t=0;t<=50;t++); // small delay