Interfacing

CAN controller

119 36470
FPeter  
I dont know what causes the messed ID-s (compared to Saleae Logic, mikroe ECAN library, etc), but NMEA 2000 PGN-s can be extracted from message ID-s by:
  1. pgn = (( rx[i].id & 0x0000007F ) << 10 ) + (( rx[i].id & 0x1FF80000 ) >> 19 );
Copy the Code
Here is the sample output of my modified receiver.c, acts as simple hard-coded NMEA2000 parser (under construction):
  1. ret=1 id=0x0858037d len=8 flags=0x04 eD  ( 8)  f4 14 27 00 00 ff 7f ff
  2.         PGN=128267 - Water Depth
  3.                 SID = 244
  4.                 Depth = 100.04 m        Depth below transducer
  5.                 Offset = 0.0000 m       Distance between transducer and surface (positive) or keel (negative)

  6. ret=1 id=0x0830057f len=8 flags=0x04 eD  ( 8)  f4 cd 6e 1f 68 f4 03 ff
  7.         PGN=130310 - Environmental Parameters
  8.                 SID = 244
  9.                 Water Temperature = 283.65 K
  10.                 Outside Ambient Air Temperature = 266.55 K
  11.                 Atmospheric Pressure = 1012 hPa

  12. ret=1 id=0x0838057f len=8 flags=0x04 eD  ( 8)  f5 40 cd 6e a1 24 f4 03
  13.         PGN=130311 - Environmental Parameters
  14.                 SID = 245
  15.                 Temperature Instance = n/a [16]
  16.                 Temperature = 283.65 K
  17.                 Humidity Instance = Inside [0]
  18.                 Humidity = 37.5080 %
  19.                 Atmospheric Pressure = 1012 hPa

  20. ret=1 id=0x0838057f len=8 flags=0x04 eD  ( 8)  f6 41 1f 68 a1 24 f4 03
  21.         PGN=130311 - Environmental Parameters
  22.                 SID = 246
  23.                 Temperature Instance = n/a [16]
  24.                 Temperature = 266.55 K
  25.                 Humidity Instance = Outside [1]
  26.                 Humidity = 37.5080 %
  27.                 Atmospheric Pressure = 1012 hPa

  28. ret=1 id=0x0830057f len=8 flags=0x04 eD  ( 8)  f6 cd 6e 1f 68 f4 03 ff
  29.         PGN=130310 - Environmental Parameters
  30.                 SID = 246
  31.                 Water Temperature = 283.65 K
  32.                 Outside Ambient Air Temperature = 266.55 K
  33.                 Atmospheric Pressure = 1012 hPa

  34. ret=1 id=0x0840057f len=8 flags=0x04 eD  ( 8)  f6 00 00 cd 6e ff ff ff
  35.         PGN=130312

  36. ret=1 id=0x0840057f len=8 flags=0x04 eD  ( 8)  f7 00 01 1f 68 ff ff ff
  37.         PGN=130312
Copy the Code

Hi,

i tried to use can4linux-examples/receive tool and I successful received messages.

My can device is transmitting at 1Mbit/s. Receiving data at this rate works only for some seconds, after that the whole board hangs up, even if green led blinks and the blue one reacts to LAN packets.

In syslog some messages are printed just before blocking:

Nov 16 18:21:56 lemaker kernel: [  780.072153] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.075733] can4linux: CAN[0] Rx: Overrun Status
Nov 16 18:21:56 lemaker kernel: [  780.126017] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.129593] can4linux: CAN[0] Rx: Overrun Status
Nov 16 18:21:56 lemaker kernel: [  780.183439] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.187016] can4linux: CAN[0] Rx: Overrun Status
Nov 16 18:21:56 lemaker kernel: [  780.240512] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.244087] can4linux: CAN[0] Rx: Overrun Status
Nov 16 18:21:56 lemaker kernel: [  780.294271] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.297846] can4linux: CAN[0] Rx: Overrun Status
Nov 16 18:21:56 lemaker kernel: [  780.345175] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.348750] can4linux: CAN[0] Rx: Overrun Status
Nov 16 18:21:56 lemaker kernel: [  780.402537] can4linux: CAN[0][0] RX: FIFO overrun
Nov 16 18:21:56 lemaker kernel: [  780.406112] can4linux: CAN[0] Rx: Overrun Status

This is the same behavior I have seen on a beaglebone board, so maybe the problem is the can4linux library.

FPeter  
Edited by FPeter at Sun Nov 16, 2014 13:22

NMEA2000 is 250Kbit/sec and current bandwidth utilization is around 1% in my application, so i have no experience in real heavy loads, but i will give it a try on 1Mbit/sec with a PIC ECAN source in the near future...

/proc/sys/dev/Can/IRQ reports that acquired interrupt is 58, but there were no entry in /proc/interrupts with this number when i insmod can4linux.ko until i start the can4linux-examples/receive for the first time, then it appears (without label):
  1. 58:      33135          0       GIC
Copy the Code
Is it appeared in Your interrupt table too? Is the number increasing while Rx is in progress? Did You test it in lower baudrate too if its stable?

I think to be around 20% of bus usage at 1mbit/s and I cannot change the bus speed of the device. I'll try to read interrupts statistics with a looping script because the system crashes almost immediately.

FPeter  
Here is my solution for CAN transceiver: MCP2551 with voltage divider

This small module can be fitted in BPi's cheap acrylic case, and all other pins can be used easily...
BPi-CAN_1.jpg
BPi-CAN_2.jpg
BPi-CAN_3.jpg

Hi, in my implementation i used a TI SN65HVD230D transceiver  rated a 3.3v and maximum speed of 1mbit/s. Have you ever managed to run bus at high speed with mcp2551?

IMG_20141108_180840.jpg

FPeter  
flaviobrums replied at Mon Nov 17, 2014 13:14
Hi, in my implementation i used a TI SN65HVD230D transceiver  rated a 3.3v and maximum speed of 1mbi ...

not yet - first i have to write a test source program for a PIC24 ECAN module, because current source Actisense NMEA0183<>NMEA2000 gateway is locked to 250Kbit/sec

hjoe  
FPeter replied at Sun Nov 16, 2014 13:21
NMEA2000 is 250Kbit/sec and current bandwidth utilization is around 1% in my application, so i have  ...

can4linux request important resources only when needed, not at load time.
The IRQ is requested when an open()  call opens the driver.

hjoe  
flaviobrums replied at Sun Nov 16, 2014 16:26
I think to be around 20% of bus usage at 1mbit/s and I cannot change the bus speed of the device. I' ...

I can do a test with 1Mbit/s tomorrow.
The messages you get in /var/log/messages tells that your application is not fast enough to handle the read() call.
You are getting an rx fifo overflow.

hjoe  
flaviobrums replied at Sun Nov 9, 2014 07:36
Hi,

i'm trying to make canbus working on my BPI. I followed all previous instructions on Lubuntu_Fo ...

you don't need any special tools to set the bitrate for can4linux devices.
Before opening any /dev/can*
do
echo bitrate > /proc/sys/dev/Can/Baud
where bitrate is something like 125, 250, 500 or 1000

You should also have a look at the examples source code. most of the have a bitrate switch.
$ receive -b 250
for example.

can4linux is character driver, no need for the ip tool. This is for network drivers.
Heinz

You have to log in before you can reply Login | Sign Up

Points Rules