jsimonkeller
Well-known member
Hi. I was hoping someone could assist me with help on the serial plotter. I have been working with someone to sort code for LIN bus control of a HV heater on my EV build. The project was part of an STM32 programming, but we have converted over to Arduino and it compiles. I am wanting to use the serial plotter to determine is the signal is going out as it should. Below is the programming and I wondered what I need to change to get readings back on the serial plotter. Thanks!
Code:
#include "lin_bus.h"
// Create an IntervalTimer object
IntervalTimer myTimer;
int ledState = LOW; // ledState used to set the LED
unsigned long interval = 200000; // interval at which to blinkLED to run every 0.2 seconds
uint16_t Power = 175; // set to required power
uint8_t Temperature = 45; //set to required temperature
uint16_t tmpheater = 0;
uint16_t udcheater = 0;
uint16_t powerheater = 0;
LIN lin;
int lin_cs = 32; // cs and serial port set for skpang LIN / FDCAN board
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(lin_cs, OUTPUT);
digitalWrite(lin_cs, HIGH);
//Serial.begin(19200);
//Serial.print("HVH50 Heater demo");
myTimer.begin(blinkLED, interval);
LIN l(&Serial3, 9600);
// LIN l(&Serial3, 19200); /// Change to this for 19200 /////
lin = l;
}
void loop() {
// heater
SendLin();
delay(100); // wait 100ms
//Serial.print(" Heater test\n");
}
void blinkLED() {
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);
}
static void SendLin()
{
static bool read = true;
uint8_t data[8];
if (lin.response(22, data, 8) >=0) // -1 indicates crc error, 9600
//if (lin.response(24, data, 8) >=0) /// Change to this for 19200 /////
{
tmpheater = data[1] - 40;
udcheater = data[4] | (data[5] & 3) << 8;
powerheater =((data[5] >> 2) | (data[6] << 8)) * 20;
Serial.print("\n Temp ");
Serial.print(tmpheater);
Serial.print("\n Udc ");
Serial.print(udcheater);
Serial.print("\n Power ");
Serial.print(powerheater);
}
if (read)
{
lin.order(22, 0, 0); // 9600
//lin.order(24, 0, 0); /// Change to this for 19200 /////
}
else
{
uint8_t lindata[] = {uint8_t(Power/40), uint8_t(Temperature+40), 0, 8};
lin.order(21, lindata, 4); // this for 9600
//lin.order(35, lindata, 4); /// Change to this for 19200 /////
Serial.print("\n Sending power and temperature");
}
read = !read;
}