exothink / exocan Goto Github PK
View Code? Open in Web Editor NEWstm32duino CAN Library for the STM32F103 aka Blue Pill
License: Other
stm32duino CAN Library for the STM32F103 aka Blue Pill
License: Other
I am using the Arduino IDE 1.8.16.
and followed your insalling instructions.
But the Arduino Library Manager could not find "eXoCAN"
Would you have any interest in implementing CAN2 in your library for the stm32F105/107?
I have managed to get CAN2 working (as a stand-alone functions) , working along side your library on a stm32F105. I told Arduino IDE that the board was a blue pill and it was happy. (It had frequent upload timeouts - I think because on the 105 & 107 you can use any port for uploading so may take longer to scan ?) My code is only basic and doesn't take advantage of all the features your library does.
You are welcome to my code but it is mostly based on your work.
I'm trying to get two bluepill boards to communicate with each other using this library. When one bluepill sends a frame to the bus, it's actually getting transmitted (the other bluepill recieves the data correctly and I can see that ACK is being sent on the bus (I'm sniffing the bus using a logic analyzer). However transmit() completely hangs the sending microcontroller and I have to reset it using the microswitch on board. Using some digitalWrite's I tracked down the line that hangs the uC and it's the last line before return
(that is: periphBit(ti0r, 0) = 1
).
I'm sure my bluepill boards don't have genuine STM32 (probably a CS32F103c8t6 but I'm not sure) on it as I had to add upload_flags = -c set CPUTAPID_0x2ba01477
to the config to work. Do you have a board with the same chip to test if it works for you?
Can exocan library support freertos?
Even thou I'm not user of this library, I've came across it while searching why my SN65HVD230 does not work. I have the same cheap knock-off from Ali.
Problem was 10 kΩ resistor, tying Rs (8) pin to ground, while the Rs should be tied to the ground directly.
From datasheet:
The RS pin (pin 8) on the SN65HVD230 and SN65HVD231 provides three different modes of operation: high
speed mode, slope control mode, and low-power mode. The high speed mode of operation is selected by
connecting the RS pin to ground, allowing the transmitter output transistors to switch on and off as fast as
possible with no limitation on the rise and fall slopes. The rise and fall slopes can also be adjusted by connecting
a resistor in series between the RS pin and ground. The slope will be proportional to the pin's output current. With
a resistor value of 10 kΩ the device will have a slew rate of ~15 V/μs, and with a resistor value of 100 kΩ the
device will have a slew rate of ~2 V/μs.
Solution: Remove 10 kΩ resistor (R1 on my module), and connect it directly (0 Ω resistor, piece of wire or good amount of solder will do). This puts chip in the high performance mode, and viola, it started to work.
If you want, you can do a test.
Bellow error is present when compiling in VSCODE + PlatformIO against a STM32 bluepill
.pio\libdeps\bluepill_f103c6\eXoCAN/eXoCAN.h:146:41: error: 'u_int32_t' has not been declared
146 | void filter32Init(int bank, int mode, u_int32_t a, u_int32_t b); //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN/eXoCAN.h:146:54: error: 'u_int32_t' has not been declared
146 | void filter32Init(int bank, int mode, u_int32_t a, u_int32_t b); //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN/eXoCAN.h:158:35: error: 'u_int32_t' has not been declared
158 | void filterMask32Init(int bank, u_int32_t id = 0, u_int32_t mask = 0);
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN/eXoCAN.h:158:53: error: 'u_int32_t' has not been declared
158 | void filterMask32Init(int bank, u_int32_t id = 0, u_int32_t mask = 0);
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN/eXoCAN.h:159:35: error: 'u_int32_t' has not been declared
159 | void filterList32Init(int bank, u_int32_t idA = 0, u_int32_t idB = 0); // 32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN/eXoCAN.h:159:54: error: 'u_int32_t' has not been declared
159 | void filterList32Init(int bank, u_int32_t idA = 0, u_int32_t idB = 0); // 32b filters
| ^~~~~~~~~
In file included from .pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:1:
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.h:146:41: error: 'u_int32_t' has not been declared
146 | void filter32Init(int bank, int mode, u_int32_t a, u_int32_t b); //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.h:146:54: error: 'u_int32_t' has not been declared
146 | void filter32Init(int bank, int mode, u_int32_t a, u_int32_t b); //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.h:158:35: error: 'u_int32_t' has not been declared
158 | void filterMask32Init(int bank, u_int32_t id = 0, u_int32_t mask = 0);
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.h:158:53: error: 'u_int32_t' has not been declared
158 | void filterMask32Init(int bank, u_int32_t id = 0, u_int32_t mask = 0);
| ^~~~~~~~~
Compiling .pio\build\bluepill_f103c6\FrameworkArduino\VirtIOSerial.cpp.o
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.h:159:35: error: 'u_int32_t' has not been declared
159 | void filterList32Init(int bank, u_int32_t idA = 0, u_int32_t idB = 0); // 32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.h:159:54: error: 'u_int32_t' has not been declared
159 | void filterList32Init(int bank, u_int32_t idA = 0, u_int32_t idB = 0); // 32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:129:41: error: 'u_int32_t' has not been declared
129 | void eXoCAN::filterList32Init(int bank, u_int32_t idA, u_int32_t idB) //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:129:56: error: 'u_int32_t' has not been declared
129 | void eXoCAN::filterList32Init(int bank, u_int32_t idA, u_int32_t idB) //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:135:41: error: 'u_int32_t' has not been declared
135 | void eXoCAN::filterMask32Init(int bank, u_int32_t id, u_int32_t mask) //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:135:55: error: 'u_int32_t' has not been declared
135 | void eXoCAN::filterMask32Init(int bank, u_int32_t id, u_int32_t mask) //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:140:47: error: 'u_int32_t' has not been declared
140 | void eXoCAN::filter32Init(int bank, int mode, u_int32_t a, u_int32_t b) //32b filters
| ^~~~~~~~~
.pio\libdeps\bluepill_f103c6\eXoCAN\eXoCAN.cpp:140:60: error: 'u_int32_t' has not been declared
140 | void eXoCAN::filter32Init(int bank, int mode, u_int32_t a, u_int32_t b) //32b filters
| ^~~~~~~~~
*** [.pio\build\bluepill_f103c6\src\main.cpp.o] Error 1
*** [.pio\build\bluepill_f103c6\lib89b\eXoCAN\eXoCAN.cpp.o] Error 1
Hello
Is it possible to send more than 1 Can message in a row (without delay) and without data being lost at the recipient? How can this be implemented properly?
void canISR() // get CAN bus frame passed by a filter into fifo0
{
can.receive(id, fltIdx, rxbytes); // empties fifo0 so that another another rx interrupt can take place
}
void setup()
{
can.attachInterrupt(canISR);
}
void loop()
{
...
...
can.transmit(frame1...);
can.transmit(frame2...);
can.transmit(frame3...);
can.transmit(frame4...);
can.transmit(frame5...);
...
}
Thank you
Hi. Thanks for the library it is just what I needed for my project. There are so few examples of using canbus on STM32 out there. This library is invaluable.
I did find the library would not compile using PlatformIO on Linux because of line 25 in eXoCAN.h
#include <arduino.h>
The 'A' needs to be capitalised
#include <Arduino.h>
The other thing I noticed is that the timeout in the function eXoCAN::transmit() is commented out. Is there a reason for this?
With the transmit FIFO being only three messages long in the STM32F103C8 it is useful to wait for a space in the FIFO when sending a cluster of messages.
Great work, thank you! Can you please tell me what has to be modifed for a bitrate of 100K? I have an already existing system I want to connect to. And is it possible to use CAN at PB8+9 and also PA11+12 via USB on "BluePill" for a serial output at the same time?
Regards,
Max
For standard ID , I can specify STD_ID_LEN as a parameter in can.begin() , Can I please know how to use extended bit identifier??
I don't see why it wouldn't, but if not do you think it would require much modification? Thanks.
I can't get the extended id and filtering to work.
Example:
can.filterMask32Init (0, 0x00232461,0x1FFFFFFF);
using eXoCAN can(EXT_ID_LEN, BR1M, PORTA_11_12_WIRE_PULLUP);
it should filter everything except 0x232461 ... but it doesn't work as expected. Nothing is received, 0x232461 is filtered.
I saw that there are 2 can buses within the bluepill. Is it possible for me to initialize and use both of them simultaneously ?
I know CAN and USB can't work at the same time.
Is there a method to switch between CAN and USB in runtime?
On my hardware I can detect the USB-Bus power, so I know if the HW is connected via USB or not.
I'd like to load the CAN functions only if not connected to USB.
At the moment the constructor
eXoCAN can;
already kills USB. Any suggestions?
Hi
I want to send 8 byte fixed data to id=0x0 and read 8 byte variable data from id=0x2bd .
Please guide me . Thanks
Hi John,
how can I send a remote frame? Couldn't figure it out neither from the .h-file nor from examples. Maybe you could give a hint in your README.
vy 73, Hermann, DF2DS
Until now I was using mcp 2515 for CAN transmission. I wanted to give a try to mcp2551 as blue pill has built in support of CAN.
Manged to add your library to Arduino IDE and uploaded example sketch.
After uploading I don't have usb serial any more.
Is it possible to have CAN and usb serial at same time?
I have tried both PORTA_11_12_WIRE_PULLUP and PORTB_8_9_WIRE_PULLUP. Nothing helps.
When I upload any other sketch usb works fine.
Arduino IDE: 1.8.13
Board core:
https://github.com/stm32duino/BoardManagerFiles/raw/master/package_stmicroelectronics_index.json
Bluepill STM32F103C8T6 generic_boot20_pc13
There is no debugging on this Arduino software, so I was very disappointed that I could not start CAN with the USB library. Now I have to use Cub for my task, but so far I have not come up with a beautiful solution with a bootloader.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.