MCP registers can only be set while idle.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 30 Oct 2012 20:27:57 +0000 (20:27 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 30 Oct 2012 20:27:57 +0000 (20:27 +0000)
Code now checks to make sure the pokes worked by reading back the reg's value.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1303 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETMCPCAN.py
client/goodfet.mcpcan

index 165d972..7182d37 100644 (file)
@@ -30,13 +30,15 @@ class GoodFETMCPCAN(GoodFETSPI):
         
         # If we don't enable promiscous mode, we'll miss a lot of
         # packets.  It can be manually disabled later.
-        self.poke8(0x60,0xFF); #TODO Does this have any unpleasant side effects?
+        #self.poke8(0x60,0xFF); #TODO Does this have any unpleasant side effects?
+        self.poke8(0x60,0x66); #Wanted FF, but some bits are reserved.
         
         #Set the default rate.
         self.MCPsetrate();
     
     #Array of supported rates.
-    MCPrates=[100,125,250,500,1000];
+    MCPrates=[83.3, 100, 125,
+              250, 500, 1000];
     
     def MCPsetrate(self,rate=125):
         """Sets the data rate in kHz."""
@@ -75,8 +77,9 @@ class GoodFETMCPCAN(GoodFETSPI):
         #           );
         
         
-        #These are the new examples.
+        print "Setting rate of %i kHz." % rate;
         
+        #These are the new examples.
         if rate==125:
             #125 kHz, 16 TQ, not quite as worked out above.
             CNF1=0x04;
@@ -87,6 +90,12 @@ class GoodFETMCPCAN(GoodFETSPI):
             CNF1=0x04;
             CNF2=0xBA;
             CNF3=0x07;
+        elif rate>83 and rate<83.5:
+            #83+1/3 kHz, 8 TQ
+            # 0.04% error from 83.30
+            CNF1=0x0E;
+            CNF2=0x90;
+            CNF3=0x02;
         elif rate==250:
             #256 kHz, 20 TQ
             CNF1=0x01;
@@ -216,4 +225,8 @@ class GoodFETMCPCAN(GoodFETSPI):
     def poke8(self,adr,val):
         """Poke a value into RAM.  Untested"""
         self.SPItrans([0x02,adr&0xFF,val&0xFF]);
+        newval=self.peek8(adr);
+        if newval!=val:
+            print "Failed to poke %02x to %02x.  Got %02x." % (adr,val,newval);
+            print "Are you not in idle mode?";
         return val;
index b52bb71..83aff43 100755 (executable)
@@ -46,10 +46,10 @@ if(sys.argv[1]=="info"):
     for foo in [packet0, packet1]:
         print client.packet2str(foo);
 if(sys.argv[1]=="sniff"):
-    client.MCPreqstatListenOnly();
     if len(sys.argv)>2:
         rate=int(sys.argv[2]);
         client.MCPsetrate(rate);
+    client.MCPreqstatListenOnly();
     while 1:
         packet=client.rxpacket();
         if packet!=None: