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: I2C_read not giving expected value

Part Number: BQ32002

Hello All,

I'm using CC3220MODASF to interface with the BQ32002. In the datasheet I came across the following in the Read Mode for the RTC

I'm passing my arguments for I2C Transaction API like this

    txBufferRtc[0]  =   YEAR;
   // txBufferRtc[1]  =   MONTH;
   // txBufferRtc[2]  =   YEAR;

    i2cTransactionRTC.slaveAddress = RTC_ADDRESS;  //0x68
    i2cTransactionRTC.writeBuf     = txBufferRtc;
    i2cTransactionRTC.writeCount   = 1;//sizeof(txBufferRtc);
    i2cTransactionRTC.readBuf      = rxBufferRtc;
    i2cTransactionRTC.readCount    = sizeof(rxBufferRtc); //10

   for (i = 0; i < 20; i++)
    {

       // I2C_transfer(i2c,&i2cTransactionEEPROM);
        I2C_transfer(i2c,&i2cTransactionRTC);


//       resistance = (rxBufferDPot[0]*1000000/256) + 60;
        /* Sleep for 1 second */
        sleep(1);
    }


    /* Deinitialized I2C */
    I2C_close(i2c);

Supposing I'm trying to read the YEAR, I've input the appropriate register after the slave address i.e. 0x06. However, I'm not getting any value (0 in the output). In this Read mode does it mean that after the slave address and the sub address, we have to again generate a start condition and slave address before we read from the register?

This is very confusing indeed. Please help

BR

Shubhankar

  • Yes, to your question. Make sure your I2C read transfer matches Figure 6 and the description in section 7.5.1 of the datasheet. I suggest probing your SDA/SCL signals at the IC pins using a oscope or protocol analyzer, and confirm that transfer meets the timing requirements in the datasheet.

    Alan
  • Hi Alan

    Thanks for the reply. So i made some progress, but I'm having trouble interpreting the readBuffer data. Please have a look at the picture i"m attaching in the reply.

    I've got the shown readbuffer value. looks like  (Seconds register) is 22 or 0x16, minutes register is 240 or xF0, Hours is 255 xFF and so on

    Note that these are the default read values of the rtc. I havent connected a backup supply so when i power off, the rtc powers off and goes into the default settings that were put into it.

    My biggest doubt is the following:

    1. They say that the minutes is a 7 bit register. The 10_Minute has valid values of 0 to 5. and 1_Minute has 0 to 9. However minutes here are 0xF0. Which doesn't follow the rule.

    2. The datasheet says that the years register is 8 bit. 10_Year is 0 to 9 and so is 1_Year. Here the years in the rxBufferRtc[6] is xFF. which again doesnt follow the rule.

    Am I interpreting these wrongly or are these just random values that are appearing upon startup of the rtc since it has been powered on for the first time, so they might be dummy values fed off in the factory mode?

    Pls advise

    BR

  • Yes, the reset value for any register bit given "X" means the initial value read could be random.

    Alan
  • Hi Alan

    Yes thanks the read is a dont care so my read works perfectly and the values are being updated accordingly.

    However, i now have a problem with the write. Here's my code and also a picture that i'm attaching. I first tried to write into all the registers. But now I'm only trying with seconds. However in my array at 0 position values get updated and seconds value crosses 60. How is that possible? I'm writing the 10s place and 1s place as shown in the datasheet. Please explain as to how data is written to the rtc. Much info hasn't beein provided in the datasheet.

    #define SECONDS                     0x00
    
    struct seconds
    {
        uint8_t seconds_10;
        uint8_t seconds_1;
    }Second;
    
    void readRtc()
    {
        txBufferReadRtc[0] =                SECONDS;
        i2cTransactionRTC.slaveAddress =   RTC_ADDRESS;
        i2cTransactionRTC.writeBuf     = txBufferReadRtc;
        i2cTransactionRTC.writeCount   = 1;
        i2cTransactionRTC.readBuf      = rxBufferReadRtc;
        i2cTransactionRTC.readCount    = sizeof(rxBufferReadRtc);
    
        I2C_transfer(i2c,&i2cTransactionRTC);
    
        return;
    }
    
    void writeRtcSeconds()
    {
        Second.seconds_10 = 0x04;
        Second.seconds_1  = 0x05;
          i2cTransactionRTC.slaveAddress =   RTC_ADDRESS;
          i2cTransactionRTC.writeBuf     = &Second;
          i2cTransactionRTC.writeCount   = sizeof(Second);
    
          I2C_transfer(i2c,&i2cTransactionRTC);
          return;
    }
    
    void *mainThread(void *arg0)
    {
        for (i = 0; i < 20; i++)
        {
    
            sleep(1);
    
            writeRtcSeconds();
            sleep(1);
            readRtc();
     sleep(1);
    }
    }


  • Hi Alan

    I got the answer to my question. The values you write to the registers are not decimal but hex values. eg. 45 seconds is split as 4 in hex and 5 in hex which makes 0100 and 0101 respectively. Thanks for the help.