Pessimism and optimism are both contagious. - Taylor [more]
 Chief Delphi > CAN CAN + MCP2515, no data
 CD-Media CD-Spy
 portal register members calendar search Today's Posts Mark Forums Read FAQ rules

#1
01-17-2016, 10:51 AM
 RyanN RyanN AKA: Ryan Nazaretian FRC #2468 (Team Appreciate) Team Role: Mentor Join Date: Jun 2006 Rookie Year: 2005 Location: Austin, TX Posts: 1,151
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?
__________________
Controls Mentor
@rnazaretian

Current team:
Team Appreciate, FRC 2468

Previous teams:
Team Fusion, FRC 364 (2003 - 2015)
#2
09-09-2017, 02:42 PM
 Wasabi Fan Registered User AKA: Kaelin Laundry FRC #0488 Join Date: Dec 2015 Rookie Year: 2015 Location: Washington Posts: 23
Re: CAN + MCP2515, no data

Did you ever find a solution here? I'm looking at this same chip and it'd be super helpful to know that someone else got it working.

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         C/C++         Java         Python     Control System         FRC Control System         Sensors     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Unsung FIRST Heroes     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     District Events     Off-Season Events     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Southern California Regional Robotics Forum         The Blue Alliance             Video Archives     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge     VEX         VEX Robotics Competition         VEX IQ     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support     Extra Discussion

All times are GMT -5. The time now is 03:57 AM.

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

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Archive - Top