0
\$\begingroup\$

I'm trying to make a working can bus example sending and receiving frames.I managed to test this library using loopback mode
https://github.com/UBC-Solar/Firmware-v2/tree/master/Peripherals/CAN
it seems to be working fine. but since I'm not very familiar with STM32 (coming from arduino IDE) I couldn't find how to set Extended id. and also in datasheet I couldn't find anything about it.

here is the main code:

uint8_t data[8] = {0, 0x1, 0x2, 0x3, 0, 0x4, 0x5, 0x6};
CANInit(CAN_250KBPS);
CAN_msg_t CAN_rx_msg;
CAN_msg_t frame;
frame.id = 0x1801234;
frame.len = 8;
frame.data= data;
CANSend(&frame);
if (CANMsgAvail())
  {
      CANReceive(&CAN_rx_msg);
         if (CAN_rx_msg.id == 0x1801234)
             printf("Good");
         else
             printf(CAN_rx_msg.id);
  }
\$\endgroup\$
4
  • \$\begingroup\$ This is not really about STM32F103, that is a custom CAN driver library for STM32F103 MCU that someone has made. It may not support Extended ID without you modifying it or writing your own CAN driver. Why would you copy random code from the web and ask here how to use it, while you could just use ST's CAN driver library which is documented. \$\endgroup\$
    – Justme
    Apr 8, 2020 at 20:10
  • \$\begingroup\$ Thanks for your answer.I used this Because its the only one that worked for me and since I'm new to STM32 in fact i'm only familiar with arduino. so i was looking all over the internet for an working example of can bus either on STMcubeIDE or Arduino (STM32duino) but I couldn't find a working example i get some errors that I couldn't fix.can you please show me a working example.or a library as simple as the MCP2515 library if exists \$\endgroup\$
    – Jwdsoft
    Apr 8, 2020 at 21:16
  • \$\begingroup\$ That code uses uint16_t for CAN identifier so it will obviously not do you any good. You'll need to look for something setting the IDE bit in the CAN frame and then 29 bit identifier (meaning uint32_t). \$\endgroup\$
    – Lundin
    Apr 9, 2020 at 10:34
  • \$\begingroup\$ Can you send me a link to a working example to use I will not use that one since i'm just a beginner and couldn't make it work \$\endgroup\$
    – Jwdsoft
    Apr 9, 2020 at 20:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.