Go to Post “There are two ways to compete, one is to drag your opponent down, the other is to raise the bar and excel. Which do you think is more beneficial to you in the long run?” -- John Abele - Candice.E [more]
Home
Go Back   Chief Delphi > Technical > Electrical > CAN
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-01-2016, 11:51
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
CAN + MCP2515, no data

Has anyone ever attempted to hook up one of the many available Arduino CAN shields that utilizes the Microchip MCP2515 CAN controller?

Seeed Studios
has code available that is supposed to work at 1Mbps, but I have not been able to get it to work on the robot's CAN bus. The code is supposed to read data on the bus and transmit it over the UART interface to my computer.

I have checked that the example code does indeed work using my car at 500kbps.

I thought maybe they had the calculations wrong, but they appear to be correct.

The Seeed Studio shield uses a 16MHz crystal oscillator. That would give a TQ of 2/16MHz, or 1/8MHz, Of course, the inverse of Hertz, or cycles / second, is seconds / cycle, giving the time base.

The three registers that select the CAN baud rate are cnf1, cnf2, and cnf3.

The "+ 1" are referenced from the datasheet, such that it will increment the value internally by 1, so if the register is set to 0, the interpreted number will really be 1.

cnf1 = 0x00: SJW = 0; BRP = 0 + 1
cnf2 = 0xD0: BTLMODE = 1; SAM = 1; PHSEG1 = 2 + 1; PRSEG = 0 + 1
cnf3 = 0x82: SOF = 1; WAKFIL = 0; PHSEG2 = 2 + 1

So now that you know what the registers are set to, let's do the math on what that means for bit timings.

For 1 Mbps, I need a bit timing of 1x10^-6 seconds, or 1 / 1 MHz (which is why I kept it in that silly format above, it makes the math easier), or again, for math terms, let's assume 8 / 8 MHz.

Tbit = Tsync_seg + Tprop_seg + Tps1 + Tps2
Tsync_seg = 1 * TQ, or 1 / 8 MHz (1/8)
Tprop_seg = (0 + 1) TQ, or 1 / 8 MHz (1/8)
Tps1 = (2 + 1) TQ, or 3 / 8 MHz (3/8)
Tps2 = (2 + 1) TQ, or 3 / 8 MHz (3/8)

From here, it's simple addition: (1/8) + (1/8) + (3/8) + (3/8) == (8/8).

So, those registers seem fine, and from what I can tell, follow all the rules the datasheet specified. I don't know why it's not working. The red RX light is flashing, so it's seeing data coming in. I know the code works because it works in my car from the OBDII port at 500kbps. Bus impedance was measured at 56 Ohms (a little shy of 60 Ohms, but should still be fine).

One other puzzling thing is my SALAE logic can read the bus just fine at 1 Mbps. The only thing I can note is that the bus uses the extended frame format with the 29-bit identifiers rather than the standard frame with 11-bit.

Any ideas?
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:29.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi