Handling Incoming Data via SPI-UART Bridge

Finally got communication with a device that runs at 921.6k by using a bridge.

New problem is learning how to handle the incoming data. I’m not really sure if there is already a buffer that I can pull bytes from, or if need to create one i the software. Either way, the eventual goal is to send a request to the external device (trigByte to “Demon”), then receive and parse an incoming string of hex bytes into an array for processing. The string is 66 hex bytes long and looks something like this:

4F5454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545401C801B001B301B301B64F47

(Note, the 54’s are nulls as the device did not have any data coming into its serial stream at the time of capture)

…and this is the current code, for communicating back and forth with RealTerm for proof of concept:

//Load Libraries:
#include <SPI.h>
#include <Wire.h>
#include <SC16IS750.h>
#include <string.h>

//Initialize SPI UART Bridge:
SC16IS750 spiuart = SC16IS750(SC16IS750_PROTOCOL_SPI,6);

//Declare Variables:
String inputString = ""; //Debug string

int delayTime = 1000; //global dwell time
int packetSize = 66; //Expected Incoming Packet Size

byte TrigByte = 0x64;  //requests data packet from Demon
byte inputBuffer[66];   //Data buffer from bridge
byte UnoByte = 0;      //Data received from Serial Monitor

void setup() 
{
  Serial.begin(115200); //Initialize Uno UART
  spiuart.begin(921600); //Initialize SPI UART bridge
}

void loop()
{
  delay(delayTime);
  int Count = 0; //Index counter
  Serial.println("Debug_Data:");
  Serial.println(inputString); //Print Debug String
  
    
  while(Count < 66)
  {
  //Update Display
  Serial.print("Byte");
  Serial.print(Count + 1);
  Serial.print(" = ");
  Serial.println(inputBuffer[Count]);
  delay(delayTime/10);
  Count++;
  }  
  
  delay(delayTime);
  //Pass data from serial monitor to bridge:
  while(Serial.available() > 0)
  {
    Serial.println("Reading_Monitor...");
    UnoByte = Serial.read(); //Read byte from serial monitor
    delay(delayTime);
    Serial.println("Pinging_Demon");
    spiuart.write(UnoByte); //Pass to bridge
    delay(delayTime);
    Serial.println("Complete.");    
  }
  
  delay(delayTime);
  
  //If no data, report then zero out array
  if(spiuart.available() == 0)
  {
    Serial.println("No_packet_available");
    for (int i = 0; i < packetSize; i++)
    inputBuffer[i] = 0;
    delay(delayTime);
  }
  
  //Pass data from bridge to serial monitor:
  while(spiuart.available() > 0)
  {
    Serial.println("Reading_Data...");
    byte inChar = spiuart.read();
    inputString += inChar; //add data to string for debug
    for(int i = 0; i < packetSize; i++)
    inputBuffer[i] = inChar; 
    Serial.println("Complete");
  }
}

Currently, my debug string looks like this:

7965065065790797901065790650797979441007907979444479794479100447979651044104479797979044044791044104465795252

and it’s only loading the last byte into the array as every value displays as “52.”

How do I get everything into the array correctly and then display each value?

This is my current setup, btw:

Made a few changes, I’m now getting a consistent response and loading/reporting my array, but I’m only getting the first value and everything else is null:

while(Count < packetSize)
  {
  //Update Display
  char value = inputBuffer[Count];
  Serial.print("Byte");
  Serial.print(Count + 1);
  Serial.print(" = ");
  Serial.println(value);
  Count++;
  delay(delayTime/10);
  }
  //Get data from Demon:
  inputString = ""; //clear input string
  //int i = 0; //clear index
  while(spiuart.available() > 0)
  {
    Serial.println("Reading_Data...");
    for(int i = 0; i < packetSize; i++)
    {
      byte inChar = spiuart.read();
      inputString += inChar; //add next byte to string for debug
      inputBuffer[i] = inChar; 
    }
    Serial.println("Complete");
  }

The debug string:

52255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255