SEEED CANbus Shield

Posted on
  • All,

    I am working on a new project that requires CANbus interface and a microprocessor to switch external logic depending of what messages is sent to it. I chose a SEEED studio shield SPI->CANbus (based on MCP2515) interface which I have used in the past, and the Espruino PICO as the micro for the task.

    As it uses SPI bus. I went ahead and pre-configured the following way:

    SPI1.setup({sck:A5, miso: A6, mosi: A7, mode: 0, baud: 4000000});
    

    Although I am not too sure that this is the problem, I am noticing the following:

    .... even though the format between the "Arduino" and "Espruino" boards carry the same messages, the way each byte is passed from board to shield does not match.... I am attaching a couple of screen shots for anyone to see.

    Has anyone noticed arrays' last byte switching and holding the MOSI line "low" whenever its last bit is a "0"???

    NOTE: I changed the "mode" and "baud" rate from the default, with no success. I also checked that the MCP2515 was ~3vdc compatible, and it is.

    Thanks


    5 Attachments

    • arduino_zoom_in.png
    • arduino_zoom_in_2.png
    • espruino_zoom_in.png
    • espruino_zoom_in_2.png
    • espruino_zoom_out.png
  • It shouldn't matter what state the mosi line is in when idle, as long as it's in the correct state on the appropriate edge of the clock, though, should it?

  • DrAzzy,

    In regards to your comment about MOSI state, I thought the same. Nevertheless, If you look at both 2nd (Arduino & Shield) and 4th (Espruino & Shield) pictures, what you will notice is that while sending the same command:

    SPI1.send([0x03, 0x0F, 0x00], 0xc7]; 
    

    from the behavior of the "Arduino" (2nd picture), you can see that right after transmitting MOSI last byte (0x00), it pulls the line "high" at the end of the clock, and MISO responds with [0x87]....

    .... then, from Espruino setup (4th picture), MOSI transmit the last byte, then holds the line "low"right at the clock edge, and MISO receives [0x00].

    That is what it confuses me... I thought I was sending the wrong payload, but not the case here...

    as long as it's in the correct state on the appropriate edge of the clock, though, should it?

    As far as I know I am respecting that format.On the spec sheet it mentions that the MODE can be [0,0] or [1,1]... I left it as [mode : 0] as it should follow convention (right?)

    Moreover, I saw some people with interest in interfacing the Espruino to the CANbus... hopefully this could serve that purpose.

    BTW, DrAzzyThanks for your quick replay.

  • ... what a mess I just made.

  • :) I think it was the spaces at the beginning of each line that messed the post up. Just fixed it.

    As @DrAzzy says, it shouldn't make any difference what happens after the last bit. I think the STM32 is pretty normal in that it only changes the state of the data line when there is a bit of data - I'm very surprised the Arduino is any different.

    I think:

    SPI1.send([0x03, 0x0F, 0x00], 0xc7]; 
    

    Isn't doing what you expect. The final argument is actually the one for the 'CS' pin, with the first
    as the data.

    You want one of:

    SPI1.send([0x03, 0x0F, 0x00, 0xc7]); 
    SPI1.send([0x03, 0x0F, 0x00, 0xc7], my_cs_pin); 
    SPI1.send([[0x03, 0x0F, 0x00], 0xc7]); 
    

    They all do the same thing - might explain why you're only sending 3 bytes and not 4?

    ... and yes, the Seeedstudio CAN bus shield looks really interesting. Let's face it, once you've got a board to convert the logic levels properly, you might as well have a chip on there to properly handle CAN bus. I'd love to get a module done to communicate with it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

SEEED CANbus Shield

Posted by Avatar for DALP @DALP

Actions