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.

BQ32002: connecting with Arduino

Part Number: BQ32002

Hi,

I am working with BQ32002 RTC  and Arduino.Using DS3231 RTC i got the  correct date and time in Arduino serial monitor.

 But when i connect BQ32002 RTC wih Arduino,I can able to set time to RTC but for displaying time,it is only showing the set time.

I think the programming of BQ32002 is same as DS3231.But here it is not acting as clock.

Please help  me with this issue.

Regards,

Dhanya

  • Hi Dhanya,

    It is not clear what the issue is. Can you share the schematic? What are the VCC and Vback volatages?

    The registers are not identical between BQ32002 and the competitor device. Addresses 0x00 to 0x06 are similar with differences in the location of the century data. Registers 0x07 and beyond do not match. I recommend to review the register settings for correctness.

    Additionally, need to confirm that the oscillator is functioning

    Kind regards,
    Lane

  • Hi Lane,

    Thank you for your reply.

    I have given Vcc as 3.3V.I am not giving Vback since power from Vcc for testing.

    Lane Boyd said:
    Additionally, need to confirm that the oscillator is functioning

    How to check whether the oscillator is working?

    I can able to write time and date to RTC and the same time i can read from RTC.So i think oscillator not working.Its not acting as clock

    I am sending the code also.

    Regrads,

    Dhanya

    #include "Wire.h"
    #define BQ32002_ADDRESS 0x68
    // Convert normal decimal numbers to binary coded decimal
    
    
    byte decToBcd(byte val)
    {
      return( (val/10*16) + (val%10) );
    }
    // Convert binary coded decimal to normal decimal numbers
    byte bcdToDec(byte val)
    {
      return( (val/16*10) + (val%16) );
    }
    void setup()
    {
      Wire.begin();
    
      Serial.begin(9600);
      // set the initial time here:
      // DS3231 seconds, minutes, hours, day, date, month, year
      setDS3231time(30,35,11,3,12,1,20);
    }
    void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
    dayOfMonth, byte month, byte year)
    {
      // sets time and date data to DS3231
      Wire.beginTransmission(BQ32002);
      Wire.write(0); // set next input to start at the seconds register
      Wire.write(decToBcd(second)); // set seconds
      Wire.write(decToBcd(minute)); // set minutes
      Wire.write(decToBcd(hour)); // set hours
      Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
      Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
      Wire.write(decToBcd(month)); // set month
      Wire.write(decToBcd(year)); // set year (0 to 99)
      Wire.endTransmission();
    }
    void readDS3231time(byte *second,
    byte *minute,
    byte *hour,
    byte *dayOfWeek,
    byte *dayOfMonth,
    byte *month,
    byte *year)
    {
      Wire.beginTransmission(BQ32002);
      Wire.write(0); // set BQ32002 register pointer to 00h
      Wire.endTransmission();
      Wire.requestFrom(BQ32002, 7);
      // request seven bytes of data from BQ32002 starting from register 00h
      *second = bcdToDec(Wire.read() & 0x7f);
      *minute = bcdToDec(Wire.read());
      *hour = bcdToDec(Wire.read() & 0x3f);
      *dayOfWeek = bcdToDec(Wire.read());
      *dayOfMonth = bcdToDec(Wire.read());
      *month = bcdToDec(Wire.read());
      *year = bcdToDec(Wire.read());
    }
    void displayTime()
    {
      byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
      // retrieve data from DS3231
      readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
      &year);
      // send it to the serial monitor
      Serial.print(hour, DEC);
      // convert the byte variable to a decimal number when displayed
      
      Serial.print(":");
      
      if (minute<10)
      {
        Serial.print("0");
      }
      Serial.print(minute, DEC);
      
      Serial.print(":");
      
      if (second<10)
      {
        Serial.print("0");
      }
      Serial.print(second, DEC);
      
      Serial.print(" ");
      
      Serial.print(dayOfMonth, DEC);
      
      Serial.print("/");
      Serial.print(month, DEC);
      Serial.print("/");
      Serial.print(year, DEC);
      Serial.print(" Day of week: ");
      switch(dayOfWeek){
      case 1:
        Serial.println("Sunday");
        break;
      case 2:
        Serial.println("Monday");
        break;
      case 3:
        Serial.println("Tuesday");
        break;
      case 4:
        Serial.println("Wednesday");
        break;
      case 5:
        Serial.println("Thursday");
        break;
      case 6:
        Serial.println("Friday");
        break;
      case 7:
        Serial.println("Saturday");
        break;
      }
    }
    void loop()
    {
      displayTime(); // display the real-time clock data on the Serial Monitor,
      delay(1000); // every second
    }

  • Hi Dhanya,

    Thanks for the info. To check if the oscillator is functioning, read back the OF bit (register 0x01 bit 7). See the description under table 5 on page 13 for more information.

    Note that the OF flag is always set during power-on, and must be cleared during after initialization in order to detect subsequent oscillator fail events

    Kind regards,
    Lane