yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ROS Robot Expansion Board📖
1.Expansion board STM32 driver
  • 0. Precautions
  • 1.1 Expansion Board Introduction_V3.0
  • 1.1 Expansion Board Introduction_V1.0
  • 1.2 STM32 Development environment
  • 1.3 Button to control the buzzer to whistle
  • 1.4 FreeRTOS application
  • 1.5 Serial communication
  • 1.6 SBUS model aircraft remote control
  • 1.7 CAN bus communication
  • 1.8 RGB colorful light bar
  • 1.9 Timer interrupt to control PWM servo
  • 1.10 Control serial port servos
  • 1.11 Nine-axis attitude sensor to obtain data
  • 1.12 Control the forward and reverse rotation of the motor
  • 1.13 The timer captures the encoder data
  • 1.14.1 Robot kinematics analysis theory
  • 1.14.2 Mecanum wheel kinematics analysis
  • 1.15 PID control robot movement
  • 1.16 OLED character display
2.Python basic control
  • 2.0 Bind PCB port devices
  • 2.1 Update the firmware of the expansion board
  • 2.2 Turn off the self-starting large program at startup
  • 2.3 Install the Rosmaster driver library
  • 2.4 Buzzer whistle
  • 2.5 Control PWM servo
  • 2.6 RGB colorful light bar special effects display
  • 2.7 Control the forward and reverse rotation of the motor
  • 2.8 Control the movement of the robot
  • 2.9 Control Serial Servo
3.ROS1 Basic Course
  • 1.ROS introduction
  • 2.ROS installation
  • 3.ROS common command tools
  • 4.ROS workspace
  • 5.ROS function package
  • 6.ROS node
  • 7.ROS topic publisher
  • 8.ROS topic subscribers
  • 9.ROS service client
  • 10.ROS service server
  • 11.ROS action client
  • 12.ROS action server
  • 13.ROS custom message reception
  • 14.ROS-launch file
  • 15.ROS-TF transformation
  • 16.ROS parameter service
  • 17.ROS-rviz use
  • 18.ROS-rqt tool usage
  • 19.Topic message recording and playback
  • 20.urdf model introduction
  • 21.gazebo introduction
  • 22.ROS distributed communication
4.ROS1 robot control
  • 0. Bind PCB port devices
  • 1. Package Use the tutorial
  • 2. Package Description
  • 3. Robot keyboard control
  • 4. Robot state estimation
  • 5. Robot imu calibration
  • 6. Robot URDF Model
5.ROS2 Basic Course
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
6.ROS2 robot control
  • 0. Bind PCB port devices
  • 1. Package Use the tutorial
  • 2. Robot information release
  • 3. Robot keyboard control
  • 4. Robot state estimation
  • 5. Robot calibration
  • 6. URDF model
7.RDK X3 course
  • 1. Update the firmware of the expansion board
  • 2. Turn off the self-starting large program at startup
  • 3. Install the Rosmaster driver library
  • 4. Buzzer whistle
  • 5. Control PWM servo
  • 6. RGB colorful light bar special effects
  • 7. Control motor forward reverse
  • 8. Control robot movement
  • 9. Control Serial Servo
Download
  • Rules_File
  • Hardware Info
  • Code
  • 3D Model File
  • RDK Code
  • ROS2_Basic_VM
Download ZIP

Welcome to ROS Robot Expansion Board repository

1.7 CAN bus communication

7. CAN bus communication

7. CAN bus communication 7.1. Purpose of the experiment 7.2. Configuration pin information 7.3. Analysis of the experimental flow chart 7.4. core code explanation 7.5. Hardware connection 7.6. Experimental effect

7.1. Purpose of the experiment

Using the CAN communication of STM32, using the loopback mode, the key control sends CAN data, interrupts the received CAN data and prints it out through the serial port assistant.

7.2. Configuration pin information

Since each new project needs configuration information, it is more troublesome. Fortunately, STM32CubeIDE provides the function of importing .ioc files, which can help us save time.

  1. Import the ioc file from the Serial project and name it CAN.

Find CAN in Connectivity and tick Activated to enable the CAN peripheral.

image-20220326121240215

  1. According to the schematic diagram, the pins connected to the CAN bus are PB8 and PB9, while the default CAN bus pins are PA11 and PA12, so it is necessary to manually modify the CAN bus pins to PB8 and PB9.

image-20220326122605409

image-20220326122759412

image-20220326122910978

  1. Set the parameters of the CAN peripheral, here we set the baud rate to 1000kbps and the mode to Loopback.

image-20220326121651092

Since this is only used to test communication, choose Loopback mode (data is sent and received automatically); if you need to connect a third-party CAN device, please choose Normal mode (data receiving/sending independent).

image-20220326121936036

  1. Turn on the CAN RX0 interrupt in the interrupt setting. If the interrupt is not turned on, the data cannot be received.

image-20220326122355699

7.3. Analysis of the experimental flow chart

image-20220519101843527

7.4. core code explanation

  1. Create new buzzer driver library bsp_can.h and bsp_can.c files in BSP. Add the following to bsp_can.h:

image-20220326140058393

  1. Add the following in bsp_can.c:

Can_Init(): Initialize the CAN peripheral related content, set the CAN receive filter, and open the CAN bus communication.

image-20220326140418820

  1. In order to test the sending data, the new Can_Test_Send() function sends the data through CAN and prints it to the serial port assistant. If you need to modify the sent data, you can modify the TxData array before sending.

image-20220326140721179

  1. The CAN receive interrupt callback function prints the received CAN data through the serial port. The name of this function cannot be modified, otherwise the function cannot be called.

image-20220326140956603

  1. In BSP initialization, call the Can_Init() function to initialize the CAN peripherals.

image-20220326141309119

  1. After the button is pressed, the function of sending CAN data is added.

image-20220326141424603

7.5. Hardware connection

Since the loopback mode is used, the CAN interface may not be connected to external devices.

image-20220326173544238

7.6. Experimental effect

After programming the program, the LED light flashes once every 200 milliseconds. After connecting the expansion board to the computer through the micro-USB data cable, open the serial port assistant (the specific parameters are shown in the figure below), and the buzzer will sound every time the button is pressed. 50 milliseconds, you can see that the serial port assistant will display the data sent by CAN and the data received by CAN.

image-20220519101952043

SBUS model aircraft remote control
RGB colorful light bar

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文