Hi, i'm currently working on a project using three Olimexino-STM32s. Each board is to be connected to a separate CAN bus and then they will communicate to each-other via serial. So far I can communicate messages through serial and send CAN messages by using x893's files, however I cannot figure out how to make any board receive from the CAN bus. I am using multiple different CAN monitoring programs to send various CAN data as well as connection the boards to CAN devices to no avail. I have tried to use the code others in the thread posted, and still nothing. For anybody who is able to receive/read CAN messages, could you possibly post example code for it? Maybe also a checklist of sorts of what is required to receive?
Using the CAN interface
(103 posts) (27 voices)-
Posted 2 years ago #
-
Good news everyone! I've managed to solve my problem. Ends up I needed to switch to CAN_MODE_NORMAL to get anywhere with the hardware I'm working with.
Posted 2 years ago # -
Hello MelonFarmer, hello every one, I am Giovanni from Brisbane Australia.
I was reading this forum under suggestion of an Olimex forum, about the Olimexino-STM32.
I want to start a project with the Olimexino-STM32 and CAN protocol.
I have some question:
- witch is the best enviroment to start a project? ( like IAR Embedded Workbench or Maple or eclipse..)
- have any one a simple code that use Can Bus over the OLIMEXINO-STM32 board that is not using the "IAR Embedded Workbench 6.30" like in the Olimex Can Bus demo code?
Appreciate Your time and help
Have Fun
Giovanni
Posted 2 years ago # -
I'm using Maple IDE and x893's library with the fixes from other users. Works Great for everything I've been doing!
I've heard some people like eclipse, but I've yet to try. Maple is just a glorified notepad, but it works well enough.
I've done a couple projects with it and works great.
If anybody was having an issue with sending a lot of messages in a row like I was here's a fix that works pretty good.
CAN_TX_MBX CANsendB(CanMsg *pmsg) { CAN_TX_MBX mbx; mbx = canBus.send(pmsg); while(mbx == CAN_TX_NO_MBX) { delayMicroseconds(1250); mbx = canBus.send(pmsg); } return mbx ; }
I took the code posted by Phono, but I would still lose a message or two, which for most applications is fine, however that didn't work for me. I found 1.25 ms was the smallest amount of time I could delay to not lose any messages after ~3-4 consecutive sends. I was using IRQ mode, if that maybe caused the requirement for that.
As I also was sending/receiving serial at the same time, I need the delay to be very small, as the delay blocks reading and caused lost data. However I haven't had any issue with Data loss with that code so far. I'm open to improvements though, I ain't no expert.
Posted 2 years ago # -
1.25ms is fairly fast, what kind of bus utilisation does that give you?
Edit: 1.25ms is VERY fast, if you're sending 11-bit IDs at 125kbps then an 8-byte message takes 1.004ms to send (including interframe spacing and assuming worst-case bit-stuffing) so if there's any other traffic on the bus then you're pretty much guaranteeing collisions!
Posted 2 years ago # -
I'm running at 250kbps, most vehicles are around there I've found, so 1.25 is pretty generous, quite a bit of overhead, again I just fiddled around until I stopped losing messages! I imagine there's a better way to to that though. Also its extended IDs I'm using.
Posted 2 years ago # -
I've a difficulty in getting CAN work on Olimexino and I'm using Eclipse. I've followed what has been suggested by X893 & Phone which includes updating 3 libmaple core libraries(rcc.h, rcc.c and usb.c) and Phone's bug fixes. Nevertheless, I ended up getting the following error:
"libmaple/usb/stm32f1/usb.c:37: fatal error: usb_hardware.h: No such file or directory
compilation terminated."Any hints/helps are highly appreciated..Thanks in advance.
Posted 2 years ago # -
Hi,
I have a MapleIDE project using an SKPang CANbus shield, which was working nicely until I crushed it in a bag. I've bought an Olimexino and am trying to transfer my old sketch to the Oli, but my old sketch relied on MCP2515.c's Interrupt method. I'm sure I'm being dense, but although I can see the IRQ versus pool [sic?] modes in x893's lib (thanks, x893!) and other people's code posts, but I can't see the interrupt-handling functions in x893's lib.How do I detect and handle a CAN interrupt in a MapleIDE sketch using x893's lib?
Thanks again to x893.
TikPosted 1 year ago # -
Edit: Had an issue where 500k Baud was not working. I was too quick to jump to here for help and didn't even think about termination. At any rate for anybody who has a similar problem, where 250k works, and 500k does not, ensure proper termination, because it might not work at a higher baud.
Posted 1 year ago # -
Hi,
Need help to configure can bus Filter.
canbus.filter(idx,id,mask)
what is idx ? how configure it?
is id - msg.ID ?Posted 1 year ago # -
Hi,
I have the same concern, and i read the source code of the library. I found this :-in HardwareCan.cpp (the classes exposed to the programmer)
CAN_STATUS HardwareCAN::filter(uint8 idx, uint32 id, uint32 mask)
{
return can_filter(Port, idx, CAN_FIFO0, CAN_FILTER_32BIT, CAN_FILTER_MASK, 0, 0);
}-in CAN.C
CAN_STATUS can_filter(CAN_Port* CANx, uint8 filter_idx, CAN_FIFO fifo, CAN_FILTER_SCALE scale, CAN_FILTER_MODE mode, uint32 fr1, uint32 fr2)Apparently, the function filter calls the function can_filter, and forces various parameters, including the MASK mode. However, I am wondering why the parameters fr1 (the identifier) and fr2 (the mask) are ignored, and replaced by 0, 0.
I do not think that the filter function can be useful anyhow.
W893, would this be a mistake? Wouldn't it be correct to change the function filter as follows :CAN_STATUS HardwareCAN::filter(uint8 idx, uint32 id, uint32 mask)
{
return can_filter(Port, idx, CAN_FIFO0, CAN_FILTER_32BIT, CAN_FILTER_MASK, id, mask);
}?
Thanks for this nice library that I have used now for many months, and I hope we can improve it with a little help from each other.
Jean-MarcPosted 1 year ago # -
Hi,
I have recently faced the necessarity to use CAN bus on Olimexino-STM32. After reading all this topic I have forked libmaple repository on GitHub and added CAN bus support using library code posted here. The repository is here: https://github.com/vagran/libmaple-olimexino-canbus
Data reading example in "examples/olimexino-can.cpp". Tested with DJI multicopters on-board CAN bus.Posted 3 months ago # -
Hi, thanks a lot. Did you fix the issue with the declarations required in the core, but that make the inclusion of the HardwareCAN library mandatory?
Posted 2 months ago #
Reply
You must log in to post.