This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Minutes and seconds, are interchanged when retrieved consecutively from rtc BQ32000

Other Parts Discussed in Thread: BQ32000, MSP430F2274

Hi,

The controller I am using for communicating with BQ32000 is MSP430F2274. I am getting seconds and minutes properly when retrieved either one (minutes or seconds) alone. i.e. if I try to get seconds alone or minutes alone i get data properly. But if try to get datas consecutively (i tried both , auto increment and separate subroutines for seconds and minutes) the datas received are interchanged i.e. the register allocated for seconds receives 'minutes' data and the other register receives 'seconds' data. Otherwise the clock is working well. I tried two options. Could someone go through my code given below and suggest a solution for this?

while(1)

{
get_sec();                     // Get the seconds data in the buffer
display_sec();              // Display 'seconds' on LCD
get_min();                     // Get the minutes data in the buffer
display_min();              // Display 'minutes' on LCD
}

}

void init_I2C(void)                                                                    // I2C initialization
{
UCB0CTL1 |= UCSWRST;                                                       // Enable SW reset
P3SEL |= 0x06;                                                                           // Assign I2C pins to USCI_B0
UCB0CTL0 |= (UCMST + UCMODE_3 + UCSYNC);          // I2C Master, synchronous mode
UCB0CTL1 |= (UCSSEL_2 + UCSWRST);                           // Use SMCLK, keep SW reset
UCB0BR0 = 12;                                                                          // FSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2COA = 0x48;                                                                  // Own Address is 048h
UCB0I2CSA = 0x68;                                                                   // Slave Address
UCB0CTL1 &= ~UCSWRST;                                                    // Clear SW reset, resume operation

}

// First option i tried

void get_sec()
{
while (UCB0CTL1 & UCTXSTP);                     // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT;                   // I2C start condition
UCB0TXBUF = RTC_write_addr;                     // Slave address with write bit, D0 
__delay_cycles(72);
UCB0TXBUF = RTC_regstr_addr;                  // Address for seconds (0) in BQ32000
__delay_cycles(72);
UCB0CTL1 &= ~UCTR;
UCB0CTL1 |= UCTXSTT;
__delay_cycles(72);
UCB0TXBUF = 0;                                                 // Writing dummy value
__delay_cycles(72);
UCB0TXBUF = RTC_read_addr;                      // Slave address with read bit, D1
__delay_cycles(72);
UCB0CTL1 |= UCTXSTP;                                   // I2C stop communication
RxDataS = UCB0RXBUF;                                   // receives 'Seconds' data

}
void get_min()
{
while (UCB0CTL1 & UCTXSTP);                      // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT;                   // I2C start condition
UCB0TXBUF = RTC_write_addr;                     // Slave address D0
__delay_cycles(72);
UCB0TXBUF = RTC_regstr_addr+1;              // Address for minutes (0x01) in BQ32000
__delay_cycles(72);
UCB0CTL1 &= ~UCTR;
UCB0CTL1 |= UCTXSTT;
__delay_cycles(72);
UCB0TXBUF = 0;
__delay_cycles(72);
UCB0TXBUF = RTC_read_addr;                     // Slave address D1
__delay_cycles(72);
UCB0CTL1 |= UCTXSTP;                                   // I2C stop communication
RxDataM = UCB0RXBUF;                                   // Receives 'Minutes' data
}

//Second option i tried

void get_sec_min()
{
while (UCB0CTL1 & UCTXSTP);                        // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT;                     // I2C start condition
UCB0TXBUF = RTC_write_addr;                       // Slave address D0
__delay_cycles(72);
UCB0TXBUF = RTC_regstr_addr;                      // Address for seconds in BQ32000
__delay_cycles(72);
UCB0CTL1 &= ~UCTR;
UCB0CTL1 |= UCTXSTT;
__delay_cycles(72);
UCB0TXBUF = 0;                                                   // Write dummy value
__delay_cycles(70);
UCB0TXBUF = RTC_read_addr;                         // Slave address D1

RxDataM = UCB0RXBUF;                                     // Receives 'Seconds' data
__delay_cycles(72);
UCB0CTL1 |= UCTXSTP;                                      // I2C stop communication
RxDataM = UCB0RXBUF;                                      // Receives 'Minutes' data

}

Regards

Shaju