Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in the bq769x2_set_switches #87

Open
vlebedev-ora opened this issue Dec 19, 2024 · 1 comment
Open

Bug in the bq769x2_set_switches #87

vlebedev-ora opened this issue Dec 19, 2024 · 1 comment

Comments

@vlebedev-ora
Copy link

err = bq769x2_direct_read_u1(dev, BQ769X2_CMD_FET_STATUS, &fet_status.byte);
if (err != 0) {
return err;
}
/* only lower 4 bytes relevant for FET_CONTROL */
fet_status.byte &= 0x0F;
if (switches & BMS_SWITCH_CHG) {
fet_status.CHG_FET = enabled ? 1 : 0;
}
if (switches & BMS_SWITCH_DIS) {
fet_status.DSG_FET = enabled ? 1 : 0;
}
if (switches & BMS_SWITCH_PDSG) {
fet_status.PDSG_FET = enabled ? 1 : 0;
}
if (switches & BMS_SWITCH_PCHG) {
fet_status.PCHG_FET = enabled ? 1 : 0;
}
err = bq769x2_subcmd_write_u1(dev, BQ769X2_SUBCMD_FET_CONTROL, fet_status.byte);
if (enabled) {
err |= bq769x2_subcmd_cmd_only(dev, BQ769X2_SUBCMD_ALL_FETS_ON);
}
return err == 0 ? 0 : -EIO;
}

The code he assumes that the FET CONTROL subcommand argument is organized the same way as FET STATUS
register. This assumption is WRONG - the argument is organized as FET CONTROL register!!!!

See:
https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/1453973/bq76952-possible-error-in-technical-reference-manual-concerning-fet-control/5577692#5577692

@vlebedev-ora
Copy link
Author

To handle this problem we did the following:

  1. We defined the SWITCH flags to match FET_CONTROL register
#define BQ769x2_SWITCH_DSG (1 << 0)
#define BQ769x2_SWITCH_PDSG (1 << 1)
#define BQ769x2_SWITCH_CHG (1 << 2)
#define BQ769x2_SWITCH_PCHG (1 << 3)
  1. We created function:
/**
 * @brief Switch the specified MOSFET(s) on (Non specified will be blocked).
 *
 * @param dev Pointer to the device structure for the driver instance.
 * @param switches MOSFET(s) to switch on (See BQ769x2_SWITCH_*).
 *
 * @return 0 for success or negative error code otherwise.
 */
BQ769x2_API int bq769x2_enable_switches(const struct bq769x2 *dev,
					uint8_t switches)
{
	uint8_t fet_control;
	int err;

	fet_control = ~switches & 0x0f;

	err = bq769x2_subcmd_write_u1(dev, BQ769X2_SUBCMD_FET_CONTROL,
				      fet_control);

	return err == 0 ? 0 : -EIO;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant