Connecting MCP2515 via SPI for CAN driver with Android kernel 4.9

This is awesome! Thanks!

2 Likes

Hi,
I followed the steps as described. Unfortunately it is not working. When I run the command "adb shell ip link set can0 type can bitrate 500000 " it says no device can0 available.
Any idea about the reason ? Thanks in advance for your support.
Hatem

Hi! What have you tried? Are you seeing any messages in the kernel logs? Did you power on the remote system before the Hikey? I did sometimes see issues if the Hikey wasn’t powered on after the rest of the devices on the CAN bus. Or it might have been the other way around. I haven’t worked on this in some months now. I believe we saw this most often when we had some kind of hardware connection issue on the SPI bus. Make sure the SPI interrupt pin is securely connected. Those tiny European headers can be hard to get a good connection with sometimes.

1 Like

Hi Christopher, first of all thx for your prompt reply. :slight_smile:

Actually i still did not connect any device from the other side. right now i have only the hikey board and the CAN module. (please see pictures).

i am sharing also part of the kernel log. it says may be wiring is wrong ???

my wiring:
CAN ← → Hikey

INT ← → PIN 32 (GPIO_019)
SCK ← → PIN 8 (SPI2_CLK)
SI ← → PIN 10 (SPI2_DI)
SO ← → PIN 14 (SPI2_DO)
CS ← → PIN 12 (SPI2_CS_N)
GND ← → PIN 39 (GND)
VCC ← → PIN 37 (SYS_5V)

e[32m[ 6.880569] e[33mspi spi32766.0e[0m: 4 <= n <=8 bits per word
e[32m[ 6.880572] e[33mspi spi32766.0e[0m: DMA mode NOT set in controller state
e[32m[ 6.880578] e[33mspi spi32766.0e[0m: setup mode 0, 8 bits/w, 500000 Hz max → 0
e[32m[ 6.880762] e[33mssp-pl022 ffd68000.spie[0m: SSP Target Frequency is: 500000, Effective Frequency is 500000
e[32m[ 6.880765] e[33mssp-pl022 ffd68000.spie[0m: SSP cpsdvsr = 2, scr = 199
e[32m[ 6.880767] e[33mmcp251x spi32766.0e[0m: 4 <= n <=8 bits per word
e[32m[ 6.880769] e[33mmcp251x spi32766.0e[0m: DMA mode NOT set in controller state
e[32m[ 6.880772] e[33mmcp251x spi32766.0e[0m: setup mode 0, 8 bits/w, 500000 Hz max → 0
e[32m[ 6.885810] e[33mssp-pl022 ffd68000.spie[0m: flush
e[32m[ 6.885815] e[33mssp-pl022 ffd68000.spie[0m: flush
e[32m[ 6.885819] e[33mssp-pl022 ffd68000.spie[0m: polling transfer ongoing …
e[32m[ 6.885823] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc218304499, tx: ffffffc218304518, txend: ffffffc218304519
e[32m[ 6.885838] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc218304499, tx: ffffffc218304519, txend: ffffffc218304519
e[32m[ 6.885841] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc218304499, tx: ffffffc218304519, txend: ffffffc218304519
e[32m[ 6.890870] e[33mssp-pl022 ffd68000.spie[0m: flush
e[32m[ 6.890873] e[33mssp-pl022 ffd68000.spie[0m: flush
e[32m[ 6.890876] e[33mssp-pl022 ffd68000.spie[0m: polling transfer ongoing …
e[32m[ 6.890879] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc21830449b, tx: ffffffc218304518, txend: ffffffc21830451b
e[32m[ 6.890885] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890889] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890892] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890894] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890897] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304498, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890901] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304499, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890904] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304499, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890907] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304499, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890910] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304499, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890913] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304499, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890916] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc218304499, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890919] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890922] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890926] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890928] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890931] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890933] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890936] e[33mssp-pl022 ffd68000.spie[0m: readwriter, rx: ffffffc21830449a, rxend: ffffffc21830449b, tx: ffffffc21830451b, txend: ffffffc21830451b
e[32m[ 6.890954] e[33mmcp251x spi32766.0e[31m: Cannot initialize MCP2515. Wrong wiring?
e[32m[ 6.890962] e[33mmcp251x spi32766.0e[31m: Probe failed, err=19
e[32m[ 6.890974] e[33mssp-pl022 ffd68000.spie[0m: registered child spi32766.0
e[32m[ 6.890977] e[33mssp-pl022 ffd68000.spie[0m: probe succeeded
e[32m[ 6.891029] e[33mssp-pl022 ff3b3000.spie[0m: ARM PL022 driver, device ID: 0x00041022
e[32m[ 6.891049] e[33mssp-pl022 ff3b3000.spie[0m: BUSNO: -1
e[32m[ 6.891056] e[33mssp-pl022 ff3b3000.spie[0m: mapped registers from 0x00000000ff3b3000 to ffffff800bb03000
e[32m[ 6.891085] e[33mssp-pl022 ff3b3000.spie[0m: setup for DMA on RX dma0chan2, TX dma0chan3
e[32m[ 6.891172] e[33mssp-pl022 ff3b3000.spie[0m: registered master spi32765 (dynamic)
e[32m[ 6.891616] e[33mssp-pl022 ff3b3000.spie[0m: probe succeeded
e[32m[ 6.892222] e[0mrt1711_i2c_probe
e[32m[ 6.892224] e[33mI2C functionality e[0m: OK…

Thank for you support
Hatem

It looks like there is some traffic on the SPI bus, but it’s unable to initialize properly. What’s the clock speed of the crystal on your CAN module? That looks like a genuine Electrodragon. It should be 16hz, if I recall correctly, but check for markings on the crystal (the silver oblong) and the datasheet. My module was a knock off with an 8hz clock. Double check that you’ve set the clock speed correctly in the device tree.

1 Like

Hi, clock is 8Mhz

is my wiring correct ?

my wiring:

CAN ← → Hikey

INT ← → PIN 32 (GPIO_019)
SCK ← → PIN 8 (SPI2_CLK)
SI ← → PIN 10 (SPI2_DI)
SO ← → PIN 14 (SPI2_DO)
CS ← → PIN 12 (SPI2_CS_N)
GND ← → PIN 39 (GND)
VCC ← → PIN 37 (SYS_5V)

thnx
Hatem

HOLD ON JUST A MINUTE THERE!!!
Are you TRYING to murder your hikey960?
You are interfacing a 5v device with a 1.8v device without a LEVEL SHIFTER.

Even if its protected from setting the world on fire, the high and low logic levels are NOT going to align, which means they will NOT communicate successfully.

2 Likes

OK :grimacing:
What shall I add/do exactly ?

Well, how about doing the obvious? Add a level shifter. And cross your fingers that you didn’t cook your SoC.

You have to make sure that the level shifter you use is capable of SPI.

It looks like the “sensors mezzanine” board has SPI routed through a level shifter (TXB0108), but I’m not sure how well that will work, I’ve read that TXB is not a great level shifter for SPI, rather it would be better to use TXS0108 for that. Its possible that the TXB may work adequately at low speeds, but I can’t confirm.

EDIT: I would be tempted to try the sensors mezzanine, especially if you happen to already own one, and if not, they’re a great tool for this type of hacking. If SPI doesn’t work through the TXB and you (or someone you know) is halfway decent at surface mount soldering, you can swap the TXB for a TXS. They are pin compatible, so its a real easy swap.

2 Likes

@doitright thanks a lot :slight_smile: . I understand better now the choice of your name (do it right) .
Hi @rubberduck203, in your case how did you manage to do the level shifting. thx

Hatem

Oh geez! Great catch.

I bought some modules from Sparkfun and fabbed a proto-board.
It takes two of these to cover all the pins.

1 Like

@rubberduck203 thx a lot :slight_smile:

1 Like

You’re welcome! One tip I do have there is to get yourself some of the smaller 0.2mm jumpers and strip one end off to solder to your level shifter proto. I did manage to make 0.2mm headers work, but it takes an extremely steady hand to solder those tiny buggers. I think you’d have better luck with using jumpers. Bad hardware connections plagued my project for months.

I think you mean 2mm.

Also, you have moose hands if you have a hard time with those. Try 0.5mm SM, those are small.

I did and, alas, I do have moose hands.

Hi @rubberduck203,
Hi @doitright,

I added a level shifter (TXS0108e) but it is always not working .
in the kernel logs it says always

Cannot initialize MCP2515. Wrong wiring?
Probe failed, err=19

would you mind checking my connection (see below picture). may be i missing again something !

Thx
Hatem

I think you have master out connected to slave out and master in → slave in.

1 Like

I think that @rubberduck203 is right. Flip them.

SPI_DO → SI
SPI_DI ← SO

And do keep in mind the potential for your having damaged the SoC when feeding it 5V. If it still doesn’t work, then you may need a logic probe to track down where the problem is.

Edit: And make sure that you are aware of how the “OE” pin on the level shifter works. Depending on how that board is wired up, you may need to drive that pin high (1.8v). See the “simplified application” diagram on the first page of the txs0108 datasheet: http://www.ti.com/lit/ds/symlink/txs0108e.pdf

The diagram shows 3 passives: 2 capacitors, and a pull-down resistor. That is consistent with the passives I see on your picture. If that resistor is a pull down, then you will need to drive it high to turn the chip on.

1 Like

@doitright @rubberduck203 thanks a lot for your prompt answers.
@doitright how can I check if the soc is damaged.
And in case it is damaged is it only the gpio which were connected to 5v or it may be more then that.

Regards
Hatem