Codebase from CC1101_Transceiver, ported to LPC1114/LPC824/STM32F103 and other micros, will be merged with panStamp project to replace AVR/MSP.

Dependencies:   mbed

Fork of CC1101_Transceiver_LPC1114 by Kai Liu

Files at this revision

API Documentation at this revision

Comitter:
allankliu
Date:
Thu Aug 24 10:37:31 2017 +0000
Parent:
1:b8285d79c9a1
Commit message:
Init version, integrated CC1101_Transceiver with STM32F103RB/LPC824, publish to public for further debugging. Current SPI access 0x30 to 0x3D registers are not stable.

Changed in this revision

CC1101.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/CC1101.h	Tue Dec 16 09:00:27 2014 +0000
+++ b/CC1101.h	Thu Aug 24 10:37:31 2017 +0000
@@ -353,4 +353,4 @@
     unsigned char lqi;
 };
 ///////////////////////////////////////////////////////////////////////////////////////
-#endif
\ No newline at end of file
+#endif
--- a/main.cpp	Tue Dec 16 09:00:27 2014 +0000
+++ b/main.cpp	Thu Aug 24 10:37:31 2017 +0000
@@ -1,53 +1,103 @@
+/*
+    Author: Allan K Liu
+    Original: Athanassios Mavrogeorgiadis
+    
+    Changes:
+    - Optimization for Low Power Consumption Operations
+    - GD0 as external interrupt, to bring MCU from deep sleep mode.
+    - GPIO setup
+    - Clock setup
+    - Event driven design
+    - ALOHA transceiver for channel access with RTS/CTS/ACK
+    - S-MAC
+    - Cloned high level designs from SimpliciTI.
+    - New CircularBuffer from mbed 5
+    
+    Status:
+    - CC1101 SPI access to regsiters from PARTNUM/VERSION to RCCTRL0 not stable
+    - PARTNUM ranges from 0x00/0xFF
+    - VERSION ranges from 0x0F/0x1F/0x4F
+ */
 #include "mbed.h"
 #include "CC1101.h"
 #include "RingBuffer.h"
  
-///////////////////////////////////////////////////
-Ticker timer;
+
+#if defined(TARGET_NUCLEO_F103RB) || defined(TARGET_LPC824)
+// RDmiso is actually the MISO, 
+// SPI only works after MISO turns into low from Hi-Z state of CC1101
+// Therefore we need a dedicated input to detect.
+CC1101 cc1101(D11, D12, D13, D10, D8);    // MOSI, MISO, SCK, nCS, RDmiso
+DigitalIn gdo0(D7);     // InterruptIn is better than DigitalIn
+InterruptIn gdo2(D9);   // InterruptIn is better than DigitalIn
+
+DigitalOut led1(A0);  // timer blink led
+DigitalOut led2(A1);  // RX led
+DigitalOut led3(A2);  // TX led
+
+#elif defined(TARGET_LPC1114)
+// Legacy platform, to be updated
 CC1101 cc1101(p5, p6, p7, p8, p10);
 DigitalIn gdo0(p9);     // pin connected to gdo0 pin of CC1101 for checking that received a new packet
 
 DigitalOut led1(LED1);  // timer blink led
 DigitalOut led2(LED2);  // RX led
 DigitalOut led3(LED3);  // TX led
-Serial pc(USBTX, USBRX); // tx, rx
-RingBuffer pcRX(512);   // ring buffer for the pc RX data
-RingBuffer pcTX(512);   // ring buffer for the pc TX data
-Timeout pcRXtimeout;
+
+#else
+
+#warning "YOU HAVE TO DEFINE A H/W."
+#endif
+
+
+Ticker timer;
+
+
+Serial pc(USBTX, USBRX); // tx, rx, to be replaced by USB CDC interface in a hub/sink node.
+RingBuffer rbRX(512);   // ring buffer for the pc RX data
+RingBuffer rbTX(512);   // ring buffer for the pc TX data
+
+Timeout rbRXtimeout;
 Timeout led2timeout;
 Timeout led3timeout;
+
 unsigned char buffer[128];
-///////////////////////////////////////////////////
+
+static unsigned char sil = 0;
+static unsigned char ver = 0;
+static unsigned char sta = 0;
+static unsigned char val = 0;
+
 void led2timeout_func()
 {
     led2 = 0;
     led2timeout.detach();
 }
-///////////////////////////////////////////////////
+
 void led3timeout_func()
 {
     led3 = 0;
     led3timeout.detach();
 }
-///////////////////////////////////////////////////
-void pcRXtimeout_func()         // function for transmiting the RF packets - empty the pcRX ring buffer
+
+void rbRXtimeout_func()         // function for transmiting the RF packets - empty the rbRX ring buffer
 {
     unsigned char txlength;
     
     txlength = 0;
-    while(pcRX.use() > 0)
+    while(rbRX.use() > 0)
     {
       led2 = 1;
-      buffer[txlength] = pcRX.getc();
+      buffer[txlength] = rbRX.getc();
       txlength++;
       led2timeout.attach(&led2timeout_func, 0.050);  // for switch off the led
     }
     if (txlength)
       cc1101.SendPacket(buffer, txlength);    // tx packet
     
-    pcRXtimeout.detach();
+    rbRXtimeout.detach();
 }
-///////////////////////////////////////////////////
+
 void timer_func()           // check the status of the CC1101 every 100ms
 {    
     unsigned char chip_status_rx, chip_status_tx;
@@ -62,14 +112,93 @@
     if ((chip_status_tx & CHIP_STATE_MASK) == CHIP_STATE_TXFIFO_UNDERFLOW)  // if tx underflow flush the tx fifo
       cc1101.FlushTX();
 }
-///////////////////////////////////////////////////
+
 int main() 
 {
     unsigned char rxlength, i;
+        unsigned char buf[128];
     
-    pcRX.clear();
-    pcTX.clear();
+    rbRX.clear();
+    rbTX.clear();
     cc1101.init();
+
+        // test routines
+
+#define REG_PART_DBG 1  
+#if defined(REG_PART_DBG)
+    
+        for (int i=0; i<10; i++){
+            buf[i] = cc1101.ReadChipStatusRX();
+        }
+        cc1101.ReadBurstReg(CCxxx0_PARTNUM, buf, CCxxx0_PATABLE-CCxxx0_PARTNUM+1);
+
+    // Read them one by one
+        for (int i=CCxxx0_PARTNUM; i<CCxxx0_PATABLE; i++){
+            buf[i] = cc1101.ReadReg(i);
+        }
+    
+        // Try to read back all of values from registers ranges from 0x30~0x3D
+        // Read them one by one
+        sil = cc1101.ReadReg(CCxxx0_PARTNUM);
+      ver = cc1101.ReadReg(CCxxx0_VERSION);
+        sta = cc1101.ReadChipStatusRX();
+    
+        for (int i=0; i<10; i++){
+            buf[i] = cc1101.ReadReg(CCxxx0_PARTNUM);
+        }
+
+        for (int i=0; i<10; i++){
+            buf[i] = cc1101.ReadReg(CCxxx0_VERSION);
+        }
+
+        for (int i=0; i<10; i++){
+            buf[i] = cc1101.ReadChipStatusRX();
+        }
+
+        // Read them in a burst reading
+        cc1101.ReadBurstReg(CCxxx0_PARTNUM, buf, CCxxx0_PATABLE-CCxxx0_PARTNUM+1);
+        // Read them in a burst reading twice
+        cc1101.ReadBurstReg(CCxxx0_PARTNUM, buf, CCxxx0_PATABLE-CCxxx0_PARTNUM+1);
+        // Read them one by one
+        for (int i=CCxxx0_PARTNUM; i<CCxxx0_PATABLE; i++){
+            buf[i] = cc1101.ReadReg(i);
+        }
+        // Read them in a burst reading
+        cc1101.ReadBurstReg(CCxxx0_PARTNUM, buf, CCxxx0_PATABLE-CCxxx0_PARTNUM+1);
+        
+#endif
+
+//#define REG_RW_DBG 1
+#if defined(REG_RW_DBG)
+        // Try to read back all of values from registers ranges from 0x00~0x2E
+        cc1101.ReadBurstReg(CCxxx0_IOCFG2, buf, CCxxx0_TEST0+1);
+        
+        for (int i=CCxxx0_IOCFG2; i<(CCxxx0_TEST0+1); i++){
+            buf[i] = cc1101.ReadReg(i);
+        }
+        
+        const unsigned char params[0x2F] = \
+            {0x06,0x2E,0x07,0x07,0xD3,0x91,0xFF,0x04, \
+             0x05,0x00,0x00,0x06,0x00,0x10,0xB1,0x3B, \
+             0xF8,0x83,0x13,0x22,0xF8,0x15,0x07,0x3F, \
+             0x18,0x16,0x6C,0x03,0x40,0x91,0x87,0x6B, \
+             0xF8,0x56,0x10,0xE9,0x2A,0x00,0x1F,0x41, \
+             0x00,0x59,0x7F,0x63,0x88,0x31,0x09};
+            
+        for (int i=CCxxx0_IOCFG2; i<(CCxxx0_TEST0+1); i++){
+            cc1101.WriteReg(i, params[i]);
+        }
+
+        for (int i=CCxxx0_IOCFG2; i<(CCxxx0_TEST0+1); i++){
+            buf[i] = cc1101.ReadReg(i);
+        }
+
+    cc1101.ReadBurstReg(CCxxx0_IOCFG2, buf, CCxxx0_TEST0+1);
+
+#endif      
+        
+        // end of test
+    
     timer.attach(&timer_func, 0.1);
     while(1)
     {
@@ -80,19 +209,18 @@
             {
                 led3 = 1;
                 for (i = 0; i < rxlength; i++)
-                    pcTX.putc(buffer[i]);                       // store the packet to the pcTX ring buffer 
+                    rbTX.putc(buffer[i]);                       // store the packet to the rbTX ring buffer 
                 led3timeout.attach(&led3timeout_func, 0.050);   // for switch off the led
             }
         }
-        if (pcTX.use() > 0)         // check if we have data to transmit to pc
-            pc.putc(pcTX.getc());   // get the data from the ring buffer and transmit it to the pc
+        if (rbTX.use() > 0)         // check if we have data to transmit to pc
+            pc.putc(rbTX.getc());   // get the data from the ring buffer and transmit it to the pc
         if (pc.readable())          // check if we received new data from the pc
         {
-            pcRX.putc(pc.getc());   // put the data to the pcRX buffer and wait until 20ms passed till the last byte before tx the packet in RF
-            pcRXtimeout.attach(&pcRXtimeout_func, 0.020);
+            rbRX.putc(pc.getc());   // put the data to the rbRX buffer and wait until 20ms passed till the last byte before tx the packet in RF
+            rbRXtimeout.attach(&rbRXtimeout_func, 0.020);
         }
-        if (pcRX.use() > 20)        // if more than 20 bytes received then tx the packet in RF
-            pcRXtimeout_func();
+        if (rbRX.use() > 20)        // if more than 20 bytes received then tx the packet in RF
+            rbRXtimeout_func();
     }     
 }
-///////////////////////////////////////////////////