I think I've got the CAN mode running at 125kHz. Not yet sure.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 16 Aug 2012 22:11:51 +0000 (22:11 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 16 Aug 2012 22:11:51 +0000 (22:11 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1235 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETMCPCAN.py
client/goodfet.mcpcan

index d4dc159..1b8a5fd 100644 (file)
@@ -24,8 +24,43 @@ class GoodFETMCPCAN(GoodFETSPI):
         self.SPIsetup();
         self.MCPreset(); #Reset the chip.
         
-        #Loopback mode for testing.
+        # We're going to set some registers, so we must be in config
+        # mode.
         self.MCPreqstatConfiguration();
+        
+        # Now we need to set the timing registers.  See chapter 5 of
+        # the MCP2515 datasheet to get some clue as to how this
+        # arithmetic of this works, as my comments here will likely be
+        # rambling, incoherent, and unchanged after I get the infernal
+        # thing working.
+        
+        # First, we must chose a Time Quanta (QT) which is used to
+        # define the durations of these segments.  Section 5.3
+        # suggests setting BRP<5:0> to 0x04 to get a TQ=500ns, as a 20
+        # MHz crystal gives a clock period of 50ns.  This way, for 125
+        # kHz communication, the bit time must be 16 TQ.
+        
+        # A bit consists of four parts:
+        # 1: SyncSeg             1 TQ
+        # 2: PropSeg             2 TQ
+        # 3: PhaseSeg1 (PS1)     7 TQ
+        # 4: PhaseSeg2 (PS2)     6 TQ
+        
+        # CNF1 with a prescaler of 4 and a SJW of 1 TQ.  SJW of 4
+        # might be more stable.
+        self.poke8(0x2a,0x04);
+        
+        # CNF2 with a BLTMODE of 1, SAM of 0, PS1 of 7TQ, and PRSEG of 2TQ
+        self.poke8(0x29,
+                   0x80   |  # BTLMODE=1
+                   (6<<3) |  # 6+1=7TQ for PHSEG1
+                   (1)       # 1+1=2TQ for PRSEG
+                   );
+        
+        #CNF3 with a PS2 length of 6TQ.
+        self.poke8(0x28,
+                   5      #5+1=6TQ
+                   );
     def MCPreset(self):
         """Reset the MCP2515 chip."""
         self.SPItrans([0xC0]);
index 9de2cc7..44b921e 100755 (executable)
@@ -46,10 +46,12 @@ if(sys.argv[1]=="info"):
     for foo in [packet0, packet1]:
         print client.packet2str(foo);
 if(sys.argv[1]=="sniff"):
+    client.MCPreqstatListenOnly();
     while 1:
         packet=client.rxpacket();
         if packet!=None:
             print client.packet2str(packet);
+
 if(sys.argv[1]=="test"):
     print "MCP2515 Self Test:";