Hello,
I want to set up serial communication between a Teensy 3.6 and a bq76PL455A-Q1 integrated circuit.
I am trying to do a basic read of the IC's device address register after I set the register value to 0. However, I am only receiving 0xFF from the IC's tx line and Serial1.available() returns 0 as well. I presume that I am receiving 0xFF (all 1's) because the default state for idling (not communicating/transmitting) is 1.
setup:
#include <Arduino.h>
#include "helper.h"
#include "init.h"
const int WAKEUP = 32;
// On Teensy, Serial1 goes to pins 0 & 1
void setup() {
Serial1.begin(250000); // sets data rate to 250000 bps
Serial.begin(9600);
delay(1000);
Serial.println("testing has begun");
// WAKEUP bq device
pinMode(WAKEUP, OUTPUT);
digitalWrite(WAKEUP, HIGH); // bq will wake up and enter IDLE state
delay(1000);
digitalWrite(WAKEUP, LOW); // after applying high signal, pin must de-assert to allow it to enter shutdown again
delay(1000);
initialize(); // request sent to read device address register in this function
}
Send/receive over serial:
The helper functions to actually provide the values to read/write are directly from the sample code provided by Texas Instruments. I have verified the messages are correct by referencing the software design reference (https://www.ti.com/lit/an/slva617a/slva617a.pdf?ts=1619208779720)
void sciSend(uint32_t len, uint8_t * data) {
int j = 0;
uint8_t toSend[len];
Serial.println("Serial1.availableForWrite(): ");
Serial.println(Serial1.availableForWrite());
while ((len--) > 0) {
// copying contents of pointer into array:
toSend[j] = *data;
data++;
j++;
}
Serial1.write(toSend, sizeof(toSend));
Serial1.flush();
delay(500);
// sending data all at once:
Serial.println("data we are sending: ");
for (int i = 0; i < (int)sizeof(toSend); i++) {
Serial.println(toSend[i], HEX);
}
}
void sciReceive(uint32_t len, uint8_t * data) {
int i = 0;
Serial.println("printing serial1.available: ");
Serial.println(Serial1.available());
Serial.println("reading back dev address ");
Serial.println("expected output 00 00 00 00");
//while ((len--) > 0 && Serial1.available() > 0) {
while ((len--) > 0) {
//*data = Serial1.read();
Serial.println(Serial1.read(), HEX);
//Serial.println(*data, HEX);
data++;
i++;
}
}
What I am seeing on the serial monitor:
data we are sending:
81
0
A
0
2E
9C
printing serial1.available():
0
reading back device address
expected output 00 00 00 00
FF
FF
FF
FF
Is there anything you can think of that could be the reason why I'm not receiving values from the IC over the Serial1 line? I have verified that the rx/tx connections are correct and that the baudrate is correct with an oscilloscope. Additionally, when I do a serial1.availableForWrite() I get back 63.