Hello,
I´m trying to read data from serial port of a BQ76455PL from TI.
This device expect the following message 89 01 00 0A 00 DA 83 and I should have as response 00 01 C1 C0 (response). It could be consulted in the document slva617a.
I´m trying to send it by Serial3 and I want to receive the data by Serial. When I push a button, i send "uint8_t msg[7] = {0x89, 0x01, 0x00, 0x0A, 0x00, 0xDA, 0x83};" to the other device. The problem in this case is to read the received data on Serial3 and send to Serial.
My sketch is the following.
int boton = 7;
int val;
uint8_t msg[7] = {0x89, 0x01, 0x00, 0x0A, 0x00, 0xDA, 0x83}; //Mensaje que tengo que enviar para recibir el siguiente mensaje.
uint8_t response[24];
void setup() {
//Ponemos el botón como entrada.
pinMode(boton, INPUT);
//Inicializamos ambos puertos serie del arduino
Serial.begin(250000); //Puerto donde va conectado el USB
Serial3.begin(250000); //Puerto 3
}
void loop() {
//Aquí si pulsamos el botón, mandamos la secuencia msg hacia el BMS
val=digitalRead(boton); //Guardo valor actual del boton
if(val == HIGH)
{ //Si el valor es High
Serial3.write(msg,sizeof(msg)); //envío el mensaje msg mediante el puerto 3 hacia el BMS
if (Serial3.available())
{
Serial.print("Mensaje enviado");
delay(1000);
}
}
// Queremos leer desde el puerto 3 (BMS) y enviarlo al puerto 0 (para leer con el PC)
if (Serial3.available()) {
//Queremos leer una cadena de 5 hexadecimales 00 01 C1 C0
Serial3.read() = uint8_t response; //lo que quiero hacer es leer el puerto serie3 (BMS) y escribir en el puerto 0 (PC)
Serial.write(response, sizeof response); //Aquí el dato rec (recibido) quiero escribirlo en el puerto 0
}
}
Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).
although not totally applicable to binary communication, you should study Serial Input Basics to get a better grasp on how to handle an asynchronous communication
I Did it all, I´m conected as I said, and i have GND of the BQ to my arduino. The voltage is 5V.
My principal problem is to communicate the port 3 with the port 0 and have a response.
In my 1st test i had this code.
// read from port 3, send to port 0:
if (Serial3.available()) {
int inByte = Serial3.read();
Serial.write(inByte);
With this code i receive a strange message. Only 1 word, but i received something, i think....
It works, But I only receive characters like ??????????????????????????????? (with my code, a lot of characters... my PC stop working xD) or ڃ ڃ ڃ ڃ ڃ ڃ (only one character with your code)
I dont know whats the problem. I think it could be baud rate, but Datasheet says that the baud rate its 250K...
No, no.
BQ76PL455A is a Battery management system.
it has an WAKEUP pin that I think i need to excite to active the BQ and have a response. Ill try it and i will say the results to you
Hello!! I tried to excite this pin without a good results..
I am receiving the same message that im sending...
This is the code that im using right now.
int wakeup = 2;
int led=3;
int boton2 = 5; //Boton wakeup
int val2;
int boton = 7;
int val;
uint8_t msg[7] = {0x89, 0x01, 0x00, 0x0A, 0x00, 0xDA, 0x83}; //Mensaje que tengo que enviar para recibir el siguiente mensaje.
uint8_t response[24]; //mensaje que quiero recibir, ha de ser este 00 01 C1 C0
void setup() {
//Ponemos el botón como entrada.
pinMode(boton, INPUT);
pinMode(boton2, INPUT);
pinMode(wakeup, OUTPUT);
pinMode(led, OUTPUT);
//Inicializamos ambos puertos serie del arduino
Serial.begin(250000); //Puerto donde va conectado el USB
Serial3.begin(250000); //Puerto 3
}
void loop() {
//WAKEUP
val2=digitalRead(boton2);
if (val2 == HIGH){
digitalWrite(wakeup,HIGH);
digitalWrite(led, HIGH);
}
else{
digitalWrite(wakeup,LOW);
digitalWrite(led, LOW);
}
//Aquí si pulsamos el botón, mandamos la secuencia msg hacia el BMS
val=digitalRead(boton); //Guardo valor actual del boton
if(val == HIGH){ //Si el valor es High
Serial3.write(msg,sizeof(msg)); // send the command
while (! Serial3.available()) ; // active wait for the first byte
size_t responseSize = Serial3.readBytes(response, sizeof response);
for (size_t i = 0; i < responseSize; i++) {
Serial.print(F("0x")); Serial.print(response[i], HEX);
Serial.write(' ');
}
Serial.println();
}
}