Not receiving anything over serial line

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.

Welcome to the forum.

From you description, I do not believe you get any data back. You commented the Serial1.available. That function will tell you when you received a character. If you call Serial.read() without a Serial.available the result is unpredictable (unless you look into the source code of the library).

You have an oscilloscope. See if you get any data back. The line will need to go from HIGH to LOW for the startbit even if all data bits are HIGH. If it stays HIGH all the time, you do not get anything back.

Not quite true; it is predictable :wink: Serial.read() returns an int and the value will be -1 if there was nothing to read.

This is very common in communication (serial, ethernet, ...) and also applies in the world of computers (PCs).

1 Like

@sterretje Now that I looked at the source code for Serial, you are right. Thanks.

@rg65 The error code of Serial.read() is -1 that is 0xFFFF in an int data type (the method signed numbers are stored is called two's complement).

Hello! Thank you for your responses. I took @sterretje 's advice and used Serial.available in a SerialEvent1 function that mimics an interrupt sequence when data is on the port:

void loop() {
  ReadReg(0, 10, &wTemp, 1, 0);
}

/*
 * SerialEvent1 occurs whenever a new data comes in the hardware serial RX
 * routine is run between each time loop() runs
 */
void serialEvent1() {
  while (Serial1.available()) {
    // get the data on the port and print out
    byte inByte = Serial1.read();
    Serial.println(inByte);
  }
}

However, I wasn't getting back any data because Serial1.available() was never > 0. Is there any other reason why the comms isn't working?

Can you provide a schematic (hand drawn is OK)?

Do you have a module for the bq76PL455A-Q1 or did you build you own PCB? Can you provide a link if it is a module?

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