ADF7023-mbed

Dependencies:   mbed

Revision:
0:3d0c404a914f
Child:
1:7d363b744c5f
diff -r 000000000000 -r 3d0c404a914f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 29 06:40:34 2015 +0000
@@ -0,0 +1,421 @@
+#include "mbed.h"
+#define ENDL "\r" << endl
+#include<iostream>
+DigitalOut led(LED_RED);
+DigitalOut CS(D10);
+
+
+SPI adf(PTD6, PTD7, PTD5); // mosi, miso, sclk
+
+
+void bbram_write()
+{   
+    CS=0;
+    // To bring in off state
+    adf.write(0xB0);
+    wait(0.1);
+    CS=1;
+    
+    // Write bbram
+    CS=0;
+    adf.write(0x19);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    
+    adf.write(0x00);    
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    
+    adf.write(0x00);
+    adf.write(0x33);
+    adf.write(0x00);
+    adf.write(0xF4);
+    
+    adf.write(0xC2);
+    adf.write(0x10);
+    adf.write(0xC0);    
+    adf.write(0x00);
+    
+    adf.write(0x30);
+    adf.write(0x31);
+    adf.write(0x07);    
+    adf.write(0x00);
+        
+    adf.write(0x01);
+    adf.write(0x00);
+    adf.write(0x7F);
+    adf.write(0x00);
+    
+    adf.write(0x0B);
+    adf.write(0x37);
+    adf.write(0x00);    
+    adf.write(0x00);
+    adf.write(0x40);
+    adf.write(0x0C);
+    adf.write(0x00);
+    adf.write(0x05);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x18);
+    adf.write(0x12);
+    adf.write(0x34);
+    adf.write(0x56);
+    adf.write(0x10);
+    adf.write(0x10);
+    adf.write(0xC4); // Different
+    adf.write(0x14);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x04);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    adf.write(0x00);
+    CS=1;
+    wait(0.1);
+    
+    // Testmode register
+    CS=0;
+    adf.write(0x09);
+    adf.write(0x39);
+    adf.write(0x10);
+    CS=1;
+    wait(0.1);
+    
+    //CMD_CONFIG_DEV
+    CS=0;
+    adf.write(0xBB);
+    CS=1;
+    wait(0.1);
+    CS=0;
+    adf.write(0xFF);
+    adf.write(0xFF);
+    CS=1;
+    wait(0.1);    
+}
+
+void data_write()
+{
+     // PHY_ON
+    CS=0;
+    adf.write(0xB1);
+    CS=1;
+    wait(0.1);
+    CS=0;
+    adf.write(0xFF);
+    adf.write(0xFF);
+    CS=1;
+    wait(0.1);
+    // TRANSMIT_DATA LENGTH
+    CS=0;
+    adf.write(0x08);
+    adf.write(0x14);
+    adf.write(0xFF);
+    CS=1;
+    wait(0.1);
+    CS=0;
+    adf.write(0x08);
+    adf.write(0x15);
+    adf.write(0xFF);
+    CS=1;
+    wait(0.1);
+    // TX_BASE ADDRESS
+    CS=0;
+    adf.write(0x09);
+    adf.write(0x24);
+    adf.write(0x20);
+    CS=1;
+    wait(0.1);
+    // BUFFER SIZE
+    CS=0;
+    adf.write(0x09);
+    adf.write(0x37);
+    adf.write(0xE0);
+    CS=1;
+    wait(0.1);
+    CS=0;
+    adf.write(0x09);
+    adf.write(0x36);
+    adf.write(0x70);
+    CS=1;
+    wait(0.1);
+    // PACKET WRITE
+    CS=0;
+    adf.write(0x18);
+    adf.write(0x20);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);
+    adf.write(0xFF);  
+    CS=1;
+    wait(0.1);
+    // TX MODE
+    CS=0;
+    adf.write(0xB5);
+    CS=1;
+    wait(0.1);    
+    while(1)
+    {
+        CS=0;
+         adf.write(0x2B);
+         adf.write(0x36);
+    int irq1 = adf.write(0xFF);
+    int irq2 = adf.write(0xFF);
+         CS=1;    
+         wait_us(500);
+         cout<<"IRQ1="<<irq1<<"irq2="<<irq2<<ENDL; 
+    }
+    
+}
+
+int main()
+{
+    adf.format(8,0);
+    adf.frequency(1000000);
+    bbram_write();
+    data_write();
+    
+}
\ No newline at end of file