Hello, Does anybody have a library for the Microchip canbus to SPI chip? It's a MCP2515.
Library for MCP2515
(18 posts) (4 voices)-
Posted 3 years ago #
-
why not use the built in CAN and a MCP2551
Posted 3 years ago # -
BJ Freeman, it's possible that x512 needs both the USB and a CAN connection or is unsure on how to do the modifications needed to get the CAN bus peripheral working on the Maple.
x512, A library port of the Arduino's library has apparently been attempted, if dsgamermike sees this he might reply if he came along:
http://forums.leaflabs.com/topic.php?id=1154Posted 3 years ago # -
Crenn, you are correct. I would like to retain the USB that is onboard. Although now that I think about it, I could offload the data through UART and use the onboard can. Is there a working library for the onboard CAN? I saw a thread about it on here, but they're all referencing using a different compiler. Looks much harder to use.
Posted 3 years ago # -
it is premature for me to be an official on using USB and CAN at the same time.
I also bought a board that uses the same device as the Maple, but has CAN and USB peripherals onboard.
what I have not done, yet, is tested the Code that ST provides for this.
I am embarrassed to say I can not upload thru DFU from windows to either board.
So I am working to convert the Loader to ST-link, which has realtime debug as well as easy upload and download to the STM32F4 series.Posted 3 years ago # -
I have not gotten it to work. It seems really simple, but I just can not get it to pass any data. If anyone could help it would be greatly appreciated. I'm sure that x512 and I are not the only ones that want to run any sort of CAN on this chip. If it's off chip solution that is still better no CAN at all. I'll paypal the 1st person that has the MCP 2515 working with the Maple 20$. There's a library in the post crenn posted.
Posted 3 years ago # -
I'll see what I can do about that tonight after I finish fixing up the WireBase library to follow the coding standards libmaple uses. I don't have that chip myself (I'd need 2 to test) but I can try to port it with libmaple in mind.
Posted 3 years ago # -
dsgamermike, Give this a whirl:
http://www.crennsmind.com/Code/Maple/Libraries/MCP2515/MCP2515.zip
Copy the "MCP2515" folder into the libraries folder of the MapleIDE and the sketch into a folder called "MCP2515_driver".
It's a near direct port of the library given here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1289195675The primary difference is a pointer to the Hardware SPI interface that you wish to use is required (a reference would work just as well). I also added in a function that will configure the SPI port to the settings required for the MCP2515 according to the data sheet.
Let me know how it goes.
Posted 3 years ago # -
Crenn, thanks for your help. Unfortunately it still does not work. 1st off I get a compiling error, but it continues to compile. The error is:
libraries\MCP2515\MCP2515.cpp: In member function 'bool MCP2515::_init(int, byte, byte, bool)':
I have my resets tied together, changed it to SPI 2, changed my CS and INT pins. Changed the bus speed, but I still have no data. I have tried swapping the SI and SO pins just to make sure, but no dice.
This circuit works when it's connect the the arudino, so I know that hardware is good. It will send and receive. I have a CANalyzer at my disposal to verify the data.Posted 3 years ago # -
I noted that late last night and I'll look into today. It's actually a warning but I'll see what I can find this afternoon. Are you using that exact sketch with your arduino?
Posted 3 years ago # -
Yes, with exception to changing the CS and INT pins, CAN speed and crystal speed.
Posted 3 years ago # -
What do you set the CAN speed and crystal speed that you're using? The warning is generated from not initialising the BT value in the _init function. There are conditions where it could fail to give it a value (which is not good).
Posted 3 years ago # -
You need to have all devices that are on the bus running at the same speed. In my case it's a 1 Meg/sec bus. The stock is 125kBps. I also have a 20Mhz crystal instead of the 16.
You change these parameters in the int baudRate=CAN.Init(125,16); function. My function looks like int baudRate=CAN.Init(1000,20);Posted 3 years ago # -
I'll try to do an in depth look of what's happening soon. I'm busy for the next week or so doing some non-electronics stuff (including a short holiday starting Friday) but I should be around still on the forums.
Would you happen to be running the MCP2515 off a 5V supply by chance? If so, can you run it off a 3.3v supply? One of the things I'm unsure about is if the Maple and MCP2515 is communicating correctly. Because of the lack of hardware on my side, I'm not sure if the problem is software or hardware. Do you have a connection diagram that you're using?
Posted 3 years ago # -
I have tried with both 3v3 and 5v(5v only on Spi2). They both act the same way. I occasionally do get some bus errors when I press the reset button on the maple, so we're close.
I can tell you really quick that I have tried swapping MOSI and MISO, each time resetting the device.
I do have the maple mini @ 3v3 this is the pinout that follows.
SCK is connected to SCK (26).
SI is connected to MOSI (28).
SO is connected to MISO (27).
int is connected to pin 29
SS is connected to SS (25)
reset to reset.
vcc to vcc
gnd to gnd
The crystal and load caps are correctly positioned.Posted 3 years ago #
Reply »
You must log in to post.