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.

BQ76952EVM: Communicating with BQ76952EVM 7695_0_36 over SPI

Part Number: BQ76952EVM
Other Parts Discussed in Thread: BQ76952, BQSTUDIO

Hi All,

I am working to switch communications from I2C to SPI on the BQ76952EVM BMS029B and am running into issues regarding whether the device is in SPI mode. I followed the software development guide and EVM users manual to create my SPI functions, but I am unable to read anything besides garbage using the logic analyzer. Since I have the device which boots into I2C mode, I wrote functions to enable SPI communications and then swap to SPI. Here is what I have done:

1. Set comm type to 0x10 (SPI with CRC) by writing to the Comm Type register (address 0x9239) - taken from EVM users guide

2. Enabled REG0 by setting REG0 config register to 0x01 (address 0x9237) - taken from EVM users guide

3. Enable REG1 by setting REG1 config register to 0x0D (address 0x9236) - taken from EVM users guide

4. Enabled SPI communication by writing 0x60 to the SPI Configuration register (address 0x923C) - taken EVM users guide

5. Configured CFETOFF for SPI CS operation by setting that register to 0x00

6. Configured HDQ pin for SPI MOSI operation but setting that register to 0x00

After these steps, I have read from these registers and verified the correct values using the logic analyzer, just to double check that the device is setting those values in its registers, so everything looks good there.

Lastly, I send the SWAP_COMM_MODE subcommand.

From here, I try to read the device address register, but I am just getting garbage on the logic analyzer. I completely remove the wires connecting to the external I2C J17 and also the jumpers on J15 and J18, so the bus lines should only have SPI traffic. This is all after verifying correct I2C operation using the logic analyzer.

I have also tried just using the SWAP_TO_SPI() subcommand but that does not work either, and am still reading garbage on the logic analyzer.

I2C communication works seamlessly and I am able to read voltages, status registers, device id, and everything else, but we need to be using SPI for our application.

Is there anything that I am missing? I am using the evaluation module and am wondering if I missed a jumper somewhere or something, or I missed a config setting. I have been through the TRM, EVM users guide, and software dev guide over and over. Any help is greatly appreciated. Thank you!

Sincerely,

Kyle Garland

  • Edit: I forgot to mention that I am not using the onboard MCU to communicate with the BQ76952, but an external MCU (tm4c123 family).

  • Hi Kyle,

    It might be easier to try these steps using the MCU on board first to verify. This will make sure the device really is transitioning to SPI mode successfully.

    One thing I do not see in your steps is you should send the commands to enter CONFIG_UPDATE mode before writing the register and to exit this mode afterwards. The SPI protocol can also be a little tricky for this device. Make sure your code is following the recommendations in the TRM and the Software Development guide (https://www.ti.com/lit/an/sluaa11a/sluaa11a.pdf ). I can also send you an ARM example using SPI through a private message if you send me an E2E friend request.

    Best regards,

    Matt

  • Hi Matt,

    I forgot to mention, but I do enter config update mode before writing to any RAM registers, and then exit right after.

    I followed the Software Dev Guide and wrote some conservative code for checking the MISO line for a read back of the data I sent before moving on to the next byte, as shown below. 

    int16_t BQ76952::GetCellVoltage(uint8_t cell_number)
    {
        bool success = false;
        uint32_t tx_voltage_array[3];
        uint8_t rx_voltage_array[2];
        uint8_t cell = GetCellNumber(cell_number);
        int16_t voltage;
    
        for (uint8_t index = 0; index < 2; index++) //writing 2 bytes of data to one of these registers
        {
            tx_voltage_array[0] = cell;
            tx_voltage_array[1] = 0xFF; //not sending anything when reading voltages
            tx_voltage_array[2] = ComputeCRC8(tx_voltage_array, 2);
    
            while (!success)
            {
                spi->Transfer(tx_voltage_array, rx_data_array, 3);
    
                if (rx_data_array[0] == cell)
                {
                    success = true;
                    //TODO Add logic for checking CRC
                    rx_voltage_array[index] = rx_data_array[1];
                }
            }
    
            success = false;
            cell++;
        }
        voltage = static_cast<int16_t>(rx_voltage_array[0] << 8
                | rx_voltage_array[1]);
        return voltage;
    }

    As you can see, I enter a while loop while waiting for the device to read back what I have sent, because usually the first bytes on the MISO line are 0xFFFFFF and then  0xFFFF00. This style is typical of my functions for sending direct commands, subcommands/data subcommands, and when writing to RAM registers. I also found example code for SPI and I2C on this forum and I see they do the same while loop checking process that I do.

    The problem with using the onboard MCU is BQ studio doesn't recognize the 7695_0_36 device that I am using, and also doesn't give me one of the options necessary for configuring SPI(setting SPI communications register to 0x60). The only close option I can select is 7695_0_28.

    Another problem with using the onboard MCU is that I have to change the jumpers back and forth from external I2C to Internal I2C to send my commands that change to SPI, and then BQ studio wont show anything when I'm not connected for internal MCU connection.

    I really just need an example of how to set up the dev kit for external SPI use so I can see if I have a jumper or configuration missing. Thank you.

    Sincerely,

    Kyle Garland

  • Hi Kyle,

    It looks like you need to update your version of BQStudio. You should download the BQSTUDIO-TEST version so that the latest devices are included. The reason I recommend connecting with BQStudio first is to confirm the device is functioning properly apart from your code.

    Regards,

    Matt

  • Hi Matt,

    That sounds good to me, I'll install the newest test version of BQStudio and check to see if I can connect to SPI and get back to you later today. 

    Also, would I need to change the jumpers for internal SPI usage after switching from I2C to SPI mode, and then remove those jumpers and connect my external SPI wires to test my code when I know the device is in SPI mode? 

    -Kyle

  • Yes, jumpers installed for internal SPI usage and removed when you connect the external SPI.