Can't Initialize Isabellenhütte ISA Sensor. [SOLVED]
- Gregski
- Posts: 2344
- Joined: Tue Sep 14, 2021 10:28 am
- Location: Sacramento, California
- Has thanked: 359 times
- Been thanked: 477 times
- Contact:
Re: Can't Initialize Isabellenhütte ISA Sensor.
fellas can we keep this on the downlow please, and I'm gonna hide it on the Web so no one can see it
"I don't need to understand how it works, I just need to understand how to make it work!" ~ EV Greg
-
- Posts: 170
- Joined: Sun Jan 03, 2021 6:12 am
- Has thanked: 52 times
- Been thanked: 17 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
Did your shunt talk in 0x680 and 0x620 IDs too? I'm having difficulty with mine.
I received similar ISA (only 1x port) and having difficulty initialising. I first hooked up Arduino Uno and followed: https://openinverter.org/wiki/Getting_s ... rduino_Uno
Arduino Uno spits out weird 0x680 and 0x620 IDs. When I try to filter for 0x521 (per https://openinverter.org/wiki/Getting_s ... bus_shield), I see nothing in the terminal.
I then hooked up to Due but it cannot seem to initialise I did follow https://openinverter.org/wiki/CAN_bus_with_Arduino_Due to ensure Due can talk CAN.
My current setup is: Arduino Due + Arduino Uno + ISA shunt. Bus is 60ohms - 2x 120ohm terminators. Uno is there to ensure Due does send data to the bus.
When I initialise from Due, my Uno sees the following - looks like correct init. data
But the ISA shunt keeps yelling the following by default. This is just a snippet for the continuos data.
Appreciate looking into this...
I received similar ISA (only 1x port) and having difficulty initialising. I first hooked up Arduino Uno and followed: https://openinverter.org/wiki/Getting_s ... rduino_Uno
Arduino Uno spits out weird 0x680 and 0x620 IDs. When I try to filter for 0x521 (per https://openinverter.org/wiki/Getting_s ... bus_shield), I see nothing in the terminal.
I then hooked up to Due but it cannot seem to initialise I did follow https://openinverter.org/wiki/CAN_bus_with_Arduino_Due to ensure Due can talk CAN.
My current setup is: Arduino Due + Arduino Uno + ISA shunt. Bus is 60ohms - 2x 120ohm terminators. Uno is there to ensure Due does send data to the bus.
When I initialise from Due, my Uno sees the following - looks like correct init. data
Code: Select all
-----------------------------
Get data from ID: 0x411
34 0 1 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
20 42 0 60 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
21 42 0 72 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
22 42 0 84 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
23 42 0 96 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
24 42 0 A8 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
25 42 0 BA 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
26 42 0 CC 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
27 42 0 DE 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
28 42 0 F0 0 0 0 0
-----------------------------
Get data from ID: 0x411
32 0 0 0 0 0 0 0
-----------------------------
Get data from ID: 0x411
34 1 1 0 0 0 0 0
Code: Select all
-----------------------------
Get data from ID: 0x680
6 D 0 0 0 0
-----------------------------
Get data from ID: 0x680
6 4 0 0 0 0
-----------------------------
Get data from ID: 0x620
0 E FF FF FF DB
-----------------------------
Get data from ID: 0x680
6 F 0 0 0 0
-----------------------------
Get data from ID: 0x680
6 5 0 0 0 0
-----------------------------
Get data from ID: 0x680
6 B 0 0 0 0
-----------------------------
Get data from ID: 0x680
6 1 0 0 0 0
-----------------------------
Get data from ID: 0x620
0 8 FF FF FF E7
-----------------------------
Get data from ID: 0x620
0 D FF FF FF E7
-----------------------------
Get data from ID: 0x680
6 4 0 0 0 0
-----------------------------
Get data from ID: 0x620
0 62 0 0 0 3E
-
- Posts: 170
- Joined: Sun Jan 03, 2021 6:12 am
- Has thanked: 52 times
- Been thanked: 17 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
These are my hardwares. For some reason PMs get stuck in the outbox. I use the shield with UNO and the tiny CAN transceiver with the DUE.
-
- Posts: 221
- Joined: Sun Feb 20, 2022 4:23 am
- Location: N. Wiltshire. UK
- Has thanked: 17 times
- Been thanked: 109 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
It looks like 0x620 is the current reading. You could try send 0x3D on byte 0 of ID 0x411 to reset to factory default settings, check CAN ids at this point and then initialise as before.
-
- Posts: 3283
- Joined: Mon Dec 24, 2018 1:37 pm
- Location: Slovenia
- Has thanked: 80 times
- Been thanked: 239 times
- Contact:
Re: Can't Initialize Isabellenhütte ISA Sensor.
Did you inspect the shunt for origin? Last year i got similar ISA shunt out from the Jaguar pack.alexbeatle wrote: ↑Tue Sep 26, 2023 5:03 am Did your shunt talk in 0x680 and 0x620 IDs too? I'm having difficulty with mine.
I received similar ISA (only 1x port) and having difficulty initialising.
....
Appreciate looking into this...
I recorded some messages of current. viewtopic.php?t=1282
You may have OEM programmed ISA.
-
- Posts: 170
- Joined: Sun Jan 03, 2021 6:12 am
- Has thanked: 52 times
- Been thanked: 17 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
No markings other than what I've posted above.arber333 wrote: ↑Wed Sep 27, 2023 9:26 pm Did you inspect the shunt for origin? Last year i got similar ISA shunt out from the Jaguar pack.
I recorded some messages of current. viewtopic.php?t=1282
You may have OEM programmed ISA.
Messaged ISA tech support and they said I should be able to reprogram it, but I don't think the shunt responds to 0x411 ID at the moment. The first data command on 0x411 ID is to put it in STOP. I'd assume it will stop posting messages on the CANbus, yet it still sends the 0x620 and 0x680 ID data.
I used this https://openinverter.org/wiki/Getting_s ... bus_shield to decode the data from 0x620 ID. I had to play with the code 'cause parts of code wouldn't compile for me, here's what worked.
Code: Select all
// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13
#include <SPI.h>
#define CAN_2515
// #define CAN_2518FD
// Set SPI CS Pin according to your hardware
#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)
// For Wio Terminal w/ MCP2518FD RPi Hat:
// Channel 0 SPI_CS Pin: BCM 8
// Channel 1 SPI_CS Pin: BCM 7
// Interupt Pin: BCM25
const int SPI_CS_PIN = BCM8;
const int CAN_INT_PIN = BCM25;
#else
// For Arduino MCP2515 Hat:
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
#endif
#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#endif
#ifdef CAN_2515
#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#endif
unsigned char len = 0;
unsigned char buf[8];
void setup() {
SERIAL_PORT_MONITOR.begin(115200);
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
delay(100);
}
SERIAL_PORT_MONITOR.println("CAN init ok!");
/*
set receive mask
*/
CAN.init_Mask(0, 0, 0x7ff); // there are 2 masks in mcp2515, you need to set both of them
CAN.init_Mask(1, 0, 0x7ff); // 0x7ff is '11111111111' in binary, so we are checking 11 of the CAN message ID bits
/*
set receive filter
*/
CAN.init_Filt(0, 0, 0x620); // there are 6 filters in mcp2515
CAN.init_Filt(1, 0, 0x620); // 0x521 is the CAN message ID for IVT-S Current value
CAN.init_Filt(2, 0, 0x620);
CAN.init_Filt(3, 0, 0x620);
CAN.init_Filt(4, 0, 0x620);
CAN.init_Filt(5, 0, 0x620);
}
void loop() {
if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if data coming
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned long canId = CAN.getCanId();
if (canId == 0x620) {
Serial.print("Data received from IVT_Msg_Result_I");
Serial.print("\t");
// Convert individual big endian byte values to actual reading
long reading = (buf[2] << 24) | (buf[3] << 16) | (buf[4] << 8) | (buf[5]);
Serial.println(reading);
}
}
// Refresh every 250ms
delay(250);
}
Code: Select all
Data received from IVT_Msg_Result_I -37
Data received from IVT_Msg_Result_I 25
Data received from IVT_Msg_Result_I 150
Data received from IVT_Msg_Result_I 37
Data received from IVT_Msg_Result_I 12
Data received from IVT_Msg_Result_I 0
Data received from IVT_Msg_Result_I 0
Data received from IVT_Msg_Result_I 125
Data received from IVT_Msg_Result_I -25
-
- Posts: 170
- Joined: Sun Jan 03, 2021 6:12 am
- Has thanked: 52 times
- Been thanked: 17 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
Tried this without success. Within the ISA.cpp there's deFAULT function. Added the case to the code. Triggered it, but no result. Still only receiving 0x680 and 0x620 IDs. Initialising after that doesn't work either.
Code: Select all
void ISA::deFAULT()
{
//Returns module to original defaults
outframe.id = 0x411; // Set our transmission address ID
outframe.length = 8; // Data payload 8 bytes
outframe.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.rtr=1; //No request
outframe.data.bytes[0]=0x3D;
outframe.data.bytes[1]=0x00;
outframe.data.bytes[2]=0x00;
outframe.data.bytes[3]=0x00;
outframe.data.bytes[4]=0x00;
outframe.data.bytes[5]=0x00;
outframe.data.bytes[6]=0x00;
outframe.data.bytes[7]=0x00;
canPort->sendFrame(outframe);
if(debug)printCAN(&outframe); //If the debug variable is set, show our transmitted frame
}
-
- Posts: 170
- Joined: Sun Jan 03, 2021 6:12 am
- Has thanked: 52 times
- Been thanked: 17 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
Ok. Some new findings.
Either after running the above factory reset command new IDs came out or after playing with the code I filtered for additional IDs.
0x620 - unknown. but I suspect this is where the current is read. having trouble finding 12VDC load with >1A. I think the sensor cannot read under 1A..
0x630 - V1 input
0x640 - V2 input
0x650 - V3 input
0x680 - unknow, some kind of counter. updates on its own, load or no load. maybe it's the runtime.. Vx inputs report FF FF FF and 00 00 00 when left floating, but always FF FF FF when tied to 0VDC. 12.09VDC reads as 00 00 2E. 12.56 reads as 00 00 30. 13.06 reads as 00 00 32.
example: Still looking for the current ID...
Sensor doesn't respond to 0x411 ID to reprogram. Can the program ID be changed!?
Either after running the above factory reset command new IDs came out or after playing with the code I filtered for additional IDs.
0x620 - unknown. but I suspect this is where the current is read. having trouble finding 12VDC load with >1A. I think the sensor cannot read under 1A..
0x630 - V1 input
0x640 - V2 input
0x650 - V3 input
0x680 - unknow, some kind of counter. updates on its own, load or no load. maybe it's the runtime.. Vx inputs report FF FF FF and 00 00 00 when left floating, but always FF FF FF when tied to 0VDC. 12.09VDC reads as 00 00 2E. 12.56 reads as 00 00 30. 13.06 reads as 00 00 32.
example: Still looking for the current ID...
Sensor doesn't respond to 0x411 ID to reprogram. Can the program ID be changed!?
-
- Posts: 221
- Joined: Sun Feb 20, 2022 4:23 am
- Location: N. Wiltshire. UK
- Has thanked: 17 times
- Been thanked: 109 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
According to the data sheet the command ID can be changed. As you have a Ardunio Due it may be better to run Savvycan which allows all messge to be seen. You could also go through all the IDs automatically until you find the correct command ID.
-
- Posts: 170
- Joined: Sun Jan 03, 2021 6:12 am
- Has thanked: 52 times
- Been thanked: 17 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
Brilliant! Thanks for your help!
For future somebody who will get in the similar situation and not a programmer just like me....
Setup SavvyCAN using this...https://openinverter.org/wiki/CAN_bus_with_Arduino_Due
Watch the video in the wiki to get yourself familiar with the SavvyCAN interface
Follow this tutorial for fuzzing.
You'll see a live data from sensor when connected.
I decided to "fuzz" with the STOP command over a span of IDs to ensure I do not miss a response.
Turned out that my Command ID was 0x600 and Response ID was 0x610. I essentially ran the fuzzing until the sensor accepted the STOP command and stopped transmitting data and sent back confirmation. Confirm by requesting data from sensor, e.g. request sensor version Send Factory reset command to the command ID discovered above - data: 3D 0 0 0 0 0 0
...and voila, sensor transmits data over default IDs, ready to initialise. After initialisation:
Connected 12.09VDC to V3 input: Amps are a little jumpy, but rather close. I think it's because my load is much too small (only 0.04A) for a 1000A sensor, cannot find anything larger in the house to test with. Attaching a useful How-to doc for different commands...
- Attachments
-
- IVT-Mod_IVT-S_HowTo_1.2.pdf
- (453.54 KiB) Downloaded 58 times
Re: Can't Initialize Isabellenhütte ISA Sensor.
All, I struggled to get a couple of ISA Isabellenhutte shunts initialised and working so am putting my solution below in case it helps anyone. I didn't have an Arduino to use the Jack Rickard-derived code linked in the wiki here https://openinverter.org/wiki/Isabellen ... te_Heusler but I did have a Teensy 4.1.
In addition, the linked code above contains libraries you don't need if all you need is to speak to the ISA shunt over CANbus (it includes duo_wire and wire_EEPROM which I can only assume Jack was using to do other stuff with).
The code below should allow you to communicate with the ISA shunt and change it from the factory defaults to whatever you need. In my case, I got two shunts from Ebay with unknown provenance. They turned out to be set to 500kbs baud rate (the ISA can be set to 250kbs, 500kbs and 1000kbs).
I strongly recommend you read the ISA data sheet, as the code below is the bare minimum you need.
Some gotchas:
The Jack-Rickard-derived code set the rtr flag on the CANmessages to 1, it should be set to 0.
By default, the ISA is big-endian so the shunt may be working fine, you just may be decoding it wrong.
That said, whilst the code below sets all the messages to come back little endian, the current persists in coming back big-endian and I haven't looked into why yet. Fixed, I wasn't sending the correct identifier.
Check your CANbus termination - some of the shunts have in-built termination and some don't.
Check your CANbus transceivers if you are using cheap rubbish like me. I have had two batches of SN65HVD230-based tranceivers from Amazon, some worked, and some didn't, and some turned out to be not terminated when others were, so don't assume the transceivers are good.
I used a Teensy 4.1, with code below, and you need the excellent flexcan_t4 library by Tonton81 from here https://github.com/tonton81/FlexCAN_T4.
In addition, the linked code above contains libraries you don't need if all you need is to speak to the ISA shunt over CANbus (it includes duo_wire and wire_EEPROM which I can only assume Jack was using to do other stuff with).
The code below should allow you to communicate with the ISA shunt and change it from the factory defaults to whatever you need. In my case, I got two shunts from Ebay with unknown provenance. They turned out to be set to 500kbs baud rate (the ISA can be set to 250kbs, 500kbs and 1000kbs).
I strongly recommend you read the ISA data sheet, as the code below is the bare minimum you need.
Some gotchas:
The Jack-Rickard-derived code set the rtr flag on the CANmessages to 1, it should be set to 0.
By default, the ISA is big-endian so the shunt may be working fine, you just may be decoding it wrong.
That said, whilst the code below sets all the messages to come back little endian, the current persists in coming back big-endian and I haven't looked into why yet. Fixed, I wasn't sending the correct identifier.
Check your CANbus termination - some of the shunts have in-built termination and some don't.
Check your CANbus transceivers if you are using cheap rubbish like me. I have had two batches of SN65HVD230-based tranceivers from Amazon, some worked, and some didn't, and some turned out to be not terminated when others were, so don't assume the transceivers are good.
I used a Teensy 4.1, with code below, and you need the excellent flexcan_t4 library by Tonton81 from here https://github.com/tonton81/FlexCAN_T4.
Code: Select all
#include <FlexCAN_T4.h>
/*
THIS CODE WAS ORIGINATED BY JACK RICKARD AND CONTAINED THE FOLLOWING MESSAGE:
"This library supports ISA Scale IVT Modular current/voltage sensor device. These devices measure current, up to three voltages, and provide temperature compensation.
This library was written by Jack Rickard of EVtv - http://www.evtv.me
copyright 2014
You are licensed to use this library for any purpose, commercial or private,
without restriction."
I HAVE REMOVED A LOT OF STUFF AND RE-WITTEN FOR TEENSY 4.1 USING FLEXCAN_T4. ADDITIONALLY I HAVE CHANGED THE RSR BIT FROM 1 IN JACK'S CODE TO 0 IN THE COMMAND MESSAGES THAT GO TO THE SHUNT.
READ THE ISA DATA SHEET!
*/
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; } //Allow streaming
float Version=1.00;
uint32_t datarate=500000;
class ISA
{
public:
ISA();
~ISA();
float Amperes; // Floating point with current in Amperes
double Voltage;
double Voltage1;
double Voltage2;
double Voltage3;
double Temperature;
double KW;
double KWH;
bool firstframe;
int framecount;
//unsigned long timestamp;
double milliamps;
long watt;
//long As;
//long wh;
};
ISA::ISA() // Define the constructor.
{
//timestamp = millis();
framecount=0;
firstframe=true;
}
ISA::~ISA() //Define destructor
{
}
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1; //
ISA Sensor; //Instantiate ISA Module Sensor object to measure current and voltage
void setup()
{
Can1.begin();
Can1.setClock(CLK_60MHz);
delay(500);
Can1.setBaudRate(datarate);
Can1.setMaxMB(2);//NUM_TX_MAILBOXES + NUM_RX_MAILBOXES);
Can1.setMB((FLEXCAN_MAILBOX)0,RX,STD); //receive on MB0
Can1.setMB(MB1,TX); //transmit from MB1
Can1.setMBFilter(REJECT_ALL); //block all data before setting filters
//Can1.setMBFilter(MB0,0x521);
Can1.setMBFilterRange(MB0, 0x521, 0x528);
Can1.enableMBInterrupts();
Can1.onReceive(canSniff); //canSniff called when message received
Serial.begin(115200);
Serial.setTimeout(3000);
Can1.mailboxStatus(); //diagnostic only.
Serial.print("rate: "); Serial.println(Can1.getBaudRate());
Serial<<"\nISA Scale Startup Successful \n";
printMenu();
}
void loop()
{
Can1.events(); //supposedly needed for the callback to work but I think it may work anyway with can.receive above
checkforinput(); //Check keyboard for user input
}
void printStatus()
{
char buffer[40];
sprintf(buffer,"%4.2f",Sensor.Voltage1);
Serial<<"V1:"<<buffer<<"v ";
sprintf(buffer,"%4.2f",Sensor.Voltage2);
Serial<<"V2:"<<buffer<<"v ";
sprintf(buffer,"%4.2f",Sensor.Voltage3);
Serial<<"V3:"<<buffer<<"v ";
sprintf(buffer,"%4.3f",Sensor.Amperes);
Serial<<"Amps:"<<buffer<<"A ";
sprintf(buffer,"%4.3f",Sensor.KW);
Serial<<buffer<<"kW ";
// sprintf(buffer,"%4.3f",Sensor.ah);
// Serial<<buffer<<"Ah ";
// sprintf(buffer,"%4.3f",Sensor.KWH);
// Serial<<buffer<<"kWh";
sprintf(buffer,"%4.0f",Sensor.Temperature);
Serial<<buffer<<"C ";
Serial<<"Frame:"<<Sensor.framecount<<" \n";
}
void printMenu()
{
Serial<<"\f\n=========== ISA Shunt Configurator "<<Version<<" ==============\n************ List of Available Commands ************\n\n";
Serial<<" ? - Print this menu\n ";
Serial<<" i - initialize new sensor\n ";
Serial<<" 1 - STOP\n ";
Serial<<" 2 - STORE\n ";
Serial<<" 3 - START\n ";
Serial<<" 4 - START\n ";
Serial<<" r - Set new datarate\n ";
Serial<<" d - deFAULT\n ";
Serial<<"**************************************************************\n==============================================================\n\n";
}
void checkforinput()
{
//Checks for keyboard input from Native port
if (Serial.available())
{
int inByte = Serial.read();
switch (inByte)
{
case 'r':
getRate();
break;
case 'i':
initialize();
break;
case '?':
printMenu();
break;
case '1':
STOP();
break;
case '2':
sendSTORE();
break;
case '3':
START();
break;
case '4':
RESTART();
break;
case 'a':
deFAULT();
break;
}
}
}
void getRate()
{
Serial<<"\n Enter the Data Rate in kbps you want for CAN: ";
if (Serial.available())
{
uint32_t V = Serial.parseInt();
if(V>0)
{
Can1.setBaudRate(V);
}
Serial.print("new rate: "); Serial.println(Can1.getBaudRate()); //check to see if entered rate has been set
Can1.mailboxStatus();
}
}
void canSniff(const CAN_message_t &msg)
{
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" TS: "); Serial.print(msg.timestamp);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ )
{
Serial.print(msg.buf[i], HEX); Serial.print(" ");
}
Serial.println();
//CAN interrupt
switch (msg.id)
{
case 0x511: //this ID may be getting filtered, see setMBFilterRange above.
break;
case 0x521:
handle521(msg);
break;
case 0x522:
handle522(msg);
break;
case 0x523:
handle523(msg);
break;
case 0x524:
handle524(msg);
break;
case 0x525:
handle525(msg);
break;
case 0x526:
handle526(msg);
break;
case 0x527:
handle527(msg);
break;
case 0x528:
handle528(msg);
break;
}
printStatus();
}
void handle521(const CAN_message_t &msg) //AMperes
{
Serial.println("hande521");
Sensor.framecount++;
long current=0;
//https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html
//https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/
// current = (long)((msg.buf[5] << 24) | (msg.buf[4] << 16) | (msg.buf[3] << 8) | (msg.buf[2])); //Little Endian ...
current = (long)(msg.buf[5] + (msg.buf[4] << 8) + (msg.buf[3] << 16) + (msg.buf[2] << 24)); //TdB Big Endian
Sensor.milliamps=current;
Sensor.Amperes=current/1000.0f;
}
void handle522(const CAN_message_t &msg) //Voltage .. note to me, what's all this framecount stuff?
{
Serial.println("hande522");
Sensor.framecount++;
long volt=0;
volt = (long)((msg.buf[5] << 24) | (msg.buf[4] << 16) | (msg.buf[3] << 8) | (msg.buf[2]));
//volt = (long)(msg.buf[5] + (msg.buf[4] << 8) + (msg.buf[3] << 16) + (msg.buf[2] << 24)); //TdB
Sensor.Voltage1=volt/1000.0f;
}
void handle523(const CAN_message_t &msg) //Voltage2
{
Serial.println("hande523");
Sensor.framecount++;
long volt=0;
volt = (long)((msg.buf[5] << 24) | (msg.buf[4] << 16) | (msg.buf[3] << 8) | (msg.buf[2]));
//volt = (long)(msg.buf[5] + (msg.buf[4] << 8) + (msg.buf[3] << 16) + (msg.buf[2] << 24)); //TdB
Sensor.Voltage2=volt/1000.0f;
}
void handle524(const CAN_message_t &msg) //Voltage3
{
Serial.println("hande524");
Sensor.framecount++;
long volt=0;
volt = (long)((msg.buf[5] << 24) | (msg.buf[4] << 16) | (msg.buf[3] << 8) | (msg.buf[2]));
//volt = (long)(msg.buf[5] + (msg.buf[4] << 8) + (msg.buf[3] << 16) + (msg.buf[2] << 24)); //TdB
Sensor.Voltage3=volt/1000.0f;
}
void handle525(const CAN_message_t &msg) //Temperature
{
Serial.println("hande525");
Sensor.framecount++;
long temp=0;
temp = (long)((msg.buf[5] << 24) | (msg.buf[4] << 16) | (msg.buf[3] << 8) | (msg.buf[2]));
Sensor.Temperature=temp/10;
//if(debug2)Serial<<"Temperature: "<<Temperature<<" C frames:"<<framecount<<"\n";
}
void handle526(const CAN_message_t &msg) //Kilowatts .... what voltage is this using? U1 I believe.
{
Serial.println("hande526");
Sensor.framecount++;
long watt=0;
watt = (long)((msg.buf[5] << 24) | (msg.buf[4] << 16) | (msg.buf[3] << 8) | (msg.buf[2]));
Sensor.KW=watt/1000.0f;
// if(debug2)Serial<<"Power: "<<watt<<" Watts "<<KW<<" kW frames:"<<framecount<<"\n";
}
void handle527(const CAN_message_t &msg) //Ampere-Hours
{
Serial.println("hande527");
Sensor.framecount++;
/*
//ignored
*/
}
void handle528(const CAN_message_t &msg) //kiloWatt-hours
{
Serial.println("hande528");
Sensor.framecount++;
/*
//ignored
*/
}
void STOP()
{
//SEND STOP///////
Serial.println("Stop called, status is ");
CAN_message_t outframe;
outframe.id = 0x411; // Set our transmission address ID
outframe.len = 8; // Data payload 8 bytes
outframe.flags.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.flags.remote = 0; //<--- THIS MUST BE SET TO ZERO. IF YOUR SENSOR IS IGNORING YOU CHECK THIS BIT
outframe.buf[0]=0x34;
outframe.buf[1]=0x00;
outframe.buf[2]=0x01;
outframe.buf[3]=0x00;
outframe.buf[4]=0x00;
outframe.buf[5]=0x00;
outframe.buf[6]=0x00;
outframe.buf[7]=0x00;
Can1.write(MB1,outframe);
Serial.println("Sent, status is ");
Can1.mailboxStatus();
}
void START()
{
Serial.println("Start called, status is ");
//SEND START///////
CAN_message_t outframe;
outframe.id = 0x411; // Set our transmission address ID
outframe.len = 8; // Data payload 8 bytes
outframe.flags.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.flags.remote=0; //<--- THIS MUST BE SET TO ZERO. IF YOUR SENSOR IS IGNORING YOU CHECK THIS BIT
outframe.buf[0]=0x34;
outframe.buf[1]=0x01;
outframe.buf[2]=0x01;
outframe.buf[3]=0x00;
outframe.buf[4]=0x00;
outframe.buf[5]=0x00;
outframe.buf[6]=0x00;
outframe.buf[7]=0x00;
Can1.write(MB1,outframe);
Serial.println("Sent, status is ");
Can1.mailboxStatus();
}
void RESTART()
{
//Has the effect of zeroing AH and KWH
Serial.println("Restart called, status is ");
CAN_message_t outframe;
outframe.id = 0x411; // Set our transmission address ID
outframe.len = 8; // Data payload 8 bytes
outframe.flags.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.flags.remote=0; //<--- THIS MUST BE SET TO ZERO. IF YOUR SENSOR IS IGNORING YOU CHECK THIS BIT
outframe.buf[0]=0x3F;
outframe.buf[1]=0x00;
outframe.buf[2]=0x00;
outframe.buf[3]=0x00;
outframe.buf[4]=0x00;
outframe.buf[5]=0x00;
outframe.buf[6]=0x00;
outframe.buf[7]=0x00;
Can1.write(MB1,outframe);
Serial.println("Sent, status is ");
Can1.mailboxStatus();
}
void deFAULT()
{
//Returns module to original defaults
Serial.println("Default called, status is");
Can1.mailboxStatus();
STOP();
delay(1000);
CAN_message_t outframe;
outframe.id =0x411; // Set our transmission address ID
outframe.len = 8; // Data payload 8 bytes
outframe.flags.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.flags.remote=0; //<--- THIS MUST BE SET TO ZERO. IF YOUR SENSOR IS IGNORING YOU CHECK THIS BIT
outframe.buf[0]=0x3D;
outframe.buf[1]=0x00;
outframe.buf[2]=0x00;
outframe.buf[3]=0x00;
outframe.buf[4]=0x00;
outframe.buf[5]=0x00;
outframe.buf[6]=0x00;
outframe.buf[7]=0x00;
Can1.write(MB1,outframe);
delay(1000);
sendSTORE();
delay(1000);
START();
delay(1000);
Serial.println("Done, status is ");
Can1.mailboxStatus();
}
void sendSTORE()
{
Serial.println("sendSTORE called, status is ");
Can1.mailboxStatus();
//SEND STORE///////
CAN_message_t outframe;
outframe.id = 0x411; // Set our transmission address ID
outframe.len = 8; // Data payload 8 bytes
outframe.flags.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.flags.remote=0; //<--- THIS MUST BE SET TO ZERO. IF YOUR SENSOR IS IGNORING YOU CHECK THIS BIT
outframe.buf[0]=0x32;
outframe.buf[1]=0x00;
outframe.buf[2]=0x00;
outframe.buf[3]=0x00;
outframe.buf[4]=0x00;
outframe.buf[5]=0x00;
outframe.buf[6]=0x00;
outframe.buf[7]=0x00;
Can1.write(MB1,outframe);
Serial.println("Sent, status is ");
Can1.mailboxStatus();
}
void initialize()
{
Sensor.firstframe=false;
STOP();
delay(2000);
for(int i=0;i<9;i++)
{
Serial.println("initialization \n");
CAN_message_t outframe;
outframe.id =1041;// 0x411; // Set our transmission address ID
outframe.len = 8; // Data payload 8 bytes
outframe.flags.extended = 0; // Extended addresses 0=11-bit1=29bit
outframe.flags.remote=0; //<--- THIS MUST BE SET TO ZERO. IF YOUR SENSOR IS IGNORING YOU CHECK THIS BIT
outframe.buf[0]=(0x20+i); //loop over each param to reset
outframe.buf[1]=0x42; //I think this sets Little Endian and Cyclic Running
outframe.buf[2]=0x00;
outframe.buf[3]=0xFA; //(0x60+(i*18)); //This sets varying transmission interevals. Not sure if we want this or just the same value for each message
outframe.buf[4]=0x00;
outframe.buf[5]=0x00;
outframe.buf[6]=0x00;
outframe.buf[7]=0x00;
Can1.write(MB1,outframe);
Can1.mailboxStatus();
delay(2000);
Can1.mailboxStatus();
delay(2000);
sendSTORE();
delay(2000);
}
START();
}