BQ76952: bq76952数据储存器读写问题

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

我在主控的初始化程序中禁用了sleep mode,并且还发送了0x009a,为什么上电后,还是进入了睡眠模式。

  • int main(void) { /* USER CODE BEGIN 1 */ CRC_Mode = 1; /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_CAN_Init(); MX_USART1_UART_Init(); MX_CRC_Init(); /* USER CODE BEGIN 2 */ HAL_CAN_Start(&hcan); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // RST_SHUT pin set low HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); // DFETOFF pin (BOTHOFF) set low HAL_Delay(6); CommandSubcommands(BQ769x2_RESET); HAL_Delay(6); BQ769x2_Init(); // Configure all of the BQ769x2 register settings HAL_Delay(2); CommandSubcommands(CommType); CRC_Mode = 0; CommandSubcommands(SLEEP_DISABLE); CommandSubcommands(FET_ENABLE); CommandSubcommands(ALL_FETS_ON); // Subcommands(FET_CONTROL,0x0A,W); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // printf("RUNLINE : %d \r\n",__LINE__); // CommandSubcommands(ALL_FETS_ON); // HAL_Delay(50); // DirectCommands(0X12,00,R); //// Subcommands(0x0057,00,R); //// BQ769x2_ReadTemperature(0x70); BQ769x2_ReadTemperature(0x72); BQ769x2_ReadTemperature(0x74); // //// DirectCommands(BatteryStatus,0X00,R); // DirectCommands(AlarmEnable,0x00,R); // DirectCommands(0x02, 0x00, R); // CommandSubcommands(ALL_FETS_ON); // HAL_Delay(5); DirectCommands(0X14, 0x00, R); // CommandSubcommands(ALL_FETS_ON); HAL_Delay(50); //// // BQ769x2_ReadFETStatus(); // BQ769x2_ReadAlarmStatus(); // BQ769x2_ReadSafetyStatus(); // BQ769x2_ReadPFStatus(); // Subcommands(MANUFACTURINGSTATUS, 0x00, W); // DirectCommands(0x3a, 0x00, R); // BQ769x2_ReadPassQ(); // Subcommands(DASTATUS5, 0x00, R); // BQ769x2_All_IntoPacket(); // SendCanPacket(0x00000100); HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_6); HAL_Delay(500); } /* USER CODE END 3 */ }

  • void BQ769x2_Init() {

    // Configures all parameters in device RAM

    // Enter CONFIGUPDATE mode (Subcommand 0x0090) - It is required to be in CONFIG_UPDATE mode to program the device RAM settings

    // See TRM for full description of CONFIG_UPDATE mode

    CommandSubcommands(SET_CFGUPDATE);

    // After entering CONFIG_UPDATE mode, RAM registers can be programmed. When programming RAM, checksum and length must also be

    // programmed for the change to take effect. All of the RAM registers are described in detail in the BQ769x2 TRM.

    // An easier way to find the descriptions is in the BQStudio Data Memory screen. When you move the mouse over the register name,

    // a full description of the register and the bits will pop up on the screen.

    // 'Power Config' - 0x9234 = 0x2D80

    // Setting the DSLP_LDO bit allows the LDOs to remain active when the device goes into Deep Sleep mode

    // Set wake speed bits to 00 for best performance

    // BQ769x2_SetRegister(PowerConfig, 0x2D80, 2);

    BQ769x2_SetRegister(PowerConfig, 0x2C80, 2);

    // 'REG0 Config' - set REG0_EN bit to enable pre-regulator

    BQ769x2_SetRegister(REG0Config, 0x01, 1);

    // 'REG12 Config' - Enable REG1 with 3.3V output (0x0D for 3.3V, 0x0F for 5V)

    BQ769x2_SetRegister(REG12Config, 0x0D, 1);

    BQ769x2_SetRegister(FETOptions, 0x1D, 1);

    BQ769x2_SetRegister(ChgPumpControl, 0x01, 1);

    // Set DFETOFF pin to control BOTH CHG and DSG FET - 0x92FB = 0x42 (set to 0x00 to disable)

    // BQ769x2_SetRegister(DFETOFFPinConfig, 0x00, 1);

    BQ769x2_SetRegister(DFETOFFPinConfig, 0x0B, 1);

    BQ769x2_SetRegister(CFETOFFPinConfig, 0x0B, 1);

    // Set up ALERT Pin - 0x92FC = 0x2A

    // This configures the ALERT pin to drive high (REG1 voltage) when enabled.

    // The ALERT pin can be used as an interrupt to the MCU when a protection has triggered or new measurements are available

    // BQ769x2_SetRegister(ALERTPinConfig, 0x2A, 1);

    BQ769x2_SetRegister(ALERTPinConfig, 0x0B, 1);

    // Set TS1 to measure Cell Temperature - 0x92FD = 0x07

    BQ769x2_SetRegister(TS1Config, 0x07, 1);

    BQ769x2_SetRegister(TS2Config, 0x07, 1);

    // Set TS3 to measure FET Temperature - 0x92FF = 0x0F

    BQ769x2_SetRegister(TS3Config, 0x07, 2);

    // Set Temperature OFFSET

    // BQ769x2_SetRegister(TS1TempOffset, 0x80, 1);

    // BQ769x2_SetRegister(CFETOFFTempOffset, 0x80, 1);

    // BQ769x2_SetRegister(TS3TempOffset, 0x80, 1);

    // BQ769x2_SetRegister(HDQTempOffset, 0x80, 1);

    // BQ769x2_SetRegister(DCHGTempOffset, 0x80, 1);

    // BQ769x2_SetRegister(DDSGTempOffset, 0x80, 1);

    BQ769x2_SetRegister(TS1TempOffset, 0x00, 1);

    BQ769x2_SetRegister(CFETOFFTempOffset, 0x00, 1);

    BQ769x2_SetRegister(TS3TempOffset, 0x00, 1);

    BQ769x2_SetRegister(HDQTempOffset, 0x00, 1);

    BQ769x2_SetRegister(DCHGTempOffset, 0x00, 1);

    BQ769x2_SetRegister(DDSGTempOffset, 0x00, 1);

    // Set HDQ to measure Cell Temperature - 0x9300 = 0x07

    BQ769x2_SetRegister(HDQPinConfig, 0x0B, 1); // No thermistor installed on EVM HDQ pin, so set to 0x00

    BQ769x2_SetRegister(DCHGPinConfig, 0x0B, 1); // DCHG Pin set low

    BQ769x2_SetRegister(DDSGPinConfig, 0x0B, 1); // DDSG Pin set low

    // 18k Temperature model

    // BQ769x2_SetRegister(T18kCoeffa1, 0xBEE3, 2); // 18k Temp a1

    // BQ769x2_SetRegister(T18kCoeffa2, 0x7BD0, 2); // 18k Temp a2

    // BQ769x2_SetRegister(T18kCoeffa3, 0x94FC, 2); // 18k Temp a2

    // BQ769x2_SetRegister(T18kCoeffa4, 0x66D4, 2); // 18k Temp a4

    // BQ769x2_SetRegister(T18kCoeffa5, 0x055A, 2); // 18k Temp a5

    // BQ769x2_SetRegister(T18kCoeffb1, 0xF7C2, 2); // 18k Temp b1

    // BQ769x2_SetRegister(T18kCoeffb2, 0x0F7A, 2); // 18k Temp b2

    // BQ769x2_SetRegister(T18kCoeffb3, 0xEF38, 2); // 18k Temp b3

    // BQ769x2_SetRegister(T18kCoeffb4, 0x128E, 2); // 18k Temp b4

    // BQ769x2_SetRegister(T18kAdc0, 0x2DB7, 2); // 18k ADC 0

    // 18k Temperature model based on EVM

    // BQ769x2_SetRegister(T18kCoeffa1, 0xC35C, 2); // 18k Temp a1

    // BQ769x2_SetRegister(T18kCoeffa2, 0x6737, 2); // 18k Temp a2

    // BQ769x2_SetRegister(T18kCoeffa3, 0xA778, 2); // 18k Temp a2

    // BQ769x2_SetRegister(T18kCoeffa4, 0x70A2, 2); // 18k Temp a4

    // BQ769x2_SetRegister(T18kCoeffa5, 0x02A0, 2); // 18k Temp a5

    // BQ769x2_SetRegister(T18kCoeffb1, 0xFE8D, 2); // 18k Temp b1

    // BQ769x2_SetRegister(T18kCoeffb2, 0x02C4, 2); // 18k Temp b2

    // BQ769x2_SetRegister(T18kCoeffb3, 0xF256, 2); // 18k Temp b3

    // BQ769x2_SetRegister(T18kCoeffb4, 0x13BB, 2); // 18k Temp b4

    // BQ769x2_SetRegister(T18kAdc0, 0x2DB7, 2); // 18k ADC 0

    // 'VCell Mode' - Enable 16 cells - 0x9304 = 0x0000; Writing 0x0000 sets the default of 16 cells

    // 0x003F for 6 cell

    // 0x007F for 7 cell

    BQ769x2_SetRegister(VCellMode, 0x3FFF, 2);

    // BQ769x2_SetRegister(FET_CONTROL, 0x1111, 2);

    // Enable protections in 'Enabled Protections A' 0x9261 = 0xBC

    // Enables SCD (short-circuit), OCD1 (over-current in discharge), OCC (over-current in charge),

    // COV (over-voltage), CUV (under-voltage)

    // BQ769x2_SetRegister(EnabledProtectionsA, 0xBC, 1);

    BQ769x2_SetRegister(EnabledProtectionsA, 0xFC, 1);

    // Enable all protections in 'Enabled Protections B' 0x9262 = 0xF7

    // Enables OTF (over-temperature FET), OTINT (internal over-temperature), OTD (over-temperature in discharge),

    // OTC (over-temperature in charge), UTINT (internal under-temperature), UTD (under-temperature in discharge), UTC (under-temperature in charge)

    // 0xF7

    BQ769x2_SetRegister(EnabledProtectionsB, 0xF7, 1);

    BQ769x2_SetRegister(EnabledProtectionsC, 0x56, 1);

    BQ769x2_SetRegister(ProtectionConfiguration, 0x0602, 2);

    BQ769x2_SetRegister(CHGFETProtectionsA, 0x98, 1);

    BQ769x2_SetRegister(CHGFETProtectionsB, 0xD5, 1);

    BQ769x2_SetRegister(CHGFETProtectionsC, 0x56, 1);

    BQ769x2_SetRegister(DSGFETProtectionsA, 0xE4, 1);

    BQ769x2_SetRegister(DSGFETProtectionsB, 0xE6, 1);

    BQ769x2_SetRegister(DSGFETProtectionsC, 0xE2, 1);

    // 'Default Alarm Mask' - 0x..82 Enables the FullScan and ADScan bits, default value = 0xF800

    BQ769x2_SetRegister(DefaultAlarmMask, 0xF882, 2);

    // THERMISTOR / TEMPERATURE threshold

    BQ769x2_SetRegister(OTCThreshold, 0x50, 2);

    BQ769x2_SetRegister(OTCDelay, 0x02, 2);

    BQ769x2_SetRegister(OTCRecovery, 0x4F, 2);

    BQ769x2_SetRegister(OTDThreshold, 0x50, 2);

    BQ769x2_SetRegister(OTDDelay, 0x02, 2);

    BQ769x2_SetRegister(OTDRecovery, 0x4F, 2);

    BQ769x2_SetRegister(OTFThreshold, 0x50, 2);

    BQ769x2_SetRegister(OTFDelay, 0x02, 2);

    BQ769x2_SetRegister(OTFRecovery, 0x4F, 2);

    BQ769x2_SetRegister(OTINTThreshold, 0x55, 2);

    BQ769x2_SetRegister(OTINTDelay, 0x02, 2);

    BQ769x2_SetRegister(OTINTRecovery, 0x54, 2);

    BQ769x2_SetRegister(UTCThreshold, 0x00, 2);

    BQ769x2_SetRegister(UTCDelay, 0x02, 2);

    BQ769x2_SetRegister(UTCRecovery, 0x01, 2);

    BQ769x2_SetRegister(UTDThreshold, 0x00, 2);

    BQ769x2_SetRegister(UTDDelay, 0x02, 2);

    BQ769x2_SetRegister(UTDRecovery, 0x01, 2);

    // Set up Cell Balancing Configuration - 0x9335 = 0x03 - Automated balancing while in Relax or Charge modes

    // Also see "Cell Balancing with BQ769x2 Battery Monitors" document on ti.com

    // BQ769x2_SetRegister(BalancingConfiguration, 0x03, 1);

    BQ769x2_SetRegister(BalancingConfiguration, 0x00, 1);

    // Set up CUV (under-voltage) Threshold - 0x9275 = 0x31 (2479 mV)

    // 0x31 to dec *50.6

    // CUV Threshold is this value multiplied by 50.6mV

    // 0x29 = 2.074 volt, // 0x20 = 1.619 volt, // 0x39 = 2.88, // 0x38 = 2.83 // 0x32 = 2.530 || 0x17 = 1.163

    // 0x3A = 2.934 volt, // 0x3E = 3.1372 volt

    // BQ769x2_SetRegister(CUVThreshold, 0x48, 1);

    // BQ769x2_SetRegister(CUVDelay, 0x01, 1);

    // BQ769x2_SetRegister(CUVRecoveryHysteresis, 0x02, 1);

    // BASED ON EXCEL SHEET 0x36 = 2.732 || 0x3B = 2.985 || 0x012C = 300*3.3 = 990 ms

    BQ769x2_SetRegister(CUVThreshold, 0x36, 1);

    BQ769x2_SetRegister(CUVDelay, 0x012C, 2);

    BQ769x2_SetRegister(CUVRecoveryHysteresis, 0x3B, 1);

    // Set up COV (over-voltage) Threshold - 0x9278 = 0x55 (4301 mV)

    // COV Threshold is this value multiplied by 50.6mV

    // 0x40 = 3.238 || 0x3F = 3.187 || 0x55 = 4.301 ||0x5B = 4.604 || 0x48 = 3.643 Volts || 0x47 = 3.592 ||0X53 = 4.199

    // BQ769x2_SetRegister(COVThreshold, 0x53, 1);

    // BQ769x2_SetRegister(COVDelay, 0x01, 1);

    // BQ769x2_SetRegister(COVRecoveryHysteresis, 0x02, 1);

    // BASED ON EXCEL SHEET 0x54 = 4.250 || 0x52 = 4.149 || 0x012C = 300*3.3 = 990 ms

    BQ769x2_SetRegister(COVThreshold, 0x54, 1);

    BQ769x2_SetRegister(COVDelay, 0x012C, 2);

    BQ769x2_SetRegister(COVRecoveryHysteresis, 0x52, 1);

    // Set up OCC (over-current in charge) Threshold - 0x9280 = 0x05 (10 mV = 10A across 1mOhm sense resistor) Units in 2mV

    BQ769x2_SetRegister(ProtectionsRecoveryTime, 0x05, 1);

    ///:Recovery:Time

    BQ769x2_SetRegister(DAConfiguration, 0x05, 1);

    BQ769x2_SetRegister(DsgCurrentThreshold, 10000, 2);

    // BQ769x2_SetRegister(ChgCurrentThreshold, 3000, 2);

    // Safety over current discharge threshold.

    // BQ769x2_SetRegister(SOCDThreshold, 0x2000, 2);

    // BQ769x2_SetRegister(SOCDDelay, 0x01, 1);

    // Set up OCC (over-current in charge) Threshold - 0x9280 = 0x05 (10 mV = 10A across 1mOhm sense resistor) Units in 2mV

    // 0x05

    BQ769x2_SetRegister(OCCThreshold, 0x08, 1);

    BQ769x2_SetRegister(OCCDelay, 0x01, 1);

    BQ769x2_SetRegister(OCCRecoveryThreshold, 0x0001, 2);

    // Set up OCD1 Threshold - 0x9282 = 0x0A (20 mV = 20A across 1mOhm sense resistor) units of 2mV

    BQ769x2_SetRegister(OCD1Threshold, 0x12, 1);

    BQ769x2_SetRegister(OCD1Delay, 0x01, 1);

    BQ769x2_SetRegister(OCD2Threshold, 0x14, 1);

    BQ769x2_SetRegister(OCD2Delay, 0x01, 1);

    BQ769x2_SetRegister(OCD3Threshold, 0x16, 1);

    BQ769x2_SetRegister(OCD3Delay, 0x01, 1);

    BQ769x2_SetRegister(OCDRecoveryThreshold, 0x0001, 2);

    BQ769x2_SetRegister(OCDLRecoveryTime, 0x01, 1);

    BQ769x2_SetRegister(CCGain, 0x40F23055, 4);

    // BQ769x2_SetRegister(CapacityGain, 0x64, 1);

    // BQ769x2_SetRegister(CoulombCounterOffsetSamples, 0xFA00, 2);

    // BQ769x2_SetRegister(BoardOffset, 0xFA00, 2);

    // Set up SCD Threshold - 0x9286 = 0x05 (100 mV = 100A across 1mOhm sense resistor) 0x05=100mV

    BQ769x2_SetRegister(SCDThreshold, 0x04, 1);

    // Set up SCD Delay - 0x9287 = 0x03 (30 us) Enabled with a delay of (value - 1) * 15 µs; min value of 1

    BQ769x2_SetRegister(SCDDelay, 0x03, 1);

    // Set up SCDL Latch Limit to 1 to set SCD recovery only with load removal 0x9295 = 0x01

    // If this is not set, then SCD will recover based on time (SCD Recovery Time parameter).

    BQ769x2_SetRegister(SCDLLatchLimit, 0x01, 1);

    BQ769x2_SetRegister(FETStatus, 0x3F, 1);

    BQ769x2_SetRegister(MfgStatusInit, 0x00D0, 2);

    BQ769x2_SetRegister(PrechargeStartVoltage, 0x0C80, 4);

    BQ769x2_SetRegister(PrechargeStopVoltage, 0X0CE4, 4);

    // BQ769x2_SetRegister(PredischargeStopDelta, 50, 2);

    BQ769x2_SetRegister(PredischargeTimeout, 0xFF, 2);

    // Security

    BQ769x2_SetRegister(SecuritySettings, 0x00, 1);

    BQ769x2_SetRegister(UnsealKeyStep1, 0x0414, 2);

    BQ769x2_SetRegister(UnsealKeyStep2, 0x3672, 2);

    BQ769x2_SetRegister(FullAccessKeyStep1, 0xFFFF, 2);

    BQ769x2_SetRegister(FullAccessKeyStep2, 0xFFFF, 2);

    BQ769x2_SetRegister(CommType, 0x09, 1);

    // Exit CONFIGUPDATE mode - Subcommand 0x0092

    CommandSubcommands(EXIT_CFGUPDATE);

    }

  • 上电状态以及在bqstudio上读取数据储存器的值发现主控并没有写入bq76952