Parsing CANBUS data from a Honeywell CSNV700 sensor

Hi. I am having problems with the Honeywell flux sensor. I am able to get a reading which is in bytes which I need to then convert to bits and use the start bit and length (provided in info sheet) in order to get a reading.

I am able to get this reading printing to the serial monitor, but I need help with converting this value.

Essentially, how do I take a string which is in bytes and split it into bits,a nd then translate those bits into readable data.

I am using the Teensy 4.0 Triple Can Board: Teensy 4.0 Triple CAN Board with 240x240 IPS LCD and uSD holder — SK Pang Electronics Ltd

Data sheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/aero-and-transportation-sensing/aero-and-transportation-sensors/electric-vehicles-sensors/csnv700-series/documents/sps-sst-csnv700-series-current-sensor-datasheet-006009.pdf?download=false

Is this a student project? If so, is decoding the data a key part of your project?

bitRead() will allow you to inspect the individual bits within a byte.
You can build a number by multiplying each bit value by the 2^n bit position in the destination 32 bit unsigned long type.

1 Like

Hint every byte is 8 bits so that part is already done, now you need to determine what ;you want to do with them.

1 Like

I'm doing this project to try to get readings for a current sensor. Decoding is not necessarily part of the project, but right now I'm stuck because the sensor is giving me readings ex 1234567890 that I'm not sure how to translate so I'm assuming decoding is the next step? I tried using bitRead() but I'm not sure what to do with the bits after. I do have the start bit and length of the data but I'm not sure if I should translate to binary, hex, or is there some other step I am missing?

Show the code you have written.

You can contact a Honeywell apps engineer and ask for help and if there are any application notes explaining how to use it. I looked for a bit and did not find any.

This is the code I have written

#include <Wire.h>
#include <SparkFunADXL313.h>
#include <SD.h>
#include <SPI.h>
#include <FlexCAN_T4.h>
#include <ST7735_t3.h>
#include <ST7789_t3.h>
#include <SparkFun_Qwiic_OLED.h>

FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;

#define TFT_RST    9
#define TFT_DC     8
#define TFT_MOSI   11
#define TFT_SCLK   13
#define TFT_CS     10
#define SD_CS     7

ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
IntervalTimer timer;
uint8_t d=0;
bool stopfd = 0;
File myFile;
ADXL313 myAdxl;
bool accelReady = false;
String fileName = "test";
String fileType = ".txt";
String file = fileName + fileType;
int fileNum = 1;
bool header = false;

int len1 = 0;
int len2 = 0;
int lenFD = 0;

int byte1;
int byte2;
int byte3;
int byte4;

String id1;
String id2;
String idFD;
String idhit1;
String idhit2;
String data1;
String data2;
String dataFD;
bool newData1 = true;
bool newData2 = true;
bool newDataFD = true;

const int IP_VALUE_START_BIT = 24;
const int IP_VALUE_LENGTH = 32;

int convertIPValue(int decimalValue) {
  byte1 = bitRead(decimalValue, 1);
  byte2 = bitRead(decimalValue, 2);
  byte3 = bitRead(decimalValue, 3);
  byte4 = bitRead(decimalValue, 4);
  
  Serial.print("byte1: ");
  Serial.print(byte1);
  Serial.print("byte2: ");
  Serial.print(byte2);
  Serial.print("byte3: ");
  Serial.print(byte3);
  Serial.print("byte4: ");
  Serial.print(byte4);
  


/*
  if (decimalValue == 0x80000000) {
    return 0;
  } else if (decimalValue == 0x80000001) {
    return 1;
  } else if (decimalValue == 0x7FFFFFFF) {
    return -1;
    */
  }
  
  /*if (decimalValue >= 0x80000001) {
    return decimalValue - 0x80000001;
  } else if (decimalValue == 0x7FFFFFFF) {
    return -1;
  } else if (decimalValue == 0x80000000) {
    return 0;
  }*/
  
 // return 9;  // Default value



void setup() {
  Serial.begin (9600);
  Wire.begin();
  
  pinMode(6, OUTPUT);
  digitalWrite(6, LOW);
 
  can2.begin();
  can2.setBaudRate(500000);
  can2.enableFIFO();
  can2.enableFIFOInterrupt();
  can2.onReceive(canSniff2);

  Serial.print("LEN2\t");
  Serial.print("ID2\t");
  Serial.print("IDHIT2\t");
  Serial.print("DATA2\t\t\t\t");
  Serial.print("IPVAL\t\t");
  Serial.print("EINFO\t");
  Serial.print("EIND\t");
  Serial.print("VAC\t");
  Serial.println("CRC8");

  // ... [Rest of your setup code]
}

void loop() {
  delay(100);
  
  if (!id2.equals("") && newData2) {
    Serial.print(len2);
    Serial.print("\t");
    Serial.print(id2);
    Serial.print("\t");
    Serial.print(idhit2);
    Serial.print("\t");
    Serial.print(data2);
    Serial.print("\t");
    
    if(data2.length()<13){
      Serial.print("\t");
    }
    //int ipValue = convertIPValue(data2.toInt());
    convertIPValue(data2.toInt());
    //Serial.print(ipValue);
    Serial.print("\t");

    // ... [Your existing serial print statements]

    newData2 = false;
  } else {
    Serial.print("\t");
    Serial.print("\t");
    Serial.print("\t");
    Serial.print("\t");
  }
  
  can2.events();
  Serial.println();
}

void canSniff2(const CAN_message_t &msg) {
  len2 = msg.len;
  id2 = String(msg.id, HEX);
    idhit2 = (String)msg.idhit;
    data2 = "";
    
    for (uint8_t i = 0; i < msg.len; i++) {
      data2 = data2 + (String)msg.buf[i];
    }
    
    newData2 = true;
  }



I will try contacting them right now :+1:

Hi, @jason123chat
Welcome to the forum.

Can I suggest you cut your code down, or write new code to just deal with the CSN sensor.
Use Serial print to output and get rid of the display code/hardware etc.

This will enable to concentrate on one device at a time.

Also Serial.begin (9600);
change to
Serial.begin (115200);

Much quicker, just don't forget to change the IDE serial monitor to 115200.

Tom.. :grinning: :+1: :coffee: :australia:

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