msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Wed Mar 11, 2015 6:09 am

If everything is identical, then it should work - as long as the cabling polarity is correct and the bus is properly terminated.

As for the "poor mans logic analyzer":
[*]Connect a can transceiver to your can bus
[*]connect the rx pin via a voltage divider to a pin on the rpi
[*]run a programm that samples the specific pin at high frequency(know that frequency/sample rate)
[*]from this you can estimate the actual bit length on the bus

The other approach is to buy a logic analyzer/oscilloscope.

rudwna
Posts: 4
Joined: Sun Nov 09, 2014 8:54 pm

Re: CAN controller

Wed Mar 11, 2015 11:43 am

I thoughts i found the the problem. I've been prototyping them on breadboard and .. after I fiddling with some wires I've found that the power wires onto breadboard (or maybe the breadboard contact) is actually a problem. So I move it to somewhere else and ... it just works :|

Thank you very much for your help Martin!

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Wed Mar 11, 2015 11:47 am

No problem
BTW: you now use the latest foundation kernels with the device overlay for the mcp2515!

skpang
Posts: 19
Joined: Mon Jul 29, 2013 10:09 pm
Location: Essex, UK

Re: CAN controller

Wed Mar 11, 2015 6:56 pm

Thanks Martin (let me know if you want a PiCAN board) for the latest kernel with device overlay built in.
I've done a step by step instructions of the installation at:

http://skpang.co.uk/blog/archives/1165

SK Pang

User avatar
Tiqni
Posts: 15
Joined: Wed Mar 11, 2015 2:03 pm

Re: CAN controller

Fri Mar 13, 2015 9:54 am

Hi all,

I did recently a step-by-step post to use CAN Bus in Raspberry Pi, independently of any shield, and that works for latest Raspbian 3.18.7+.
http://tiqni.com/raspberry-pi/can-bus-s ... spberry-pi

If you need also help for electrical schematic, please let me know it.

Good luck !

Regards

bapou
Posts: 5
Joined: Wed Mar 04, 2015 4:03 pm

Re: CAN controller

Fri Mar 13, 2015 10:47 am

@Tiqni
If I see it right, your approach works only for the RPI A, or B+ but not the RPI 2.

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Fri Mar 13, 2015 11:10 am

the approach using the foundation kernels works for RPI and RPI2.

User avatar
Tiqni
Posts: 15
Joined: Wed Mar 11, 2015 2:03 pm

Re: CAN controller

Fri Mar 13, 2015 12:14 pm

@bapou
msperl wrote:the approach using the foundation kernels works for RPI and RPI2.
As said by msperl, I don't see any reason for what Raspberry Pi 2 is not supported, since the same SPI chip is used.

jchernus
Posts: 5
Joined: Fri Mar 13, 2015 3:16 pm
Location: Saskatoon, Saskatchewan

Re: CAN controller

Fri Mar 13, 2015 3:37 pm

Hello everyone!

I'm very happy I found this forum, it has already been very helpful in getting my CAN system up and running. Thank you very much!

I'm working on a project to create a CAN-Bus Datalogger. I followed the instructions on CANned Pi to get my system setup. My problem is that I cannot see any CAN messages coming off my vehicle even though everything seems to be setup properly. See screenshot below:

Image Link to full size image.

The vehicle I'm using is running OpenCAN but when I was using the SPKang CAN Bus Shield for the Arduino, I did not encounter any problems. Setup was easy and it was working right away.

Please let me know what I could be doing wrong. I am brand new to Linux and Raspberry Pi (just started yesterday!) but I'm very excited to get things working.

Thank you,

Julia

User avatar
Tiqni
Posts: 15
Joined: Wed Mar 11, 2015 2:03 pm

Re: CAN controller

Sat Mar 14, 2015 8:47 am

Hi Julia,

From what I can see there is no SW problem, maybe you are not using the same Raspbian version like in the attached link.
However I can advise you to use latest modules versions : http://tiqni.com/raspberry-pi/can-bus-s ... spberry-pi

You mentioned Arduino shield, so it's probably a voltage issue, the MCP2551 uses 5V, while Raspberry Pi GPIO and MCP2515 use 3,3V.
So you need to make a voltage divider between them like described here : http://lnxpps.de/rpie/

Good luck !

jchernus
Posts: 5
Joined: Fri Mar 13, 2015 3:16 pm
Location: Saskatoon, Saskatchewan

Re: CAN controller

Sat Mar 14, 2015 3:25 pm

Hi Tiqni,

Thank you for your help. I happen to have both shields - one for the Arduino, and one for the Pi. So that should not be a problem.

I have the suggested Raspbian version from the CANned Pi article (3.12.28+) but I can retry with a newer version as you suggest.

Thank you, I will post an update when I am done!

Julia

jchernus
Posts: 5
Joined: Fri Mar 13, 2015 3:16 pm
Location: Saskatoon, Saskatchewan

Re: CAN controller

Mon Mar 16, 2015 4:04 pm

Thank worked, thank you very much!! This forum is great :)

User avatar
Tiqni
Posts: 15
Joined: Wed Mar 11, 2015 2:03 pm

Re: CAN controller

Mon Mar 16, 2015 4:41 pm

You're welcome :)

TeeTrinker
Posts: 6
Joined: Tue Jan 13, 2015 8:34 am

Re: CAN controller

Wed Mar 18, 2015 11:03 am

Hi Rpi Community,

My PICAN worked like a charm the last few weeks.
Now i encountered a problem where after each Message send on my bus, i wasnt able to send a second message. I had to reboot my can-device :
ifconfig can0 down
ifconfig can0 up

to send the next message. I did not change any of my setup and it was working before.
Does anyone know what the problem could be ? I think it might be some kind of hardware issue, since the loopback mode worked without any problems.


I tried to solve the problem through an software update but when i updated my kernel to 3.18.7+ and loaded the CAN modules from lnxpp.de/rpie my spi-2708 module could not be loaded. everything else could (can, can-dev, can-raw...).
When i tried to modify my blacklist in the usual /etc/modprobe.d/raspi-blacklist.conf I noticed that the blacklistfile did not exist. So either i dont have blacklisted any or the file moved its place. On my SD-card with the 3.12.35+ Kernel the Blacklist.conf is in that exact spot.

So I have the following questions:
why can i only send one message? (and how can i fix that)
and where did my Blacklist go? If the above indicates, that i do not have a blacklist, why am i not able to load spi-bcm2708?
error code for:
~$ sudo modprobe spi-bcm2708
ERROR: could not insert 'spi_bcm2708':No such device

Greetings
TeeTrinker

User avatar
Tiqni
Posts: 15
Joined: Wed Mar 11, 2015 2:03 pm

Re: CAN controller

Wed Mar 18, 2015 11:22 am

Hi TeeTrinker,

Why you can't send many messages ?
> I have sometimes the same problem, it's mainly due to SPI latency, so I had to down/up can0 to make it working again.
Another possibility is that your SW/HW changes (update, new CAN bus ?)

Where the blacklist goes ?
> The latest Raspbian version (3.18) doesn't include it. I had the same remark when I updated my Raspberry Pi.

Problems after update ?
> Please check the end of this post (http://tiqni.com/raspberry-pi/can-bus-s ... spberry-pi), one of problems is spi-2835 instead of spi-2708. Check your SPI modules like explained in the post.

Good luck !

TeeTrinker
Posts: 6
Joined: Tue Jan 13, 2015 8:34 am

Re: CAN controller

Fri Mar 20, 2015 7:47 am

Hi Tinqui,
Thanks for the reply. The link actually did it for me. did not have spi - enabled on the 3.18.7+ Kernel. Stupid me!
But still don't know what the other problem on 3.12.35+ was. I can see messages on CAN bus through CANoe, and just the first message came through. The second message was not displayed. To send a second message i had to reboot canbus with ifconfig up/down.

But to be honest i didn't investigate it further since it is working with the 3.18.7+ Kernel.

Greetings,
Teetrinker

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Fri Mar 20, 2015 5:35 pm

actually this "one message only" issue with 3.12.x kernel could be related to some interrupt handling bug in the mcp251x driver that could only get resolved during a restart. But this was actually (mostly) related to receiving too many packets in a short time.

The driver in the new 3.18.x kernel does not exhibit this kind of behaviour.

Romey-Rome
Posts: 13
Joined: Sun Mar 22, 2015 10:34 am

Re: CAN controller

Sun Mar 22, 2015 10:50 am

I can't get this design to work for nothin' http://hackaday.io/project/346-canpi on Pi2.

Using the "new" overlay method. This is my first run at it, so I have no previous working version for refference.

Schematic:
Image

lsmod:

Code: Select all

root@raspberrypi:~# lsmod
Module                  Size  Used by
bnep                   10206  2 
binfmt_misc             6370  1 
i2c_dev                 6027  0 
snd_bcm2835            18665  0 
snd_pcm                73475  1 snd_bcm2835
snd_timer              17784  1 snd_pcm
snd                    50998  3 snd_bcm2835,snd_timer,snd_pcm
fuse                   82155  1 
mcp251x                 8640  0 
ecb                     2027  1 
can_dev                 9187  1 mcp251x
spi_bcm2835             3086  0 
i2c_bcm2708             4990  0 
btusb                  19521  0 
bluetooth             287204  21 bnep,btusb
uio_pdrv_genirq         2958  0 
uio                     8119  1 uio_pdrv_genirq
rfkill                 16651  2 bluetooth
dmesg:

Code: Select all

root@raspberrypi:~# dmesg 
[    0.000000] Booting Linux on physical CPU 0xf00
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.18.9-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #768 SMP PREEMPT Sun Mar 15 19:41:56 GMT 2015
[    0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] Machine model: Raspberry Pi 2 Model B
[    0.000000] cma: Reserved 8 MiB at 0x3a800000
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] On node 0 totalpages: 241664
[    0.000000] free_area_init_node: node 0, pgdat 80809440, node_mem_map ba093000
[    0.000000]   Normal zone: 1888 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 241664 pages, LIFO batch:31
[    0.000000] [bcm2709_smp_init_cpus] enter (8620->f3003010)
[    0.000000] [bcm2709_smp_init_cpus] ncores=4
[    0.000000] PERCPU: Embedded 10 pages/cpu @ba060000 s11456 r8192 d21312 u40960
[    0.000000] pcpu-alloc: s11456 r8192 d21312 u40960 alloc=10*4096
[    0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 239776
[    0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2709.boardrev=0xa21041 bcm2709.serial=0xa2dd6313 smsc95xx.macaddr=B8:27:EB:DD:63:13 bcm2708_fb.fbswap=1 bcm2709.disk_led_gpio=47 bcm2709.disk_led_active_low=0 sdhci-bcm2708.emmc_clock_freq=250000000 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[    0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Memory: 940852K/966656K available (5705K kernel code, 397K rwdata, 1740K rodata, 384K init, 763K bss, 25804K reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xffe00000   (2048 kB)
[    0.000000]     vmalloc : 0xbb800000 - 0xff000000   (1080 MB)
[    0.000000]     lowmem  : 0x80000000 - 0xbb000000   ( 944 MB)
[    0.000000]     modules : 0x7f000000 - 0x80000000   (  16 MB)
[    0.000000]       .text : 0x80008000 - 0x8074d700   (7446 kB)
[    0.000000]       .init : 0x8074e000 - 0x807ae000   ( 384 kB)
[    0.000000]       .data : 0x807ae000 - 0x8081147c   ( 398 kB)
[    0.000000]        .bss : 0x8081147c - 0x808d01d4   ( 764 kB)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Preemptible hierarchical RCU implementation.
[    0.000000] NR_IRQS:608
[    0.000000] Architected cp15 timer(s) running at 19.20MHz (virt).
[    0.000013] sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 3579139424256ns
[    0.000036] Switching to timer-based delay loop, resolution 52ns
[    0.000336] Console: colour dummy device 80x30
[    0.001805] console [tty1] enabled
[    0.001855] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000)
[    0.001938] pid_max: default: 32768 minimum: 301
[    0.002340] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.002402] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.003666] Initializing cgroup subsys memory
[    0.003756] Initializing cgroup subsys devices
[    0.003812] Initializing cgroup subsys freezer
[    0.003882] Initializing cgroup subsys net_cls
[    0.003934] Initializing cgroup subsys blkio
[    0.004046] CPU: Testing write buffer coherency: ok
[    0.004161] ftrace: allocating 19576 entries in 58 pages
[    0.052411] CPU0: update cpu_capacity 1024
[    0.052489] CPU0: thread -1, cpu 0, socket 15, mpidr 80000f00
[    0.052529] [bcm2709_smp_prepare_cpus] enter
[    0.052685] Setting up static identity map for 0x525438 - 0x52546c
[    0.112345] [bcm2709_boot_secondary] cpu:1 started (0) 18
[    0.112659] CPU1: Booted secondary processor
[    0.112667] [bcm2709_secondary_init] enter cpu:1
[    0.112715] CPU1: update cpu_capacity 1024
[    0.112724] CPU1: thread -1, cpu 1, socket 15, mpidr 80000f01
[    0.132312] [bcm2709_boot_secondary] cpu:2 started (0) 17
[    0.132565] CPU2: Booted secondary processor
[    0.132571] [bcm2709_secondary_init] enter cpu:2
[    0.132601] CPU2: update cpu_capacity 1024
[    0.132609] CPU2: thread -1, cpu 2, socket 15, mpidr 80000f02
[    0.152368] [bcm2709_boot_secondary] cpu:3 started (0) 18
[    0.152611] CPU3: Booted secondary processor
[    0.152618] [bcm2709_secondary_init] enter cpu:3
[    0.152646] CPU3: update cpu_capacity 1024
[    0.152654] CPU3: thread -1, cpu 3, socket 15, mpidr 80000f03
[    0.152749] Brought up 4 CPUs
[    0.152873] SMP: Total of 4 processors activated (153.60 BogoMIPS).
[    0.152907] CPU: All CPU(s) started in SVC mode.
[    0.153932] devtmpfs: initialized
[    0.179074] VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
[    0.181088] pinctrl core: initialized pinctrl subsystem
[    0.184365] NET: Registered protocol family 16
[    0.189999] DMA: preallocated 4096 KiB pool for atomic coherent allocations
[    0.191180] bcm2709.uart_clock = 3000000
[    0.194400] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
[    0.194456] hw-breakpoint: maximum watchpoint size is 8 bytes.
[    0.194516] mailbox: Broadcom VideoCore Mailbox driver
[    0.194651] bcm2708_vcio: mailbox at f300b880
[    0.195014] bcm_power: Broadcom power driver
[    0.195059] bcm_power_open() -> 0
[    0.195086] bcm_power_request(0, 8)
[    0.695766] bcm_mailbox_read -> 00000080, 0
[    0.695800] bcm_power_request -> 0
[    0.695965] Serial: AMBA PL011 UART driver
[    0.696116] dev:f1: ttyAMA0 at MMIO 0x3f201000 (irq = 83, base_baud = 0) is a PL011 rev3
[    1.204203] console [ttyAMA0] enabled
[    1.275606] SCSI subsystem initialized
[    1.279627] usbcore: registered new interface driver usbfs
[    1.285296] usbcore: registered new interface driver hub
[    1.290769] usbcore: registered new device driver usb
[    1.297701] Switched to clocksource arch_sys_counter
[    1.332824] FS-Cache: Loaded
[    1.336049] CacheFiles: Loaded
[    1.350585] NET: Registered protocol family 2
[    1.356233] TCP established hash table entries: 8192 (order: 3, 32768 bytes)
[    1.363492] TCP bind hash table entries: 8192 (order: 4, 65536 bytes)
[    1.370224] TCP: Hash tables configured (established 8192 bind 8192)
[    1.376705] TCP: reno registered
[    1.379994] UDP hash table entries: 512 (order: 2, 16384 bytes)
[    1.385982] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes)
[    1.392723] NET: Registered protocol family 1
[    1.397764] RPC: Registered named UNIX socket transport module.
[    1.403707] RPC: Registered udp transport module.
[    1.408452] RPC: Registered tcp transport module.
[    1.413169] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    1.420623] hw perfevents: enabled with armv7_cortex_a7 PMU driver, 5 counters available
[    1.429038] bcm2708_dma: DMA manager at f3007000
[    1.433841] vc-mem: phys_addr:0x00000000 mem_base=0x3dc00000 mem_size:0x3f000000(1008 MiB)
[    1.443698] futex hash table entries: 1024 (order: 4, 65536 bytes)
[    1.450166] audit: initializing netlink subsys (disabled)
[    1.455639] audit: type=2000 audit(1.239:1): initialized
[    1.477166] VFS: Disk quotas dquot_6.5.2
[    1.481532] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    1.491084] FS-Cache: Netfs 'nfs' registered for caching
[    1.497433] NFS: Registering the id_resolver key type
[    1.502640] Key type id_resolver registered
[    1.506839] Key type id_legacy registered
[    1.512055] msgmni has been set to 1853
[    1.517683] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
[    1.525331] io scheduler noop registered
[    1.529310] io scheduler deadline registered (default)
[    1.534790] io scheduler cfq registered
[    1.541324] BCM2708FB: allocated DMA memory fac00000
[    1.546339] BCM2708FB: allocated DMA channel 0 @ f3007000
[    1.557449] Console: switching to colour frame buffer device 82x26
[    1.569479] bcm2708-dmaengine bcm2708-dmaengine: Load BCM2835 DMA engine driver
[    1.578786] uart-pl011 dev:f1: no DMA platform data
[    1.585766] vc-cma: Videocore CMA driver
[    1.591297] vc-cma: vc_cma_base      = 0x00000000
[    1.597548] vc-cma: vc_cma_size      = 0x00000000 (0 MiB)
[    1.604491] vc-cma: vc_cma_initial   = 0x00000000 (0 MiB)
[    1.623258] brd: module loaded
[    1.633807] loop: module loaded
[    1.638725] vchiq: vchiq_init_state: slot_zero = 0xba800000, is_master = 0
[    1.647898] Loading iSCSI transport class v2.0-870.
[    1.655219] usbcore: registered new interface driver smsc95xx
[    1.662587] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    1.870212] Core Release: 2.80a
[    1.874831] Setting default values for core params
[    1.881132] Finished setting default values for core params
[    2.088604] Using Buffer DMA mode
[    2.093387] Periodic Transfer Interrupt Enhancement - disabled
[    2.100769] Multiprocessor Interrupt Enhancement - disabled
[    2.107901] OTG VER PARAM: 0, OTG VER FLAG: 0
[    2.113815] Dedicated Tx FIFOs mode
[    2.119190] WARN::dwc_otg_hcd_init:1047: FIQ DMA bounce buffers: virt = 0xbac14000 dma = 0xfac14000 len=9024
[    2.132161] FIQ FSM acceleration enabled for :
[    2.132161] Non-periodic Split Transactions
[    2.132161] Periodic Split Transactions
[    2.132161] High-Speed Isochronous Endpoints
[    2.155124] dwc_otg: Microframe scheduler enabled
[    2.155200] WARN::hcd_init_fiq:412: FIQ on core 1 at 0x803d6a28
[    2.162757] WARN::hcd_init_fiq:413: FIQ ASM at 0x803d6d84 length 36
[    2.170668] WARN::hcd_init_fiq:438: MPHI regs_base at 0xbb80a000
[    2.178285] dwc_otg bcm2708_usb: DWC OTG Controller
[    2.184793] dwc_otg bcm2708_usb: new USB bus registered, assigned bus number 1
[    2.193695] dwc_otg bcm2708_usb: irq 32, io mem 0x00000000
[    2.200826] Init: Port Power? op_state=1
[    2.206291] Init: Power Port (0)
[    2.211326] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    2.219738] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    2.228561] usb usb1: Product: DWC OTG Controller
[    2.234809] usb usb1: Manufacturer: Linux 3.18.9-v7+ dwc_otg_hcd
[    2.242435] usb usb1: SerialNumber: bcm2708_usb
[    2.249430] hub 1-0:1.0: USB hub found
[    2.254753] hub 1-0:1.0: 1 port detected
[    2.260662] dwc_otg: FIQ enabled
[    2.260676] dwc_otg: NAK holdoff enabled
[    2.260687] dwc_otg: FIQ split-transaction FSM enabled
[    2.260725] Module dwc_common_port init
[    2.261129] usbcore: registered new interface driver usb-storage
[    2.268965] mousedev: PS/2 mouse device common for all mice
[    2.276689] bcm2835-cpufreq: min=600000 max=900000
[    2.283372] sdhci: Secure Digital Host Controller Interface driver
[    2.291142] sdhci: Copyright(c) Pierre Ossman
[    2.297214] DMA channels allocated for the MMC driver
[    2.337744] Load BCM2835 MMC driver
[    2.344577] sdhci-pltfm: SDHCI platform and OF driver helper
[    2.355845] ledtrig-cpu: registered to indicate activity on CPUs
[    2.365822] hidraw: raw HID events driver (C) Jiri Kosina
[    2.373145] usbcore: registered new interface driver usbhid
[    2.380392] usbhid: USB HID core driver
[    2.387165] TCP: cubic registered
[    2.392088] Initializing XFRM netlink socket
[    2.398014] NET: Registered protocol family 17
[    2.404185] Key type dns_resolver registered
[    2.413769] Registering SWP/SWPB emulation handler
[    2.421070] registered taskstats version 1
[    2.426921] vc-sm: Videocore shared memory driver
[    2.433163] [vc_sm_connected_init]: start
[    2.439406] [vc_sm_connected_init]: end - returning 0
[    2.447135] Waiting for root device /dev/mmcblk0p2...
[    2.457846] Indeed it is in host mode hprt0 = 00021501
[    2.461152] mmc0: host does not support reading read-only switch, assuming write-enable
[    2.463284] mmc0: new high speed SDHC card at address b368
[    2.463920] mmcblk0: mmc0:b368       14.9 GiB 
[    2.476845]  mmcblk0: p1 p2
[    2.576066] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    2.587372] VFS: Mounted root (ext4 filesystem) readonly on device 179:2.
[    2.596884] devtmpfs: mounted
[    2.602171] Freeing unused kernel memory: 384K (8074e000 - 807ae000)
[    2.667855] usb 1-1: new high-speed USB device number 2 using dwc_otg
[    2.676381] Indeed it is in host mode hprt0 = 00001101
[    2.878107] usb 1-1: New USB device found, idVendor=0424, idProduct=9514
[    2.886661] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    2.896503] hub 1-1:1.0: USB hub found
[    2.902258] hub 1-1:1.0: 5 ports detected
[    3.187999] usb 1-1.1: new high-speed USB device number 3 using dwc_otg
[    3.308294] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00
[    3.317288] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    3.329524] smsc95xx v1.0.4
[    3.391920] smsc95xx 1-1.1:1.0 eth0: register 'smsc95xx' at usb-bcm2708_usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:dd:63:13
[    3.648036] usb 1-1.4: new full-speed USB device number 4 using dwc_otg
[    3.770424] udevd[170]: starting version 175
[    3.802754] usb 1-1.4: New USB device found, idVendor=0a12, idProduct=0001
[    3.812607] usb 1-1.4: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[    3.822949] usb 1-1.4: Product: CSR8510 A10
[    4.427524] Bluetooth: Core ver 2.19
[    4.450023] NET: Registered protocol family 31
[    4.469364] Bluetooth: HCI device and connection manager initialized
[    4.480651] Bluetooth: HCI socket layer initialized
[    4.487893] Bluetooth: L2CAP socket layer initialized
[    4.495151] Bluetooth: SCO socket layer initialized
[    4.522479] usbcore: registered new interface driver btusb
[    4.594857] bcm2708_i2c_init_pinmode(1,2)
[    4.614046] bcm2708_i2c_init_pinmode(1,3)
[    4.640479] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000)
[    4.751580] CAN device driver interface
[    4.914027] random: nonblocking pool is initialized
[    6.381399] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[    6.843861] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[    7.415408] fuse init (API version 7.23)
[    7.595005] i2c /dev entries driver
[   12.100958] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[   13.561194] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC5E1
[   14.816291] Adding 102396k swap on /var/swap.  Priority:-1 extents:2 across:2134012k SSFS
[   15.527292] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   15.527344] Bluetooth: BNEP filters: protocol multicast
[   15.527412] Bluetooth: BNEP socket layer initialized
/boot/config.txt

Code: Select all

dtparam=spi=on
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay

Code: Select all

root@raspberrypi:~# uname -a
Linux raspberrypi 3.18.9-v7+ #768 SMP PREEMPT Sun Mar 15 19:41:56 GMT 2015 armv7l GNU/Linux

root@raspberrypi:~# /sbin/ip link set can0 up type can bitrate 500000
Cannot find device "can0"
I tried loading all the various cad-dev/cat-raw/etc modules with no luck. Everything is the newest version available.

Thanks!
Last edited by Romey-Rome on Sun Mar 22, 2015 8:07 pm, edited 1 time in total.

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Sun Mar 22, 2015 12:50 pm

Please also add the following to /boot/config.txt:

Code: Select all

dtdebug=on
then reboot.

Please run:

Code: Select all

head /sys/bus/spi/devices/spi*/modalias
as well as:

Code: Select all

sudo vcdbg log msg
and share the output?

Thanks, Martin

Romey-Rome
Posts: 13
Joined: Sun Mar 22, 2015 10:34 am

Re: CAN controller

Sun Mar 22, 2015 7:52 pm

Code: Select all

root@raspberrypi:~# head /sys/bus/spi/devices/spi*/modalias
==> /sys/bus/spi/devices/spi0.0/modalias <==
spi:mcp2515

==> /sys/bus/spi/devices/spi0.1/modalias <==
spi:spidev

Code: Select all

root@raspberrypi:~# vcdbg log msg
000695.394: HDMI:EDID error reading EDID block 0 attempt 0
000696.657: HDMI:EDID error reading EDID block 0 attempt 1
000697.916: HDMI:EDID error reading EDID block 0 attempt 2
000699.174: HDMI:EDID error reading EDID block 0 attempt 3
000700.434: HDMI:EDID error reading EDID block 0 attempt 4
000701.692: HDMI:EDID error reading EDID block 0 attempt 5
000702.952: HDMI:EDID error reading EDID block 0 attempt 6
000704.211: HDMI:EDID error reading EDID block 0 attempt 7
000705.470: HDMI:EDID error reading EDID block 0 attempt 8
000706.729: HDMI:EDID error reading EDID block 0 attempt 9
000707.751: HDMI:EDID giving up on reading EDID block 0
000710.482: HDMI:Setting property pixel encoding to Default
000710.504: HDMI:Setting property pixel clock type to PAL
000710.522: HDMI:Setting property content type flag to No data
000710.544: HDMI:Setting property fuzzy format match to enabled
000715.996: gpioman: gpioman_get_pin_num: pin LEDS_RUNNING not defined
000716.019: gpioman: gpioman_get_pin_num: pin LEDS_NAND_ACTIVITY not defined
000716.040: gpioman: gpioman_get_pin_num: pin LEDS_USB_ACTIVITY not defined
000716.061: gpioman: gpioman_get_pin_num: pin LEDS_FATAL_ERROR not defined
000716.082: gpioman: gpioman_get_pin_num: pin LEDS_APP_OK not defined
000716.104: gpioman: gpioman_get_pin_num: pin LEDS_APP_FAILED not defined
000716.123: gpioman: gpioman_get_pin_num: pin LEDS_HDCP_AUTH not defined
000716.145: gpioman: gpioman_get_pin_num: pin LEDS_HDCP_UNAUTH not defined
000716.167: gpioman: gpioman_get_pin_num: pin LEDS_HDMI_ON not defined
000716.188: gpioman: gpioman_get_pin_num: pin LEDS_DVI_ON not defined
000716.210: gpioman: gpioman_get_pin_num: pin LEDS_HDMI_HPD_UP not defined
000716.231: gpioman: gpioman_get_pin_num: pin LEDS_REMOTE_CONTROL not defined
000716.251: gpioman: gpioman_get_pin_num: pin LEDS_ARM_CONTROLLED not defined
000734.293: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
000734.319: hdmi: HDMI:>>>>>>>>>>>>>Rx sensed, reading EDID<<<<<<<<<<<<<
000734.715: hdmi: HDMI:EDID error reading EDID block 0 attempt 0
000735.984: hdmi: HDMI:EDID error reading EDID block 0 attempt 1
000737.248: hdmi: HDMI:EDID error reading EDID block 0 attempt 2
000738.512: hdmi: HDMI:EDID error reading EDID block 0 attempt 3
000739.776: hdmi: HDMI:EDID error reading EDID block 0 attempt 4
000741.040: hdmi: HDMI:EDID error reading EDID block 0 attempt 5
000742.304: hdmi: HDMI:EDID error reading EDID block 0 attempt 6
000743.568: hdmi: HDMI:EDID error reading EDID block 0 attempt 7
000744.832: hdmi: HDMI:EDID error reading EDID block 0 attempt 8
000746.096: hdmi: HDMI:EDID error reading EDID block 0 attempt 9
000747.123: hdmi: HDMI:EDID giving up on reading EDID block 0
000747.152: hdmi: HDMI: No lookup table for resolution group 0
000747.169: hdmi: HDMI: hotplug attached with DVI support
000747.230: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
000747.599: hdmi: HDMI:EDID error reading EDID block 0 attempt 0
000748.860: hdmi: HDMI:EDID error reading EDID block 0 attempt 1
000750.123: hdmi: HDMI:EDID error reading EDID block 0 attempt 2
000751.385: hdmi: HDMI:EDID error reading EDID block 0 attempt 3
000752.647: hdmi: HDMI:EDID error reading EDID block 0 attempt 4
000753.909: hdmi: HDMI:EDID error reading EDID block 0 attempt 5
000755.171: hdmi: HDMI:EDID error reading EDID block 0 attempt 6
000756.433: hdmi: HDMI:EDID error reading EDID block 0 attempt 7
000757.695: hdmi: HDMI:EDID error reading EDID block 0 attempt 8
000758.957: hdmi: HDMI:EDID error reading EDID block 0 attempt 9
000759.982: hdmi: HDMI:EDID giving up on reading EDID block 0
000760.042: hdmi: HDMI: hotplug deassert
000760.057: hdmi: HDMI: HDMI is currently off
000760.072: hdmi: HDMI: changing mode to unplugged
000760.095: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
000760.888: *** Restart logging

000761.848: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

000766.766: Loading 'kernel7.img' from SD card
000997.898: Kernel trailer DTOK property says yes
000998.026: Loading 'bcm2709-rpi-2-b.dtb' from SD card
001024.451: dtparam: spi=on
001027.206: dtparam: i2c_arm=on
001041.678: Loaded overlay 'mcp2515-can0-overlay'
001070.813: dtparam: oscillator=16000000
001073.986: dtparam: interrupt=25
001085.215: Loaded overlay 'spi-bcm2835-overlay'
001093.476: dtparam: arm_freq=900000000
001151.256: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
003250.128: vchiq_core: vchiq_init_state: slot_zero = 0xfa800000, is_master = 1
003253.589: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
003257.264: gpioman: gpioman_get_pin_num: pin LEDS_RUNNING not defined
003257.290: gpioman: gpioman_get_pin_num: pin LEDS_NAND_ACTIVITY not defined
003257.313: gpioman: gpioman_get_pin_num: pin LEDS_USB_ACTIVITY not defined
003257.335: gpioman: gpioman_get_pin_num: pin LEDS_FATAL_ERROR not defined
003257.355: gpioman: gpioman_get_pin_num: pin LEDS_APP_OK not defined
003257.375: gpioman: gpioman_get_pin_num: pin LEDS_APP_FAILED not defined
003257.398: gpioman: gpioman_get_pin_num: pin LEDS_HDCP_AUTH not defined
003257.418: gpioman: gpioman_get_pin_num: pin LEDS_HDCP_UNAUTH not defined
003257.440: gpioman: gpioman_get_pin_num: pin LEDS_HDMI_ON not defined
003257.460: gpioman: gpioman_get_pin_num: pin LEDS_DVI_ON not defined
003257.480: gpioman: gpioman_get_pin_num: pin LEDS_HDMI_HPD_UP not defined
003257.503: gpioman: gpioman_get_pin_num: pin LEDS_REMOTE_CONTROL not defined
003257.526: gpioman: gpioman_get_pin_num: pin LEDS_ARM_CONTROLLED not defined
Thanks!

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Sun Mar 22, 2015 10:02 pm

Device tree looks fine.

Are you sure the cabling is done correctly as per your diagram?
That seems to be the only thing left open.

The only other thing I can think of is to run the following shell script (which runs spi bitbang inside a shell script):

Code: Select all

#! /bin/sh

CS=8
test -z "$1" || CS=$1
SCLK=11
MOSI=10
MISO=9

#config SPI Pins and Directions
CONFIG_PINS() {
(while read gpio dir level; do
  test -f /sys/class/gpio/gpio$gpio/value || echo $gpio > /sys/class/gpio/export
  echo $dir >  /sys/class/gpio/gpio$gpio/direction
  test -z "$level" || echo $level >  /sys/class/gpio/gpio$gpio/value
done) <<EOF
$CS   out 1
$MISO in
$MOSI out 0
$SCLK out 0
EOF
}

UNCONFIG_PINS() {
(while read gpio dir level; do
  test -f /sys/class/gpio/gpio$gpio/value || echo $gpio > /sys/class/gpio/unexport
done) <<EOF
$CS
$MISO
$MOSI
$SCLK
EOF
}

CS() {
  echo "$1" > /sys/class/gpio/gpio$CS/value
}

MOSI() {
  echo "$1" > /sys/class/gpio/gpio$MOSI/value
}

SCLK() {
  echo "$1" > /sys/class/gpio/gpio$SCLK/value
}

spi_send() {
  echo "$1" \
      | awk '{X=$1;for(i=128;i>=1;i/=2){B=0;if (X>=i){ B=1;X-=i;}print i,B}}' \
      | while read bit v; do
        MOSI $v
        SCLK 1
        echo -n "$bit "
        cat /sys/class/gpio/gpio$MISO/value
        SCLK 0
      done \
      | awk 'BEGIN{C=0}{if ($2){C+=$1}}END{printf "%-20s %3i 0x%02x\n","'$2'",C,C;}'
}

CONFIG_PINS

# reset mcp2515
echo "Resetting MCP2515"
CS 0
spi_send 192 RESET
CS 1

# wait some time
sleep 1

# and read the registers
echo "Read MCP2515 registers"
CS 0
spi_send 3  CMD-READ
spi_send 40 REG-CNF3
spi_send 0 CNF3
spi_send 0 CNF2
spi_send 0 CNF1
spi_send 0 INTE
spi_send 0 INTF
spi_send 0 EFLG
spi_send 0 CANSTAT
spi_send 0 CANCTRL
CS 1

UNCONFIG_PINS
The output should look like this:

Code: Select all

Resetting MCP2515
RESET                  0 0x00
Read MCP2515 registers
CMD-READ               0 0x00
REG-CNF3               0 0x00
CNF3                   0 0x00
CNF2                   0 0x00
CNF1                   0 0x00
INTE                   0 0x00
INTF                   0 0x00
EFLG                   0 0x00
CANSTAT              128 0x80
CANCTRL              135 0x87
Can you check that?

Any difference would indicate an issue with the wireing, but that is impossible to debug from afar...

Romey-Rome
Posts: 13
Joined: Sun Mar 22, 2015 10:34 am

Re: CAN controller

Sun Mar 22, 2015 10:50 pm

Yeah. I get:

Code: Select all

Resetting MCP2515
RESET                  0 0x00
Read MCP2515 registers
CMD-READ               0 0x00
REG-CNF3               0 0x00
CNF3                   0 0x00
CNF2                   0 0x00
CNF1                   0 0x00
INTE                   0 0x00
INTF                   0 0x00
EFLG                   0 0x00
CANSTAT                0 0x00
CANCTRL                0 0x00
Last 2 are different.

Maybe it is the HW. I have parts on order to build another one. We'll see. If I still can't get it to go, I'll get an off-the shelf product.

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Sun Mar 22, 2015 11:31 pm

Just check with an mcp2515 on a breadboard - Just connect miso/mosi/sck/cs0/gnd/3v3 to the mcp2515 and the script should work and show the values above.

But beware: you may also need a working clock/resonator to get spi on the mcp2515 working in the first place - can not remember if I have ever tried without...

Romey-Rome
Posts: 13
Joined: Sun Mar 22, 2015 10:34 am

Re: CAN controller

Mon Mar 23, 2015 2:12 am

I checked continuity of all the needed mcp2515 pins, and they all go to the right GPIO pins. Unfortunately I don't have an oscilloscope to do any real testing.

Maybe I fried the IC . I just looked @ the MCP data-sheet for the max soldering temps, and I may (read: definitely) have gone too hot with the iron.

Thanks for your help!

msperl
Posts: 356
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Mon Mar 23, 2015 6:01 am

For completeness:
Connect gpio7 (cs1) with gpio9 (miso) directly(maybe with a 1k resistor) without anything else connected to the pi.
Then run the script above again, but give an argument of "7" to the script to use the second chip-select.
If it returns 255/0xff for all then the portion on the pi is fine.

Subsequently you could also check the same, but with your board connected as well - if you read anything else, then you got some sort of short on the miso line.

Return to “Interfacing (DSI, CSI, I2C, etc.)”