This library lets you connect an MRF24J40 tranceiver to your mbed. The MRF24J40 is intended for use as a zigbee or 6LowPan tranciever. However, it can also be used to simply send data from one tranceiver to another. The tranceiver is also available as a module on a small PCB with antenna etc. It requires no other components and can be connected to the mbed using 6 or 7 pins: MISO, MOSI, CLK, CS, WAKE, INT, RESET (optional). New: Added support for INT and WAKE pins. Added PrintBuffer function Added DebugDump function

Fork of MRF24J40 by Jeroen Hilgers

Files at this revision

API Documentation at this revision

Comitter:
nbremond
Date:
Wed Jan 07 22:03:56 2015 +0000
Parent:
2:d1e104b6ce31
Commit message:
Add support for INT and WAKE pins

Changed in this revision

MRF24J40.cpp Show annotated file Show diff for this revision Revisions of this file
MRF24J40.h Show annotated file Show diff for this revision Revisions of this file
diff -r d1e104b6ce31 -r f8a30ff66793 MRF24J40.cpp
--- a/MRF24J40.cpp	Wed Jan 07 15:50:58 2015 +0000
+++ b/MRF24J40.cpp	Wed Jan 07 22:03:56 2015 +0000
@@ -66,12 +66,12 @@
 #define CLKINTCR  0x211
 #define CLCCTRL   0x220
 
-MRF24J40::MRF24J40(PinName mosi, PinName miso, PinName sck, PinName cs, PinName reset) ://, PinName irq, PinName wake) :
+MRF24J40::MRF24J40(PinName mosi, PinName miso, PinName sck, PinName cs, PinName reset, PinName irq, PinName wake) :
     mSpi(mosi, miso, sck), // mosi, miso, sclk
     mCs(cs),
-    mReset(reset)
-//    mIrq(irq),
-//    mWake(wake)
+    mReset(reset),
+    mIrq(irq),
+    mWake(wake)
 {
     mSpi.format(8, 0); // 8 bits, cpol=0; cpha=0
     mSpi.frequency(500000);
@@ -82,34 +82,35 @@
 void MRF24J40::DebugDump(Serial &ser)
 {
    ser.printf("MRF24J40 registers:\r");
-   ser.printf("RXMCR=0x%X\r", MrfReadShort(RXMCR));
-   ser.printf("RXFLUSH=0x%X\r", MrfReadShort(RXFLUSH)); 
-   ser.printf("TXNMTRIG=0x%X\r", MrfReadShort(TXNMTRIG));
-   ser.printf("TXSR=0x%X\r", MrfReadShort(TXSR));
-   ser.printf("ISRSTS=0x%X\r", MrfReadShort(ISRSTS)); 
-   ser.printf("INTMSK=0x%X\r", MrfReadShort(INTMSK));
-   ser.printf("GPIO=0x%X\r", MrfReadShort(GPIO));
-   ser.printf("TRISGPIO=0x%X\r", MrfReadShort(TRISGPIO));
-   ser.printf("RFCTL=0x%X\r", MrfReadShort(RFCTL));
-   ser.printf("BBREG2=0x%X\r", MrfReadShort(BBREG2));
-   ser.printf("BBREG6=0x%X\r", MrfReadShort(BBREG6));
-   ser.printf("RSSITHCCA=0x%X\r", MrfReadShort(RSSITHCCA));
+   ser.printf("RXMCR=0x%X\r", ReadShort(RXMCR));
+   ser.printf("RXFLUSH=0x%X\r", ReadShort(RXFLUSH)); 
+   ser.printf("TXNMTRIG=0x%X\r", ReadShort(TXNMTRIG));
+   ser.printf("TXSR=0x%X\r", ReadShort(TXSR));
+   ser.printf("ISRSTS=0x%X\r", ReadShort(ISRSTS)); 
+   ser.printf("INTMSK=0x%X\r", ReadShort(INTMSK));
+   ser.printf("GPIO=0x%X\r", ReadShort(GPIO));
+   ser.printf("TRISGPIO=0x%X\r", ReadShort(TRISGPIO));
+   ser.printf("RFCTL=0x%X\r", ReadShort(RFCTL));
+   ser.printf("BBREG2=0x%X\r", ReadShort(BBREG2));
+   ser.printf("BBREG6=0x%X\r", ReadShort(BBREG6));
+   ser.printf("RSSITHCCA=0x%X\r", ReadShort(RSSITHCCA));
   
   
-   ser.printf("RFCTRL0=0x%X\r", MrfReadLong(RFCTRL0));
-   ser.printf("RFCTRL2=0x%X\r", MrfReadLong(RFCTRL2));
-   ser.printf("RFCTRL3=0x%X\r", MrfReadLong(RFCTRL3));
-   ser.printf("RFCTRL6=0x%X\r", MrfReadLong(RFCTRL6));
-   ser.printf("RFCTRL7=0x%X\r", MrfReadLong(RFCTRL7));
-   ser.printf("RFCTRL8=0x%X\r", MrfReadLong(RFCTRL8));
-   ser.printf("CLKINTCR=0x%X\r", MrfReadLong(CLKINTCR));
-   ser.printf("CLCCTRL=0x%X\r", MrfReadLong(CLCCTRL));
+   ser.printf("RFCTRL0=0x%X\r", ReadLong(RFCTRL0));
+   ser.printf("RFCTRL2=0x%X\r", ReadLong(RFCTRL2));
+   ser.printf("RFCTRL3=0x%X\r", ReadLong(RFCTRL3));
+   ser.printf("RFCTRL6=0x%X\r", ReadLong(RFCTRL6));
+   ser.printf("RFCTRL7=0x%X\r", ReadLong(RFCTRL7));
+   ser.printf("RFCTRL8=0x%X\r", ReadLong(RFCTRL8));
+   ser.printf("CLKINTCR=0x%X\r", ReadLong(CLKINTCR));
+   ser.printf("CLCCTRL=0x%X\r", ReadLong(CLCCTRL));
    ser.printf("\r");
 }
 
 
 void MRF24J40::Reset(void)
 {
+    mWake = 1;
     mCs = 1;
     // Pulse hardware reset.
     mReset = 0;
@@ -157,6 +158,8 @@
 {
   uint8_t i;
   
+  mWake = 1;
+  
   WriteLong(0x000, 0);   // No addresses in header.
   WriteLong(0x001, length); // 11 bytes
   for(i=0; i<length; i++)
@@ -170,6 +173,8 @@
   uint8_t i, length;
   uint8_t lqi, rssi;
   
+  mWake = 1;
+  
   if(ReadShort(ISRSTS)& 0x08)
   {
     length = ReadLong(0x300);
@@ -241,3 +246,13 @@
   mCs = 1;
   wait_us(1);
 }
+
+
+void MRF24J40::PrintBuffer(Serial &ser, uint8_t *buffer, uint8_t bufferSize)
+{
+    for(uint8_t i=0; i<bufferSize; i++)
+    {
+         ser.printf("0x%02X ", buffer[i]);
+    }
+    ser.printf("\r\n");
+}
\ No newline at end of file
diff -r d1e104b6ce31 -r f8a30ff66793 MRF24J40.h
--- a/MRF24J40.h	Wed Jan 07 15:50:58 2015 +0000
+++ b/MRF24J40.h	Wed Jan 07 22:03:56 2015 +0000
@@ -116,7 +116,7 @@
      * @param pin cs Pin connected to MRF's #CS.
      * @param pin reset Pin connected to MRF's #Reset.
      */
-    MRF24J40(PinName mosi, PinName miso, PinName sck, PinName cs, PinName reset);//, PinName irq, PinName wake);
+    MRF24J40(PinName mosi, PinName miso, PinName sck, PinName cs, PinName reset, PinName irq=NC, PinName wake=NC);
     
     /** Reset the MRF24J40 and initialize it.
      */
@@ -143,14 +143,16 @@
      */
     uint8_t Receive(uint8_t *data, uint8_t maxLength);  // Receive data if ready.
     
-    // void DebugDump(Serial &ser);
-
+    void DebugDump(Serial &ser);
+    
+    void PrintBuffer(Serial &ser, uint8_t *buffer, uint8_t bufferSize);
+    
   private:
     SPI mSpi;
     DigitalOut mCs;
     DigitalOut mReset;
-    // DigitalIn mIrq;
-    // DigitalIn mWake;
+    DigitalIn mIrq;
+    DigitalOut mWake;
 
     uint8_t ReadShort (uint8_t address);
     void WriteShort (uint8_t address, uint8_t data);