Part Number: MSP432P401R
Hi everyone,
I'm currently trying to communicate with a BQ27441-G1 Fuel Gauge and edit the design capacity using the steps found on page 11 of the technical reference manual (link below).
http://www.ti.com/lit/ug/sluuac9/sluuac9.pdf
Now with what I've written so far (below), I've been able to write a new design capacity to the BQ27441-G1 successfully.
// Driver Library #include "driverlib.h"
// Standard Library Includes #include <stdbool.h> #include <string.h>
// Toolkit for the BQ27441 Fuel Gauge
#include "BQ27441_Definitions.h" #include "FuelGauge.h" // I2C Master Configuration Parameter const eUSCI_I2C_MasterConfig i2cConfig = { EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 3000000, // SMCLK = 3MHz EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 100khz 0, // No byte counter threshold EUSCI_B_I2C_NO_AUTO_STOP // No Auto-stop }; int main(void) { // Disabling the Watchdog MAP_WDT_A_holdTimer(); MAP_GPIO_setAsPeripheralModuleFunctionInputPin(I2Cport, SDApin + SCLpin, GPIO_PRIMARY_MODULE_FUNCTION); // Select Port 6 for I2C - Set Pin 4, 5 MAP_I2C_initMaster(EUSCI_module, &i2cConfig); // Initializing I2C Master to SMCLK at 100kbs with no auto-stop MAP_I2C_setSlaveAddress(EUSCI_module, BQ27441_I2C_ADDRESS); // Specify slave address MAP_I2C_setMode(EUSCI_module, EUSCI_B_I2C_TRANSMIT_MODE); // Set Master in transmit mode MAP_I2C_enableModule(EUSCI_module); // Enable I2C Module to start operations MAP_I2C_clearInterruptFlag(EUSCI_module, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_RECEIVE_INTERRUPT0); // Enable and clear the interrupt flags MAP_Interrupt_enableInterrupt(EUSCI_moduleINT); // Enable master Receive interrupt uint16_t BatCapacity = 1200; // mAh FuelGauge_SetBatteryCap(BatCapacity); int batteryCap = FuelGauge_GetBatteryCap(); int stateOfCharge = FuelGauge_GetStateOfCharge(); int voltage = FuelGauge_GetVoltage(); while (1); }
Where FuelGauge_SetBatteryCap() is a function I wrote that essentially follows the steps on page 11. The other functions also send the appropriate commends to get back what their names imply.
My problem happens when I try to set the DCO clock frequency to something other than the default by adding the driverlib commands...
MAP_CS_setDCOFrequency(8000000); // Setting DCO (clock) to the specified clock speed MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // Tie SMCLK to DCO
And changing the frequency in the I2C config...
// I2C Master Configuration Parameter const eUSCI_I2C_MasterConfig i2cConfig = { EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 8000000, // SMCLK = 8MHz EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 100khz 0, // No byte counter threshold EUSCI_B_I2C_NO_AUTO_STOP // No Auto-stop };
My function FuelGauge_SetBatteryCap() will try and retrieve the old checksum value from the BQ27441-G1 (step 7) and get 0x00 back which is unexpected. Then when the new checksum is calculated
from this value and sent to the BQ27441-G1 (step 11), it doesn't acknowledge.
Is there something wrong with the way I'm changing the DCO frequency that is making the I2C malfunction? Is the point at which its failing during design capacity setup have something to do with it?
Thanks in advance!