I am trying to run OBC 2012 and used the code by @49driver(for timing) and TrueSoln(message needs to be sent). Below are the messages that needed to be sent but my charger is still off. In the TrueSoln code snipped he has nissan_crc(messageData, 0x85); function which does-not provide any detail but I have used 49driver code which is supposed to include CRC. What could be done?
///This is header file msg.h
//1d4 8 bytes including prun & crc for 10ms
byte message1d4_0[8] = {0xF7,0x07,0x00,0x04,0x87,0x46,0xe0,0x64};
byte message1d4_1[8] = {0xf7,0x07,0x00,0x04,0xC7,0x46,0xe0,0xA3};
byte message1d4_2[8] = {0xf7,0x07,0x00,0x04,0x07,0x46,0xe0,0x6F};
byte message1d4_3[8] = {0xf7,0x07,0x00,0x04,0x47,0x46,0xe0,0xA8};
//1f2 8 bytes including prun & crc for 10ms
byte message1f2_0[8] = {0x30,0x64,0x20,0x00,0x00,0x82,0x00,0x0B};
byte message1f2_1[8] = {0x30,0x64,0x20,0x00,0x00,0x82,0x01,0x0C};
byte message1f2_2[8] = {0x30,0x64,0x20,0x00,0x00,0x82,0x02,0x0D};
byte message1f2_3[8] = {0x30,0x64,0x20,0x00,0x00,0x82,0x03,0x0E};
//50b 7 bytes no prun or crc for 100ms
byte message50b[6] = {0x00,0x00,0x00,0xC0,0x00,0x00};
// This code written by Peter Luckham known as 49thdiver
#include <DueTimer.h> //© 2021 GitHub, Inc.
#include "variant.h" //due support
#include <due_can.h> // Collin Kidder et alb
#include "msg.h"
void setup(){
// setup 10ms 100MS and 500ms timers
Timer3.attachInterrupt(SendChargeStateCan10msMessage);
Timer3.start(10000); // Calls every 10ms
Timer4.attachInterrupt(SendChargingSimBattery100msMessage);
Timer4.start(100000); // Calls every 100ms
Timer2.attachInterrupt(StatusLed_On);
Timer2.start(1000000);// bink led
//pinMode(buttonPin, INPUT_PULLUP); // output indicators and button inout for diagnostics
pinMode(RelayLED, OUTPUT);
// Initialize serial I/O for debug messages
Serial.begin(115200); delay(100);
// Initialize CAN0 and CAN1, Set the proper baud rates here
Can0.begin(CAN_BPS_500K); //Transmit
Can0.watchFor();
// Send first 500ms message to get things started and sync charger
SendChargingSimBattery500msMessage();
}
void loop(){} // Nothing here all interupt driven
// Blink status LED
void StatusLed_On(){
digitalWrite(RelayLED, LOW); //Inititalize relay to BMS ON
}
// Send 1F2 message every 10ms
void VCM_1F2_Charging_Message(){
bool sendState = false;
switch(counter_1f2){
case 0:
sendState = SendCanMessage(0x1f2,0, 8, message1f2_0);
break;
case 1:
sendState = SendCanMessage(0x1f2,0, 8, message1f2_1);
break;
case 2:
sendState = SendCanMessage(0x1f2,0, 8, message1f2_2);
break;
case 3:
sendState = SendCanMessage(0x1f2,0, 8, message1f2_3);
break;}
counter_1f2++;
if (counter_1f2 >= 4)
counter_1f2 = 0;
return;
}
// Send 1d4 message every 10ms
void VCM_1d4_Charging_Message(){
bool sendState = false;
switch(counter_1d4){
case 0:
sendState = SendCanMessage(0x1d4,0, 8, message1d4_0);
break;
case 1:
sendState = SendCanMessage(0x1d4,0, 8, message1d4_1);
break;
case 2:
sendState = SendCanMessage(0x1d4,0, 8, message1d4_2);
break;
case 3:
sendState = SendCanMessage(0x1d4,0, 8, message1d4_3);
break;}
counter_1d4++;
if (counter_1d4 >= 4)
counter_1d4 = 0;
return;
}
// Send 1dc message every 10ms
// Send 50b message every 100ms
void VCM_50B_Charging_Message(){
bool sendState = SendCanMessage(0x50b,0, 6, message50b);
return;
}
void SendChargeStateCan10msMessage()
{
VCM_1F2_Charging_Message();
VCM_1d4_Charging_Message();
}
void SendChargingSimBattery100msMessage()
{
VCM_50B_Charging_Message();
}
void SendChargingSimBattery500msMessage(){
digitalWrite(RelayLED, HIGH); // turn status led off
}
bool SendCanMessage(unsigned int messageId, unsigned short extendedId, unsigned int payloadLength, byte * messageData)
{
OBCFrame.id = messageId;
OBCFrame.length = payloadLength;
OBCFrame.extended = false;
OBCFrame.rtr=1;
OBCFrame.priority = 15;
for( int i=0; i< payloadLength;i++)
{
OBCFrame.data.bytes = messageData;
}
bool sent = Can0.sendFrame(OBCFrame);
return sent;
}