Go Down

Topic: Cheap & simple MCP2551/MCP2515 CAN BUS set up (Read 90601 times) previous topic - next topic

dearroz

I understand the basic send and receive sketches, but I wish to send / receive a data structure rather than bytes.  The structure will be something like:
struct MsgType
{
  unsigned int NodeID;
  unsigned int NodeLoc;
  unsigned int DevType;
  byte DevID;
  byte DevStat;
};


MsgType  MsgData

After assigning values the data would be transmitted.  On receiving the data it would be translated back into a structure format.

All examples that I have seen on the Internet deal only with byte data.  Can a structure be transmitted and received, and can you please provide some sample code.

I am wanting to use this in a model railroad to transmit messages to operate various devices such as crossarms and servos.

Appreciate your assistance.


mbedadroid

you fix those things with:

 typedef union {
    UCHAR array[sizeof(float)];
    float ebyte;
} E_float;

typedef union {
   UCHAR array[sizeof(int)];
   int Eint;
} E_int;

typedef union {
   UCHAR array[sizeof(UCHAR)];
   UCHAR Euchar;
} E_UCHAR;


in fact you need a converter visa versa to convert your structure


baghernaseri

Hello friends,
I wanted to know how to turn on the brake lights through the canbus protocol. Please help me with this. I can use the can bus library from my arduino and mcp2515.

mikrotron

Hello baghernaseri. First of all: "You know that you should not do this, because it's illegal and risk to harm yourself and others!" Don't mess around with your CAR, it is not a playground.

Now, to the technical issues to solve. Due to the nature of CAN-Bus usage in cars, it is not a trivial task to produce messages which already exist. That means that most messages are repeated constantly in a fast period between 5 and 1000 ms, depending on the priority of the data it contains and the bus speed. If two nodes tries to send the same message (ID), they overlapp and produce CAN-Bus errors, which will shut down some systems sooner or later. Also the different signals inside the message will drive the receiver-module nuts and it may ignore them or shutdown itself.

The only chance to produce CAN messages at will it so put a filterdevice between the module to control and the CAN-Bus connector for it. This is some kinde of "man-in-the-middle-attack". A microcontroller must receive all signals from one interface (side) and pass them to the other unchanged. Only the requestet signales may be mangled/manipulated.

Next, i would doubt about that you cars brake lights are connected to any CAN-Bus! It is a critical system. In most cars the brake-pedal has a switch, which signals the brake to the central computer (BCM/GEM). There may also other module which signal a "brake" to the central computer like Adaptive Cruise Controls, or pedestrian protection systems. The BCM will then drive a lamp or LED with a direct wire to light. So if you don't own one of these new fancy cars, where everything is CAN connected, it would be the way i described.


Hope this helps you get things clearer.

JohnRob

Please do not PM me with thread based messages.  If your thoughts are worth responding,  the group should benefit from your insight.

Rumenigg

   Hello.
  I'm working in a personal project with my car and I'm trying to get RPM information. For that I bought a Serial CAN-BUS Module based on MCP2551 and MCP2515 from SeeeStudio, at https://www.seeedstudio.com/Serial-CAN-BUS-Module-based-on-MCP2551-and-MCP2515-p-2924.html and I'm not getting information from my car. I'm using a teensyduino 3.1 and serial CAN Module.
  I asked for a help on seeed site but I didn't receive any help.
  My car is a Volkswagem Saveiro 2013 and on OBD-II conector doesn't have CAN-H and CAN-L cables, just K-MASS cable, and I'm catching CAN-H, CAN-L cables from instruments' panel.
  On Serial Monitor is showing that is sending information, but don't receive anything.
  Their library works with SoftwareSerial library to create aditional serial port but my teensyduino has three serial ports and I'm thinking that the problem is with their library.
  I'm connecting the module, tx on pin 7 and rx on pin 8 of teensy.
  Could you help me please?
  Thank you.

parkerlewis404

I'm hoping to learn how Can bus works using a Usb Peak device, and an Arudino/MCP2515.

The readme on Cory's MCB_CAN_lib github page, says it was tested using a Peak.. so I'm wondering how?

I know CAN doesn't use master/slave, but how can I setup PCAN-View and the Arudino to just see basic communication between the two?

Any ideas how Cory used the Peak / Arduino ?


"What kind of USB dongle is this and are you receiving anything?"

coryjfowler

#37
Mar 21, 2019, 09:45 pm Last Edit: Mar 21, 2019, 09:48 pm by coryjfowler
I'm hoping to learn how Can bus works using a Usb Peak device, and an Arudino/MCP2515.

The readme on Cory's MCB_CAN_lib github page, says it was tested using a Peak.. so I'm wondering how?
I tested the baud rate settings in the library using a CAN bus shield and a PCAN-USB adapter connected to a Windows PC. I used PCAN-View basically checking that no errors were reported about messages the Arduino was sending on the small, terminated, CAN bus between the two.

I know CAN doesn't use master/slave, but how can I setup PCAN-View and the Arudino to just see basic communication between the two?
Any ideas how Cory used the Peak / Arduino ?
Basically connect CAN_H of the Peak to CAN_H on the sheild and CAN_L of the Peak to CAN_L of the sheild.  Depending on what you're using, you may need to enable the CAN termination on the shield.  You need at least one 120ohm resistor placed across CAN_H and CAN_L at one end of the bus.  A proper termination uses two 120ohm resistors at the far ends of the bus.

As long as the baudrate set in PCAN-View matches the baudrate programed into the Arduino and you have the Arduino sending a message, something should show up on PCAN-View.
"Taking the time to make a proper, punctuated, post is a mark of courtesy and respect."  http://forum.arduino.cc/index.php?topic=149022.0

Go Up