PaulS
Well-known member
OK, I installed https://github.com/MarkusLange/Teensy_3.x_4.x_and_LC_LIN_Master .
Your code compiles fine now. I will dive into it now.
Paul
Your code compiles fine now. I will dive into it now.
Paul
#include "lin_bus.h"
LIN lin(&Serial3, 19200);
int lin_cs = 32;
uint8_t data[8];
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(lin_cs, OUTPUT);
digitalWrite(lin_cs, HIGH);
}
void loop() {
lin.order(24, 0, 0);
Serial.println(lin.response(24, data, 8), HEX);
digitalToggle(LED_BUILTIN);
delay(100);
}
Thanks for letting me know. I will update that. Here is the attachment that should be shown at that link.PS: the link to the LIN interface on the WIKI page seems not active
I would like to suggest the following minimal code:
That would pin FAULT.I have continuity with the multi-meter from pin 32 to breakout board at both 3.3V pins and on the MCP2004 Chip, I am getting continuity on one of the pins. Either LIN_TXD or LIN_FAULT. Cannot tell which, but here is a photo. Pin that is pinging is the one on the bottom row second from the right.
Without this analyzer, will I be able to see data output on the serial monitor or plotter?To verify whether data is actually outputted using my code, I hooked up the logic analyzer to pin TX3. It is:
No, my code is not doing that.Paul. When I compiled your code above, the board connects and disconnects and connects again every 10 seconds. Should it be doing that?
HVH shall be a LIN slave node following the LIN specification pacakge 2.1
.Enhanced Checksum
by adding the "lin2x" parameter.#include "lin_bus.h"
LIN lin(&Serial3, 19200);
int lin_cs = 32;
uint8_t data[8];
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(lin_cs, OUTPUT);
digitalWrite(lin_cs, HIGH);
}
void loop() {
lin.order(24, 0, 0, lin2x);
Serial.println(lin.response(24, data, 8, lin2x), HEX);
digitalToggle(LED_BUILTIN);
delay(100);
}
Yes, you should. The LA is only reading the data on the TX3 line. If a had an actual LIN device, I probably would have seen the response data as well.Without this analyzer, will I be able to see data output on the serial monitor or plotter?
Pin 1 (RX) is reading 3.3V while code is running. Nothing from Pin 2.Important is that pin 2 of the MCP2004 is HIGH when the code is active.
Pin1 (RXD) reading HIGH is normal. Only during a LIN message (~5ms) it can go LOW. See LA screenshot.Pin 1 (RX) is reading 3.3V while code is running. Nothing from Pin 2.
pinMode(lin_cs, OUTPUT);
digitalWrite(lin_cs, HIGH);
drive Teensy pin 32 HIGH.#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, lin2x) >=0) // -1 indicates crc error, 9600
//if (lin.response(24, data, 8, lin2x) >=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("Temp:");
Serial.print(tmpheater);
Serial.print(",");
Serial.print("Udc:");
Serial.print(udcheater);
Serial.print(",");
Serial.print("Power:");
Serial.println(powerheater);
}
if (read)
{
lin.order(22, 0, 0, lin2x); // 9600
//lin.order(24, 0, 0, lin2x); /// 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;
}
Shorter code was disconnecting with or without it connected to the Webasto.If so, what happens if you disconnect the Webasto device?
Yeah, that's a good sign. Perhaps there should be some time between lin.order() and lin.response()?Paul, I know we were pulling things back, but when I included your lin2x into the longer code, the board stays connected with and without WEBASTO connected AND pin 2 is now showing 3.3V, so a good sign, no? I need to go test it in the garage now with the heater on.
I am floating between 9600 and 19200 because the OI guys found their webasto was at 9600 . . . so I try both every time . . . not sure if there is a way to sniff the baud rate with a simple program.Yeah, that's a good sign. Perhaps there should be some time between lin.order() and lin.response()?
I also saw that you reverted back to 9600bps?
#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
LIN lin;
int lin_cs = 32; // cs and serial port set for skpang LIN / FDCAN board
uint8_t data[8];
void blinkLED() {
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(lin_cs, OUTPUT);
digitalWrite(lin_cs, HIGH);
myTimer.begin(blinkLED, interval);
//LIN l(&Serial3, 9600);
LIN l(&Serial3, 19200); /// Change to this for 19200 /////
lin = l;
}
void loop() {
lin.order(22, 0, 0, lin2x);
Serial.println(lin.response(22, data, 8, lin2x), HEX);
digitalToggle(LED_BUILTIN);
delay(100);
}
Weird, adding a timer that stops disconnecting...Paul, once I added in the blink LED to your shorter code, it stopped disconnecting and I am getting the blinking amber light.
0xFFFFFFFF means that it is reading HIGH's only. HIGH is the default state of the DATA line. And 0xFFFFFFFF is only 4 bytes - you would expectWith the heater disconnected, I am getting this on the Serial Monitor: FFFFFFFF
lin.response(22, data, 8, lin2x
to read 8 bytes.