Communication problem with hdq

Hello friends, I am currently trying to establish communication via HDQ with a BQ2019 battery monitor, the situation is that I have not been able to get the Arduino UNO to work and I have not been able to read or write to the device, the code I use is the following:

#include <OneWire.h>

#define HDQ_PIN 7 // Pin de datos HDQ conectado al Arduino

OneWire oneWire(HDQ_PIN); // Inicializa la comunicación OneWire

// Función para enviar un "break" (reset de comunicación) al BQ2019
void hdq_send_break() {
  pinMode(HDQ_PIN, OUTPUT);
  digitalWrite(HDQ_PIN, LOW);  // Mantener la línea baja
  delay(250);                  // Mantener bajo por 250 microsegundos para un break
  digitalWrite(HDQ_PIN, HIGH); // Liberar la línea (alta)
  delay(250);                  // Esperar 250 microsegundos antes de continuar
}

// Función para escribir un byte en HDQ
void hdq_write_byte(uint8_t byte) {
  oneWire.reset();  // Resetear la línea 1-Wire antes de enviar datos
  oneWire.write(byte);  // Enviar el byte
}

// Función para leer un byte en HDQ
uint8_t hdq_read_byte() {
  oneWire.reset();  // Resetear la línea 1-Wire antes de leer
  return oneWire.read();  // Leer el byte
}

// Función para leer de una dirección específica del BQ2019
uint8_t hdq_read_register(uint8_t address) {
  hdq_send_break();        // Enviar un "break" antes de cada comunicación
  hdq_write_byte(address); // Enviar dirección de lectura
  return hdq_read_byte();  // Leer el valor del registro
}

// Función para leer un rango de direcciones de memoria
void leer_rango_memoria(uint8_t start_address, uint8_t end_address) {
  for (uint8_t address = start_address; address <= end_address; address++) {
    uint8_t value = hdq_read_register(address);  // Leer el valor del registro
    Serial.print("Dirección 0x");
    Serial.print(address, HEX);
    Serial.print(": 0x");
    Serial.println(value, HEX);
  }
}

void setup() {
  Serial.begin(9600);  // Iniciar la comunicación serial

  // Leer todas las direcciones desde 0x00 hasta 0x7F
  Serial.println("Leyendo registros desde 0x00 hasta 0x7F:");
  leer_rango_memoria(0x00, 0x7F);  // Leer el rango completo
}

void loop() {
  // No se requiere código en el loop en este caso, ya que la lectura se hace en setup()
}

In the Serial Monitor onli appear 0xFF

Thank You

I did a search for Arduino examples for the BQ2019 with the HDQ interface, and couldn't find any that are reported to work.

HDQ is somewhat similar, but certainly not equivalent to oneWire, so I'm wondering where the code you posted came from, and why you think it could work.

Do you have the required pullup on the data line?

There is this library, but it clearly has not been widely used or adopted:

Thank you very much for your answer, there is indeed not much information about the HDQ protocol and most likely it was OneWire and that is why I made that code to test, I am going to do tests with the library you sent and any progress I will be publishing, best regards

TI published a detailed description of the HDQ protocol, just no usable Arduino example.

It is very clear that the OneWire library will not work as the timings are different.

Given the lack of support provided by TI, it is probably best to find a battery gauge IC with a standard communications protocol.

The situation is that these are batteries for devices that come from the factory with the BQ2019, perhaps the manufacturer does this because of the difficulties in making any adjustments to it, in that case I will be the first to do it and I will gladly share the achievements with the community.

star_border

Hi. Any progress? Interested in the same topic but started only yesterday. Believe to have a good understanding of the requirements and will review to target the RP2350 / RP2040 due to the PIO state machines which will be able to meet the timings. Also, would you have a logic analyzer for the HDQ interface? It appears that zeroplus (Taiwan) has a free plug-in for this interface. We have a few of their tools in the lab. Will update this thread once we make some progress. Thanks.

Update: Zeroplus does offer a decoder for their LA tools. See attached.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.