remmie1972 said:
elanimal28 said:
I need help to long in to flatpack 2 . I need to set one of them to 47 volts but every time I try to use any of the codes that have been provided I get a can bus fail message. when I send this code i can receive the serial number on the Serial monitor part of the arduino.
This might have to do that my code uses an other pin for initializing the CAN-interface.
these 2 lines determine the pin for the CAN-interface in my code (it is for pin 10)
const int SPI_CS_PIN = 10;
MCP_CAN CAN(SPI_CS_PIN);
It seems your board requires another pin (possibly #9)
There should be some lines of code above the code you've published where the SPI_CS_PIN is configured. Either try my code with the correct SPI_CS_PIN or add the following 5 lines to your code in the
void SETUP section, NOT IN THE LOOP SECTION !. Place it right behind the 'Serial.println("CAN BUS Shield init ok!");' line
unsigned char login[8] = {0x06, 0x16, 0x71, 0x01, 0x49, 0x29, 0x00, 0x00}; //this is for logging into your flatpack
CAN.sendMsgBuf(0x05004805, 1, 8, login);
delay(2000);
unsigned char setdefaultvolt[5] = {0x29, 0x15, 0x00, 0x5C, 0x12}; //this is the command for setting the default output voltage 47v (0x125C = 4700 Last two bytes, LSB first). 80 16 is the maximum voltage of 57.6 V
CAN.sendMsgBuf(0x05019C00, 1, 5, setdefaultvolt);
this code will log in into your Flatpack and send the command for using 47 volts as default voltage.
The codes from the flatpack should now come every 0,2 seconds and have a different format (because you've logged in). wait about 15 seconds until the messages come much more slowly (about every 2 seconds) the output voltage should have changed to 47 volts.
Now switch off the flatpack, wait about a minute and switch it back on. It should now default to 47 volt.
Good luck.
I still can't get it to change! the only change I see when I upload the code is this new response:
Get data from ID: 9C00
2B 15 0 5C 12 0 0 0
-----------------------------
normally I get :
Get data from ID: 929
5B 6 16 71 1 49 29 0
-----------------------------
Get data from ID: 929
5B 6 16 71 1 49 29 0
-----------------------------
Get data from ID: 929
5B 6 16 71 1 49 29 0
-----------------------------
Get data from ID: 929
5B 6 16 71 1 49 29 0
-----------------------------
Get data from ID: 929
5B 6 16 71 1 49 29 0
-----------------------------
Get data from ID: 4400
6 16 71 1 49 29 0 0
here is the code I am using:
// 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>
#include "mcp_can.h"
// 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;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_125KBPS)) // init can bus : baudrate = 125k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
unsigned char login[8] = {0x06, 0x16, 0x71, 0x01, 0x49, 0x29, 0x00, 0x00}; //this is for logging into your flatpack
CAN.sendMsgBuf(0x05004805, 1, 8, login);
delay(2000);
unsigned char setdefaultvolt[5] = {0x29, 0x15, 0x00, 0x5C, 0x12}; //this is the command for setting the default output voltage 47v (0x125C = 4700 Last two bytes, LSB first). 80 16 is the maximum voltage of 57.6 V
CAN.sendMsgBuf(0x05019C00, 1, 5, setdefaultvolt);
Serial.println("CAN BUS Shield init ok!");
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned int canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.print("Get data from ID: ");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf
, HEX);
Serial.print("\t");
}
Serial.println();
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/