I read chapter 2.6.1 "Alternative function assignments" in the "Raspberry Pi Compute Module 5" manual _carefully_ before deciding on the GPIO pin assignment in my schematic. I decided on using SPI4, I2C0 and UART2. Too bad I didn't read the rest of the manual. Especially the table where the clearly states that SPI4 is "slave only"
Fortunately it seems that I can use SPI0 with the SPI4 pinout using some device tree magic. The following line in config.txt did the trick:
dtoverlay=spi0-1cs,cs0_pin=8,sclk_pin=11,miso_pin=9,mosi_pin=8
Next up was defining the overlay for the MCP2515
dtoverlay=mcp2515-can0,oscillator=8000000,cs_pin=8,sclk_pin=11,miso_pin=9,mosi_pin=8
Do you spot the second brain fart already ? (The Xiaomi Cybergears default to a bitrate of 1000000)
Now I had to make sure that the mcp driver was loaded
> echo "mcp251x" | sudo tee -a /etc/modules
After a quick reboot, i checked dmesg
hansj@cyber-1:~ $ dmesg | grep 2515
[ 4.277991] mcp251x spi0.0 can0: MCP2515 successfully initialized.
Yaaaay - right...?
Now it was tTime to bring up can0
sudo ip link set can0 up type can bitrate 1000000
Error: bitrate error: 33.3% too high.
Wooops...
Turned out I hadn't looked to carefully at the MCP2515 datasheet either, so I had selected a 8MHz crystal without thinking about the implications regarding the maximum bitrate the mcp could support given the frequency of the oscillator. I can do a bitrate of 500000, but not 1000000.
This is fixable by changing the Cybergear bitrate using communication type 22 via another tool, but I decided to order some 16Mhz crystals from Mouser instead (along with some 22pF capacitors). I guess they will arrive in a couple of days.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.