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.

working External RTC BQ32000 interfacing to msp430 code

Other Parts Discussed in Thread: BQ32000

0447.BQ32000 with msp430.zip

Hi 

this is the working code for BQ32000 interfacing to msp430.

Regards

Nandish

  • MainClockInit() statement inside your main() block is giving an error.

    The error is :
    unresolved symbol MainClockInit, first referenced in ./main.obj

    I'm new to I2C so I used your code and I have no idea how to correct this. Any help is appreciated.

  • Hi bhaskar,

    sorry i forgot to remove that line in my code and please  find the  below  code which is tested . `

    #include "MSP430.h"
    unsigned char sec, min, hour, month, year, date;
    #define SLA_ADR 0x68//slave address
    void BQ32000Init(void);
    void BQ32000ReadTime(unsigned char *datos);
    void USCIB0Init(void);
    void I2CStop(void);
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata);
    unsigned char I2CStartRead(unsigned int slave);
    unsigned char I2CWrite(unsigned char c);
    unsigned char I2CRead(void);
    int main( void )
    {   
       unsigned char datos[8];
       WDTCTL = WDTPW + WDTHOLD;
       
        BQ32000Init();
      __delay_cycles(250000);//250mseg
       
       
       while(1){
          
             BQ32000ReadTime(&datos[0]);
             sec=datos[0];
            min=datos[1];
            hour=datos[2];
            date=datos[4];
            month=datos[5];
            year=datos[6];
             
       }
    }
    void BQ32000Init(void)
    {
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CWrite(0x30);//s  0
       I2CWrite(0x02);//m  1
       I2CWrite(0x10);//h  2
       I2CWrite(0x02);//day  3
       I2CWrite(0x11);//d  4
       I2CWrite(0x11);//mth   5
       I2CWrite(0x14);//y  6
       I2CWrite(0x10);//cotrol register  7
       I2CStop();
    }
    void BQ32000ReadTime(unsigned char *datos)
    {
       unsigned char aux;
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CStartRead(SLA_ADR);
       for(aux = 0; aux < 7; aux++, datos++){//6
          *datos = I2CRead();
       }
       UCB0CTL1 |= UCTXNACK;
       I2CStop();
       *datos = I2CRead();
       __delay_cycles(15);//15
       I2CStop();
    }
    void USCIB0Init(void){
       P1SEL |= 0xC0;
       P1SEL2 |= 0xC0;
       UCB0CTL1 |= UCSWRST;
       UCB0CTL0 = UCMST+UCMODE_3+UCSYNC;
       UCB0CTL1 = UCSSEL_2+UCSWRST;
       UCB0BR0 = 10;
       UCB0BR1 = 0;
       UCB0I2COA = 0;
       UCB0I2CSA = 0;
       UCB0CTL1 &= ~UCSWRST;
    }
    void I2CStop(void)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0CTL1 |= UCTXSTP;
    }
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 |= UCTR;                      // I2C TX
       UCB0CTL1 |= UCTXSTT;
       UCB0TXBUF = firstdata;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0){
          return 0;
       } else {
          return 1;
       }
    }
    unsigned char I2CStartRead(unsigned int slave)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 &= ~UCTR;
       UCB0CTL1 |= UCTXSTT;
       while((UCB0CTL1 & UCTXSTT)!= 0);
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CWrite(unsigned char c)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0TXBUF = c;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CRead(void)
    {
       unsigned char data;
       while((UCB0STAT & BUSY)!= 0);
       while(!(IFG2 & UCB0RXIFG));
       data = UCB0RXBUF;
       return data;
    }
  • I'm trying to interface RTC BQ32000 with MSP430  and i'm unable to find suitable circuitry for this purpose. Do you have a working circuit in mind?

    Thanks for the help!

  • share me your schematic and code file to my id nandish.sriram@serialsystem.com
  • Nandish H S said:

    Hi bhaskar,

    sorry i forgot to remove that line in my code and please  find the  below  code which is tested . `

    #include "MSP430.h"
    unsigned char sec, min, hour, month, year, date;
    #define SLA_ADR 0x68//slave address
    void BQ32000Init(void);
    void BQ32000ReadTime(unsigned char *datos);
    void USCIB0Init(void);
    void I2CStop(void);
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata);
    unsigned char I2CStartRead(unsigned int slave);
    unsigned char I2CWrite(unsigned char c);
    unsigned char I2CRead(void);
    int main( void )
    {   
       unsigned char datos[8];
       WDTCTL = WDTPW + WDTHOLD;
       
        BQ32000Init();
      __delay_cycles(250000);//250mseg
       
       
       while(1){
          
             BQ32000ReadTime(&datos[0]);
             sec=datos[0];
            min=datos[1];
            hour=datos[2];
            date=datos[4];
            month=datos[5];
            year=datos[6];
             
       }
    }
    void BQ32000Init(void)
    {
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CWrite(0x30);//s  0
       I2CWrite(0x02);//m  1
       I2CWrite(0x10);//h  2
       I2CWrite(0x02);//day  3
       I2CWrite(0x11);//d  4
       I2CWrite(0x11);//mth   5
       I2CWrite(0x14);//y  6
       I2CWrite(0x10);//cotrol register  7
       I2CStop();
    }
    void BQ32000ReadTime(unsigned char *datos)
    {
       unsigned char aux;
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CStartRead(SLA_ADR);
       for(aux = 0; aux < 7; aux++, datos++){//6
          *datos = I2CRead();
       }
       UCB0CTL1 |= UCTXNACK;
       I2CStop();
       *datos = I2CRead();
       __delay_cycles(15);//15
       I2CStop();
    }
    void USCIB0Init(void){
       P1SEL |= 0xC0;
       P1SEL2 |= 0xC0;
       UCB0CTL1 |= UCSWRST;
       UCB0CTL0 = UCMST+UCMODE_3+UCSYNC;
       UCB0CTL1 = UCSSEL_2+UCSWRST;
       UCB0BR0 = 10;
       UCB0BR1 = 0;
       UCB0I2COA = 0;
       UCB0I2CSA = 0;
       UCB0CTL1 &= ~UCSWRST;
    }
    void I2CStop(void)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0CTL1 |= UCTXSTP;
    }
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 |= UCTR;                      // I2C TX
       UCB0CTL1 |= UCTXSTT;
       UCB0TXBUF = firstdata;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0){
          return 0;
       } else {
          return 1;
       }
    }
    unsigned char I2CStartRead(unsigned int slave)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 &= ~UCTR;
       UCB0CTL1 |= UCTXSTT;
       while((UCB0CTL1 & UCTXSTT)!= 0);
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CWrite(unsigned char c)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0TXBUF = c;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CRead(void)
    {
       unsigned char data;
       while((UCB0STAT & BUSY)!= 0);
       while(!(IFG2 & UCB0RXIFG));
       data = UCB0RXBUF;
       return data;
    }

    Nandish H S said:

    Hi bhaskar,

    sorry i forgot to remove that line in my code and please  find the  below  code which is tested . `

    #include "MSP430.h"
    unsigned char sec, min, hour, month, year, date;
    #define SLA_ADR 0x68//slave address
    void BQ32000Init(void);
    void BQ32000ReadTime(unsigned char *datos);
    void USCIB0Init(void);
    void I2CStop(void);
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata);
    unsigned char I2CStartRead(unsigned int slave);
    unsigned char I2CWrite(unsigned char c);
    unsigned char I2CRead(void);
    int main( void )
    {   
       unsigned char datos[8];
       WDTCTL = WDTPW + WDTHOLD;
       
        BQ32000Init();
      __delay_cycles(250000);//250mseg
       
       
       while(1){
          
             BQ32000ReadTime(&datos[0]);
             sec=datos[0];
            min=datos[1];
            hour=datos[2];
            date=datos[4];
            month=datos[5];
            year=datos[6];
             
       }
    }
    void BQ32000Init(void)
    {
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CWrite(0x30);//s  0
       I2CWrite(0x02);//m  1
       I2CWrite(0x10);//h  2
       I2CWrite(0x02);//day  3
       I2CWrite(0x11);//d  4
       I2CWrite(0x11);//mth   5
       I2CWrite(0x14);//y  6
       I2CWrite(0x10);//cotrol register  7
       I2CStop();
    }
    void BQ32000ReadTime(unsigned char *datos)
    {
       unsigned char aux;
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CStartRead(SLA_ADR);
       for(aux = 0; aux < 7; aux++, datos++){//6
          *datos = I2CRead();
       }
       UCB0CTL1 |= UCTXNACK;
       I2CStop();
       *datos = I2CRead();
       __delay_cycles(15);//15
       I2CStop();
    }
    void USCIB0Init(void){
       P1SEL |= 0xC0;
       P1SEL2 |= 0xC0;
       UCB0CTL1 |= UCSWRST;
       UCB0CTL0 = UCMST+UCMODE_3+UCSYNC;
       UCB0CTL1 = UCSSEL_2+UCSWRST;
       UCB0BR0 = 10;
       UCB0BR1 = 0;
       UCB0I2COA = 0;
       UCB0I2CSA = 0;
       UCB0CTL1 &= ~UCSWRST;
    }
    void I2CStop(void)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0CTL1 |= UCTXSTP;
    }
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 |= UCTR;                      // I2C TX
       UCB0CTL1 |= UCTXSTT;
       UCB0TXBUF = firstdata;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0){
          return 0;
       } else {
          return 1;
       }
    }
    unsigned char I2CStartRead(unsigned int slave)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 &= ~UCTR;
       UCB0CTL1 |= UCTXSTT;
       while((UCB0CTL1 & UCTXSTT)!= 0);
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CWrite(unsigned char c)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0TXBUF = c;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CRead(void)
    {
       unsigned char data;
       while((UCB0STAT & BUSY)!= 0);
       while(!(IFG2 & UCB0RXIFG));
       data = UCB0RXBUF;
       return data;
    }

    Nandish H S said:

    Hi bhaskar,

    sorry i forgot to remove that line in my code and please  find the  below  code which is tested . `

    #include "MSP430.h"
    unsigned char sec, min, hour, month, year, date;
    #define SLA_ADR 0x68//slave address
    void BQ32000Init(void);
    void BQ32000ReadTime(unsigned char *datos);
    void USCIB0Init(void);
    void I2CStop(void);
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata);
    unsigned char I2CStartRead(unsigned int slave);
    unsigned char I2CWrite(unsigned char c);
    unsigned char I2CRead(void);
    int main( void )
    {   
       unsigned char datos[8];
       WDTCTL = WDTPW + WDTHOLD;
       
        BQ32000Init();
      __delay_cycles(250000);//250mseg
       
       
       while(1){
          
             BQ32000ReadTime(&datos[0]);
             sec=datos[0];
            min=datos[1];
            hour=datos[2];
            date=datos[4];
            month=datos[5];
            year=datos[6];
             
       }
    }
    void BQ32000Init(void)
    {
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CWrite(0x30);//s  0
       I2CWrite(0x02);//m  1
       I2CWrite(0x10);//h  2
       I2CWrite(0x02);//day  3
       I2CWrite(0x11);//d  4
       I2CWrite(0x11);//mth   5
       I2CWrite(0x14);//y  6
       I2CWrite(0x10);//cotrol register  7
       I2CStop();
    }
    void BQ32000ReadTime(unsigned char *datos)
    {
       unsigned char aux;
       USCIB0Init();
       I2CStartWrite(SLA_ADR,0x00);
       I2CStartRead(SLA_ADR);
       for(aux = 0; aux < 7; aux++, datos++){//6
          *datos = I2CRead();
       }
       UCB0CTL1 |= UCTXNACK;
       I2CStop();
       *datos = I2CRead();
       __delay_cycles(15);//15
       I2CStop();
    }
    void USCIB0Init(void){
       P1SEL |= 0xC0;
       P1SEL2 |= 0xC0;
       UCB0CTL1 |= UCSWRST;
       UCB0CTL0 = UCMST+UCMODE_3+UCSYNC;
       UCB0CTL1 = UCSSEL_2+UCSWRST;
       UCB0BR0 = 10;
       UCB0BR1 = 0;
       UCB0I2COA = 0;
       UCB0I2CSA = 0;
       UCB0CTL1 &= ~UCSWRST;
    }
    void I2CStop(void)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0CTL1 |= UCTXSTP;
    }
    unsigned char I2CStartWrite(unsigned int slave, unsigned char firstdata)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 |= UCTR;                      // I2C TX
       UCB0CTL1 |= UCTXSTT;
       UCB0TXBUF = firstdata;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0){
          return 0;
       } else {
          return 1;
       }
    }
    unsigned char I2CStartRead(unsigned int slave)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0I2CSA = slave;
       UCB0CTL1 &= ~UCTR;
       UCB0CTL1 |= UCTXSTT;
       while((UCB0CTL1 & UCTXSTT)!= 0);
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CWrite(unsigned char c)
    {
       while((UCB0STAT & BUSY)!= 0);
       UCB0TXBUF = c;
       while(!(IFG2 &UCB0TXIFG));
       if((UCB0STAT & UCNACKIFG)!=0)
       {
          return 0;
       } else
       {
          return 1;
       }
    }
    unsigned char I2CRead(void)
    {
       unsigned char data;
       while((UCB0STAT & BUSY)!= 0);
       while(!(IFG2 & UCB0RXIFG));
       data = UCB0RXBUF;
       return data;
    }

**Attention** This is a public forum