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.

BQ79606A-EXAMPLE-CODE: ReadReg() function issue

Part Number: BQ79606A-EXAMPLE-CODE
Other Parts Discussed in Thread: BQ79606A-Q1

Hi support,

I am able to read the cells voltage back and enable the cell balance, all FETs are in their expected states. But I can not read the status back (always 0) with following code:

BYTE bFrame = 0;
ReadReg(0, CB_SW_STAT, &bFrame, 1, 0, FRMWRT_SGL_R);
int pStat = (int)(bFrame & 0x3F);
printf("Passive switch status: %d\n", pStat);

/* or
ReadReg(0, DEV_STAT, &bFrame, 1, 0, FRMWRT_SGL_R);
int pStat = (int)((bFrame >> 4) & 0x1);
printf("Passive CB status: %d\n", pStat);
*/

In BQ79606A-Q1 Software Design Reference under 4.7 section, it mentions:

80 00 02 00 00 84 1E // read PARTID
80 00 02 04 00 86 DE // read DEV_STAT
80 00 02 06 00 87 BE // read FAULT_SUM
• 80 = Single device read of 1 byte
• 00 = Device 0
• 0200, 0204, 0206 = Register address 0x200, 0x204, 0x206
• 00 = Read back one byte of data
• 841E, 86DE, 87BE = CRC

So does my ReadReg() function sending the right code of: 80 00 02 04 00 86 DE ?

Please advise.

Thanks,

Eric

  • Hi Eric,

    All the other commands for PARTID and FAULT_SUM work correctly as well? Did you complete balancing or any other functions that would make DEV_STAT change from 0x00? If you read the register summary in the datasheet, ensure one of the bits would go high as expected otherwise it could be correct.

    Regards,

    Taylor

  • Hi Taylor,

    None of those status can be read back correctly (always 0)!

    Can you explain how to implement the function

    #_of_Read_Bytes = ReadReg(Device_Address, Register_Address, Incoming_Data_Byte_Array,
    #_Data_Bytes, ms_Before_Time_Out, Packet_Type)

    to send the code of 80 00 02 04 00 86 DE ?

    Thanks,

    Eric

  • Hi Taylor,

    Okay, some kind of figure it out. But can you explain why the  read back data byte is staying in response_frame2[4] in void AutoAddress() function within bq79606.c? And how to implement it with only passing a single byte type parameter and read it back?

    // //OPTIONAL: read back all device addresses
    // WriteReg(0, COMM_TO, 0x00, 1, FRMWRT_ALL_NR); //Disable communication timeout because printf takes a long time
    // for (nCurrentBoard = 0; nCurrentBoard < TOTALBOARDS; nCurrentBoard++) {
    // memset(response_frame2, 0, sizeof(response_frame2));
    // ReadReg(nCurrentBoard, DEVADD_USR, response_frame2, 1, 0, FRMWRT_SGL_R);
    // printf("Board %d=%02x\n",nCurrentBoard,response_frame2[4]);

    Thanks,

    Eric

  • Hi Eric,

    I am not sure I understand the question, can you please explain what the intention would be to do? It is better to not edit any structure in bq79606.c and only edit the code you want to execute within sysmain.c file only. (and bq79606.h just to edit totalboards variable in case the # of stack devices changes).

    Regards,

    Taylor

  • Hi Tylor,

    That is the way I used to read the data back from the register in my main file, and I don't intent to modify any codes in bq79606.c but will need some help to understand it. Hopefully I can see some real codes or explanation instead of  just a simple reference link.

    Thanks,

    Eric

  • Hi Eric,

    I apologize but I'm still not sure exactly what you are looking for, perhaps this thread explanation below may help with background. Most everything in bq79606.c is just the layer to put in correct UART structure as per datasheet section "Command and Response Protocol Layer" or functions used in sys main. I think that portion of code was just designed to read back the device address to confirm autoaddressing was done correctly (please read up on this in the datasheet). And the function ReadReg is explained in section 1.2 of the user guide for how to change it to support other commands, there is an example nRead = command which you are free to change out register name, byte length etc. and should be self-explanatory to change for what you want using this example.

    https://e2e.ti.com/support/power-management/f/196/t/868854?tisearch=e2e-sitesearch&keymatch=bq79606a%25252520example%25252520code%25252520readreg

    Regards,

    Taylor

  • Hi Taylor,

    Specifically, I want to know why the read back data is in the [4] of the array when only 1 byte of data is required.

    // ReadReg(nCurrentBoard, DEVADD_USR, response_frame2, 1, 0, FRMWRT_SGL_R);
    // printf("Board %d=%02x\n",nCurrentBoard,response_frame2[4]);

    And what is wrong by doing the following?

    BYTE bFrame = 0;
    ReadReg(0, DEV_STAT, &bFrame, 1, 0, FRMWRT_SGL_R);

    Thanks,

    Eric

  • Eric,

    As I said above I think that portion of code was just designed to read back the device address to confirm autoaddressing was done correctly (please read up on this in the datasheet), so it would be several device addresses to print out for each board. Again, follow the exact structure of our example to edit commands for the second part, you are missing nRead and the full structure. 

    Regards,

    Taylor