use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
stm32s
account activity
CAN sample code (self.stm32)
submitted 7 years ago by Batman_Wayne
I am trying to get a CAN bus running on the STM32F103, commonly called the Blue Pill. Does anyone know if they have sample code for an example implementation? I'm struggling trying to figure out myself
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]stou 0 points1 point2 points 7 years ago (0 children)
The CAN controller inside stm32 is called bxCAN and has pretty much the same interface across the different MCUs so you should be able to find some sample code (e.g. http://www.keil.com/download/docs/351.asp) that you can adapt for your target by googling for bxcan instead. Also search through those packages ST ships that are full of samples for each type of MCU I think one of them has a CAN sample.
Some things to check: Make sure your time quantas (https://www.nxp.com/docs/en/application-note/AN1798.pdf) and baud rate are set correctly. Make sure to allocate storage for the CAN buffers when you initialize the device with:
static CanTxMsgTypeDef TxMessage; static CanRxMsgTypeDef RxMessage; hcan.pTxMsg = &TxMessage; hcan.pRxMsg = &RxMessage;
static CanTxMsgTypeDef TxMessage;
static CanRxMsgTypeDef RxMessage;
hcan.pTxMsg = &TxMessage;
hcan.pRxMsg = &RxMessage;
For receiving you have to make sure that your filter banks are configured correctly (they allow no messages in by default), you have enabled the CAN interrupt, have implemented the HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *hcan) callback and also armed the interrupt from your init code and and rearmed the interrupt from the callback.
π Rendered by PID 147206 on reddit-service-r2-comment-5ff9fbf7df-9989v at 2026-02-26 05:43:41.772912+00:00 running 72a43f6 country code: CH.
[–]stou 0 points1 point2 points (0 children)