B4R Question CAN-BUS

mrossen

Active Member
Licensed User
Longtime User
Hi,

Is a CAN-BUS library available, ex for the CAN-BUS shield from Sparkfun?

Mogens
 

mrossen

Active Member
Licensed User
Longtime User
Thank you Erel.

I have ordred the Arduino and Can-Bus shield (and a gsm shield) today.

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Erel,

Now I have got the hardware. The Arduino UNO and the Can-Bus shield from Sparkfun.

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Now I have tested the Can-Bus Shield.

When I run my code without the shield mounted I get a 0 in return when I init the CanBus.
When I run my code with the shield mounted I get a 1 in return when I init the CanBus.
That seems to be right?

But I can not receive or send any thing. I don't know if it is the library or it is the shield thev is something wrong with?

The timeout in the send function, is it how long time it will sending? Ex. 100ms?

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi,

I am still confused about whats not working. I have tonight ordered the CanBus shield from Seeed Studio to see if there is any difference.

You will bu updated :)

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi,

Now I have the new hardware. A Arduino and CAN-Bus shield from Seeed.

This library: https://github.com/Seeed-Studio/CAN_BUS_Shield works perfect in the Arduino program.

In b4r I revieve a 0 when I try to connect with this code.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public CanBus1 As MCP2515

B4X:
    '    The constants For the baud settings are:
    '    1 = CAN_BAUD_10K
    '    2 = CAN_BAUD_50K
    '    3 = CAN_BAUD_100K
    '    4 = CAN_BAUD_125K
    '    5 = CAN_BAUD_250K
    '    6 = CAN_BAUD_500K
    
    'Is CanBus connected
    Dim canbusConnected As Boolean
    canbusConnected = CanBus1.InitCAN(6)
    Log("CanBus Connected: ", canbusConnected)



Any ideas

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi again,

I have (again) looked in the code.

This part is fron the original code

B4X:
// demo: CAN-BUS Shield, send data
// [email protected]

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

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

Maybe I need to set the SPI port? But I dont have that option?

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hmmmm.

Have tried that, with no luck

B4X:
  13       SCK
   9       CS

*/

#include "SPI.h"
#include "MCP2515.h"

#define SLAVESELECT 9

//MCP2515 Registers
#define RXF0SIDH 0x00
 

Attachments

  • upload_2017-12-17_19-52-57.png
    upload_2017-12-17_19-52-57.png
    15.1 KB · Views: 322
Upvote 0
Top