Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5850

General discussion • RPi 4B with RS485 CAN HAT

$
0
0
Hi all,

I'm using RPi 4B with an RS485 CAN HAT (https://www.waveshare.com/wiki/RS485_CAN_HAT)
But I cannot get any response from my RS485 equipment when I use the demo code they provide.

Here is the demo code:

Code:

# -*- coding:utf-8 -*-import RPi.GPIO as GPIOimport serialEN_485 =  4GPIO.setmode(GPIO.BCM)GPIO.setup(EN_485,GPIO.OUT)GPIO.output(EN_485,GPIO.LOW)ser = serial.Serial("/dev/ttyS0", baudrate=115200)  # open first serial port   try:     while 1:          str = ser.readall()          if str:              print (str) except KeyboardInterrupt:      print("STOP")  except:      print("Other error or exception occurred!" )  finally:      GPIO.cleanup()
Here is the /boot/firmware/config.txt

Code:

# For more options and information see# http://rptl.io/configtxt# Some settings may impact device functionality. See link above for details# Uncomment some or all of these to enable the optional hardware interfaces#dtparam=i2c_arm=on#dtparam=i2s=ondtparam=spi=on# Enable audio (loads snd_bcm2835)dtparam=audio=on# Additional overlays and parameters are documented# /boot/firmware/overlays/README# Automatically load overlays for detected camerascamera_auto_detect=1# Automatically load overlays for detected DSI displaysdisplay_auto_detect=1# Automatically load initramfs files, if foundauto_initramfs=1# Enable DRM VC4 V3D driverdtoverlay=vc4-kms-v3dmax_framebuffers=2# Don't have the firmware create an initial video= setting in cmdline.txt.# Use the kernel's default instead.disable_fw_kms_setup=1# Run in 64-bit modearm_64bit=1# Disable compensation for displays with overscandisable_overscan=1# Run as fast as firmware / board allowsarm_boost=1[cm4]# Enable host mode on the 2711 built-in XHCI USB controller.# This line should be removed if the legacy DWC2 controller is required# (e.g. for USB device mode) or if USB support is not required.otg_mode=1[all]hdmi_enable_4kp60=1dtparam=spi=ondtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000dtoverlay=spi-bcm2835-overlayenable_uart=1
Here is my connection:

RPi 4B <----> RS485 CAN HAT <---> RS485 CAN HAT a and b <---> my RS485 equipment
Image

Image

How can I modify the code to get response from my RS485?
Thanks,

Statistics: Posted by k134563 — Wed Apr 24, 2024 8:38 pm — Replies 1 — Views 41



Viewing all articles
Browse latest Browse all 5850

Trending Articles