question

christophlaib avatar image
christophlaib asked

Raspi4 (v1.4) and Wafeshare CAN HAT how to ?

Hi everybody

Need : Venus OS on Raspi4 with Wafeshare CAN HAT

Problem :

So I'm a bit stuck between ;-)

Any idea ?


VE.Can
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

4 Answers
bathnm avatar image
bathnm answered ·

Which wave share HAT do you have, as depending on the model depends on the configuration. You re best to go with the latest 2.90 beta as a few things have been changing under the hood with regards to CAN interface are configured.

Until kwindem VeCanSetup script is updated you will need to do things manually by logging in via ssh

The first thing to do is get the driver loaded, that requires a modification to the file /u-boot/config.txt to load the relevant overlay file.

As I have a revision 2 dual channel 251xFD card this is what I have in my /u-boot/config.txt

dtoverlay=spi1-3cs
dtoverlay=mcp251xfd,spi0-0,interrupt=25 
dtoverlay=mcp251xfd,spi1-0,interrupt=24

If you have a different card read the Waveshare wiki for your card as to what needs loading. The files you will need to load are located in /u-boot/overlays

Once that is done the system will load the kernel driver and detect the CAN interfaces. The GUI will show can0 and if you have a dual card can1. There is further configuration required to get a name against these, but let's get you loading the relevant files and detecting the can interfaces first.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

christophlaib avatar image christophlaib commented ·

thx for the answer !

I have the waveshare RS485 CAN Hat. 12Mhz One CAN BUS
So, if i unserstood correctly, your advice is to leave out kwindem, and do the configuration manually ?

On the mentioned Waveshare Wiki i found config.txt modifications for my model :

dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000

Are other files in /u-boot/overlays needed ?

best
CL

0 Likes 0 ·
christophlaib avatar image
christophlaib answered ·

success so far :-)

Just added in config :

dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000

1660561987247.png- and i see my CAN0


how to make it talk to my Batrium BMS ?






1660561987247.png (38.2 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

bathnm avatar image
bathnm answered ·

Great. Now if you would like to replace the can0 with a name such as VE.Can then you need to modify the file /etc/udev/rules.d/machine. This is what mine consists off.

ENV{BASE_COMPATIBLE}!="raspberrypi,4-model-b", GOTO="end-rpi4-model-b"
ACTION=="add",SUBSYSTEM=="tty",KERNEL=="ttyAMA0",RUN+="/usr/bin/hciattach /dev/ttyAMA0 bcm43xx 3000000 flow -"
ACTION=="add", SUBSYSTEM=="net", ATTR{type}=="280", KERNELS=="fe204000.spi", NAME="can0", ENV{VE_NAME}="VE.Can port"
ACTION=="add", SUBSYSTEM=="net", ATTR{type}=="280", KERNELS=="fe215080.spi", NAME="can1", ENV{VE_NAME}="WS.Can port"
LABEL="end-rpi4-model-b"

The KERNELS== is the identifier, as you can see in mine it is

fe215080.spi

The simplest thing to do to find this is run find /sys -name can0. This will turn a path which includes something .spi. Replace accordingly.

Then under ENV{VE_NAME} insert the name you would like displaying.

I shall be updating the material here for future reference.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Kevin Windrem avatar image
Kevin Windrem answered ·

There is a beta version of VeCanSetup that might help. There is code to insert a name to be displayed in the Services menu but it's commented out for now. I'm not sure it would work for the Waveshare hat though.

If you are running PackageManager, just change the branch to "beta". Otherwise, download from GitHub.

You've got the interface working so the only thing that VeCanSetup will add now is a custom name but since you only have one CANbus port, that seems unnecessary.

Instead of modifying /etc/udev/rules.d/machine you can add your own rules file to the directory /etc/udev/rules.d

As far as getting your BMS talking, that will depend on selecting a CAN-bus profile that works with that BMS. CANbus data rate is important. You may need more information from Batrium.


2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources

Additional resources still need to be added for this topic