Arduino Yun with CAN BUS shield

Hi,
I now start a project with a Arduino Yun and Can Bus shield of Sparkfun, and I have a problem, when I send a message with library can bus receipt :
“CAN BUS Shield init fail”
“Init CAN BUS Shield again”

My code is this:

#include <mcp_can.h>
#include <SPI.h>

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

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;
    }
}

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
    // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
    CAN.sendMsgBuf(0x00, 0, 8, stmp);
    delay(100);                       // send data per 100ms
}

I use the ICSP connector (for MISO, MOSI…) and a welded wire to RXLED (for CS).

How I can solve the FAIL error?

I now start a project with a Arduino Yun

By posting in the wrong part of the forum. You're not off to a good start.

And hooking up the shield incorrectly. It just plugs in on top of the you.

Mark

Sorry it’s my first post in the forum and thought I’d be better in the programming section.
I have proven to directly connect the can bus shield on Arduino Yun, but get the same error. I see that pins MISO, MOSI, SCK are only in the ICSP connector for this reason I use the wires.

I solved the problem!! :smiley:

It’s necessary change the assignation CS pin to 17 and solder a wire to the RXLED similar way to Arduino Leonardo. Also I connected the shield using ICSP.

This is my code:

#include <mcp_can.h>
#include <SPI.h>

MCP_CAN CAN(17);                                      

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;
    }
}

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
    // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
    CAN.sendMsgBuf(0x00, 0, 8, stmp);
    delay(100);                       // send data per 100ms
}

This is an old post, but in case anyone else was considering soldering wires onto their Yun (like I just did), you don’t need to!

I think there is a little bit of confusion about CS/SS and how SPI works. My understanding is that an SPI master will pull the slave select (SS) pin low on a particular micro in order to control it. The output pin on the master is called the chip-select (CS) and, if there is more than one device on the SPI bus, then it will use more than one CS output; one for each device that it wants to control. The master can use any output to be the CS and this is configurable in software.

The RXLED wire on the yun is the SS (slave select) pin for the ATmega32U4 chip. I.e. it is useful if you want the ATmega32U4 on the yun to be the SLAVE not the master. This is hooked up on the Yun to allow the other chip on the Yun, the Atheros AR9331, the be the SPI master and use the ATmega32U4 as a slave. I’ve never tried this, but I guess it could be useful. But the ATmega32U4 does NOT need to use this pin in order to select another device, like the CAN shield. So, unless you want another off-board SPI device to command the ATmega32U4 as an SPI slave, then there is no need to break-out RXLED by soldering onto the board.

So the details of connecting the Yun + CAN shield. The yun does not break out the 3 main SPI wires onto the Arduino headers, so you do have to use the ICSP connector, which is a shame as the CAN shield does not have one on.

So the simplest way to connect the two boards is to sandwich them as usual except for pins 11,12 and 13. These should be brought up from the ICSP connector:

MISO: ICSP pin 1 to pin 12 on the CAN Shield
MOSI: ICSP pin 4 to pin 11 on the CAN Shield
SCK: ICSP pin 3 to pin 13 on the CAN Shield

That’s it. The CS should be left as the default in the driver and examples (pin 10) which will come up through the sandwiched headers, along with power, RST, the CAN interrupt and the other I/O for the CAN Shield joystick and SD card.

Also, be sure to get the latest CAN shield drivers from github. The best drivers from my sweep are the ones for the Seeedstudio CAN shield: https://github.com/Seeed-Studio/CAN_BUS_Shield . It’s not explicitly for the sparkfun CAN shield, but as this uses the same CAN devices and the same pinout, they should work fine.