🛠 Industrial Automation with BPI-5202: RS485 and GPIO
Objectives
This tutorial aims to configure the BPI-5202 for a simple automation scenario. We will enable the isolated RS485 ports to communicate with industrial sensors and use GPIO pins to control actuators. This use case demonstrates the versatility of the LoongArch architecture in a critical industrial environment.
Required Hardware
- BPI-5202 Loongson 2K1000LAi board
- 24V DC Power Supply
- GPIO Output Module (DI/DO) connected to the 20-pin connector
- RS485 cable and compatible peripheral (e.g., temperature sensor)
- Loongnix or LoongOS operating system installed
- SSH or serial terminal for configuration
Steps
- System Verification: Connect via SSH. Check that serial drivers are loaded.
ls /dev/ttyS*
dmesg | grep ttyS
- RS485 Configuration: Identify the RS485 port (often ttyS2 or ttyS3). Configure the baud rate and direction mode.
stty -F /dev/ttyS2 9600 cs8 -cstopb -parenb
- GPIO Activation: Export the necessary GPIO pins via sysfs. Assume the internal bus exposes GPIOs under
/sys/class/gpio.
echo 17 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio17/direction
- Control Script: Create a Python or Bash script to send an RS485 command and activate the GPIO output simultaneously.
#!/bin/bash
echo "CMD_SENSOR" > /dev/ttyS2
echo 1 > /sys/class/gpio/gpio17/value
sleep 1
echo 0 > /sys/class/gpio/gpio17/value
- Persistence: Add the script to systemd startup to ensure automation on boot.
Verification
Use a multimeter to check the voltage on the GPIO pin (5V or 3.3V depending on the module). On the RS485 port, use a logic analyzer or a second BPI-5202 to confirm data transmission. Check system logs for any serial port errors.
Further Reading
Explore integration with industrial protocols like Modbus RTU over RS485. You can also test hardware security by using the SMEC98SP chips to encrypt data transmitted over the 1000M Ethernet network.