Hi all,
I am very new to posting messages on forums. I have a battery pack - B024N059HD02 which can communicated via CANBus. I can successfully read data using a PCAN tool. According to the datasheet if you send 0x201 with no data written should return Frame 1 - consisting of Byte 0-1 with Pack Voltage, Byte 2-3 with Charge current etc. I am getting these data on PCAN as it can be seen in image below (ignore the rows which arent highlighted).
I have tried various examples and different techniques to read data. The examples I have seen are CAN communication between two Arduinos. Here I am trying to read/write to a device in CAN bus.
-
I tried continously calling 0x201 every 10ms - using PCAN (see image) and tried Arduino's "read" examples from different libraries.
-
I have tried writing 0x201 using "Write" example from different libraries.
-
Tried "Read" and "Write" example combined.
-
Tried a different node id which requires to write 0x02 byte on 0x00E (see image).
-
All the above - One of the errors from various examples
*CAN Read - Testing receival of CAN Bus message
- Can't init CAN
This indicates it does not get inside the void loop(). I have not enabled any filters either.
bitrate -250kbit/s, 8Mhz clock
Connection between Arduino Uno and MCP2515 as follows;
MCP2515 - Arduino
- SCK - Pin 13
- SI - 12
- SO - 11
- CS - 10
- GND - GND
- VCC - 5V
Any help will be much appreciated
One of the read and write examples I tried on 0x201. Some other example had the ability to alter clock speed to 8Mhz. I have tried all that but nothing has worked.
/****************************************************************************
CAN Write Demo for the SparkFun CAN Bus Shield.
Written by Stephen McCoy.
Original tutorial available here: http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino
Used with permission 2016. License CC By SA.
Distributed as-is; no warranty is given.
*************************************************************************/
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
//********************************Setup Loop*********************************//
void setup() {
Serial.begin(115200);
Serial.println("CAN Write - Testing transmission of CAN Bus messages");
delay(1000);
if(Canbus.init(CANSPEED_250)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok");
else
Serial.println("Can't init CAN");
delay(2000);
tCAN message;
message.id = 0x201; //formatted in HEX
message.header.rtr = 0;
message.header.length = 8; //formatted in DEC
message.data[0] = 0x00;
message.data[1] = 0x00;
message.data[2] = 0x00;
message.data[3] = 0x00; //formatted in HEX
message.data[4] = 0x00;
message.data[5] = 0x00;
message.data[6] = 0x00;
message.data[7] = 0x00;
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
mcp2515_send_message(&message);
delay(1000);
}
//********************************Main Loop*********************************//
void loop(){
if (mcp2515_check_message())
{
Serial.println("In the loop - if ");
if (mcp2515_get_message(&message))
{
Serial.println("In the loop - Second if ");
if(message.id == 0x00D and message.data[2] == 0xFF) //uncomment when you want to filter
{
Serial.print("ID: ");
Serial.print(message.id,HEX);
Serial.print(", ");
Serial.print("Data: ");
Serial.print(message.header.length,DEC);
for(int i=0;i<message.header.length;i++)
{
Serial.print(message.data[i],HEX);
Serial.print(" ");
}
delay(2000);
Serial.println("");
}
}}
}