#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
const int SPI_CS_PIN = 17; // Set CS pin to pin 17
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin for CANBUS shield
void setup() // Initialisation routine
{
pinMode(23, OUTPUT); // Set pin 9 to output (backlight of the LCD)
digitalWrite(23, HIGH); // LED on
delay(250);
digitalWrite(23, LOW);
START_INIT:
if(CAN_OK == CAN.begin(CAN_125KBPS)) // init can bus : baudrate = 125k !!
{
}
else
{
delay(100);
goto START_INIT;
}
// unsigned char login[8] = {0x14, 0x49, 0x72, 0x00, 0x31, 0x66, 0x00, 0x00}; //CAMON this is the serial number of the Flatpack + 2 added bytes of 00 each)
unsigned char login[8] = {0x15, 0x44, 0x71, 0x02, 0x11, 0x66, 0x00, 0x00}; //HB this is the serial number of the Flatpack + 2 added bytes of 00 each)
CAN.sendMsgBuf(0x05004804, 1, 8, login); //send message to log in and assign ID=1 (last 04 means ID=1, for ID=2 use 05004808 )
// unsigned char setdefaultvolt[5] = {0x2B, 0x15, 0x00, 0x44, 0x16}; //???? INCORRECT ??? this is the command for setting the default output voltage (Last two bytes, LSB first). 16 80 is the maximum voltage of 57.6 V
unsigned char setdefaultvolt[5] = {0x29, 0x15, 0x00, 0x9C, 0x13}; // 50.2V
// CAN.sendMsgBuf(0x05009C02, 1, 5, setdefaultvolt); //???? WRONG COMMAND ???? send message to set ouput voltage to all Flatpacks connected to the CAN-bus
CAN.sendMsgBuf(0x05019C00, 1, 5, setdefaultvolt); //send message to set ouput voltage to all Flatpacks connected to the CAN-bus
digitalWrite(23, HIGH);
}
void loop() // main program (LOOP)
{ // nothing to do :)
}