Go Down

Topic: Can bus init ok, but no data. (Read 1 time) previous topic - next topic

MelectroU

So I've been trying for a long time to communicate with a car through can bus and arduino uno. Since I failed to do that, I thought I would try out simple send and receive sketch (which is in library examples). I hooked up two can communication circuits and I thought I'll try to send data from one can chip to another while one is sending data and other is receiving. Basically it says that can init ok, and then nothing, no data is being received. I've tried few shields, even standalone chips (MCP2551 and MCP2515), but no luck. Has anyone encountered such thing?? My stand alone circuit does have 16MHz crystal, common ground and is set to a same baudrate on both arduinos.

All the libraries are very similar (and yes, I'm pretty sure I've tried them all). This is the one I'm using: https://github.com/reeedstudio/CAN_BUS_Shield

This is the send code:

Code: [Select]
#include <mcp_can.h>
#include <SPI.h>

MCP_CAN CAN(10);                               

void setup()
{
    Serial.begin(115200);

START_INIT:

    if(CAN_OK == CAN.begin(CAN_500KBPS))             
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
 
    CAN.sendMsgBuf(0x00, 0, 8, stmp);
    delay(100);                     
}


This is the receive code:

Code: [Select]
#include <SPI.h>
#include "mcp_can.h"


unsigned char Flag_Recv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];


MCP_CAN CAN(10);                                            // Set CS to pin 10

void setup()
{
    Serial.begin(115200);

START_INIT:

    if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}


void loop()
{
    if(CAN_MSGAVAIL == CAN.checkReceive())            // check if data coming
    {
        CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

        for(int i = 0; i<len; i++)    // print the data
        {
            Serial.print(buf[i]);Serial.print("\t");
        }
        Serial.println();
    }
}


Does anybody see any reason why I'm not getting any data?

MelectroU

ok so, this is what I have so far: apparently something does come out of can H and can L pins, but after sending that data to another can transceiver I get the data only on Rx pin. Shouldn't both pins transmit and receive in order for it to work? Tried to change the chip, same thing happens.

OmarGamal


coryjfowler

Me, I'd try my library and see if it works.  If it still doesn't, I'll be more than happy to assist you.

https://github.com/coryjfowler/MCP_CAN_lib/
"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