Go Down

Topic: Arduino Communication with a Texas Chip Over Serial (Read 337 times) previous topic - next topic

Rorschac

Hi, I have a BQ76PL455 ti. I want to communicate this chip with Arduino. But I did not find a way to send a hex. When I try to send the following code, the Arduino compiler gives an overload error.

Code: [Select]


void setup() {
 
Serial1.begin(250000);
}

void loop() {
 
    Serial1.write(0x8901000A00DA83);
  }
}




I added the PDF of the TI chip in case anyone wanted to review it.

http://www.ti.com/lit/an/slva617a/slva617a.pdf

Thank you from now.


el_supremo

You need to store each pair of hex digits as a separate byte:
uint8_t msg[] = {0x89, 0x01, 0x00, 0x0A, 0x00, 0xDA, 0x83};

and then you can write it like this:
Code: [Select]
Serial1.write(msg,sizeof(msg));

Pete
Don't send me technical questions via Private Message.

Rorschac

#2
Jun 13, 2018, 12:58 am Last Edit: Jun 13, 2018, 01:03 am by Rorschac
Thank you for your answer.

Also response will be hex too. Which variable should I save this response? Should I parse this coming message too?

el_supremo

Quote
Also response will be hex too.
No, it will be in binary which is also what you will send. Hex is just a way to represent the value in a byte. If a byte has a hex value of 0x12 you equally have written this in decimal as 18 or in binary as 0B00010010. If you're an old geezer like me you could even write it in octal as 022. They all represent the same quantity.

Quote
Which variable should I save this response?
Depends how long the response will be. You could also re-use this same variable for other responses, in which case you would declare it to be as long as the longest response that you are expecting. If all responses are going to be less than, for example, 20 bytes then I'd declare a variable to have 24 bytes just to be sure.
Code: [Select]
uint8_t response[24];

Quote
Should I parse this coming message too?
You should always check whatever response you get to make sure that whatever message you've just sent was received correctly.

Pete
Don't send me technical questions via Private Message.

Rorschac

I solved the problem, thank you. You're really very helpful. :)

GolamMostafa

#5
Jul 01, 2018, 01:38 pm Last Edit: Jul 01, 2018, 06:47 pm by GolamMostafa
I solved the problem, thank you. You're really very helpful. :)
But, there are questions to ask -- why the number 0x8901000A00DA83 is to be broken into byte oriented chunks in order to use this command:
Code: [Select]
Serial.write(msg, sizeof(msg));

The number can also be sent using this command: The number should not be sent in the following format as the the receiving instrument (Q76PL455 ti) demands natural binary numbers. See Post#6 of @el_supremo
Code: [Select]
Serial.print("8901000A00DA83");

Then, what are the merits and demerits of sending the number using either of the following two commands:
Code: [Select]
Serial.write(msg, sizeof(msg));
Serial.print("8901000A00DA83");

el_supremo

Quote
The number can also be sent using this command:
Code: [Select]
Serial.print("8901000A00DA83");
No it can't. That is not the same as sending this:
Code: [Select]
uint8_t msg[] = {0x89, 0x01, 0x00, 0x0A, 0x00, 0xDA, 0x83};
.
.
Serial1.write(msg,sizeof(msg));

which is what the device is expecting.

Pete
Don't send me technical questions via Private Message.

GolamMostafa

@el_supremo

You are right! The receiving device (Q76PL455 ti.) demands that the incoming bytes must be natural binary numbers.

Thank you for the prompt reply that helped me to convert my ignorance into knowledge.

Go Up