Dheeraj M Pai
/
October_22_1_28AM
Partially made code for adf7023
main.cpp@0:e80c23aacae6, 2015-10-21 (annotated)
- Committer:
- dheerajmpai23
- Date:
- Wed Oct 21 20:10:52 2015 +0000
- Revision:
- 0:e80c23aacae6
- Child:
- 1:434b2062426b
To make the transmission foolproof. With options of hardware resets.; To DO:; Ensuring PHY_ON and PHY_TX STATE transitions SPI and Command Ready bit checking
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dheerajmpai23 | 0:e80c23aacae6 | 1 | ///ADF7023 From BIT BUCKET |
dheerajmpai23 | 0:e80c23aacae6 | 2 | |
dheerajmpai23 | 0:e80c23aacae6 | 3 | #include "mbed.h" |
dheerajmpai23 | 0:e80c23aacae6 | 4 | #include <iostream> |
dheerajmpai23 | 0:e80c23aacae6 | 5 | #include <stdio.h> |
dheerajmpai23 | 0:e80c23aacae6 | 6 | using namespace std; |
dheerajmpai23 | 0:e80c23aacae6 | 7 | #include <bitset> |
dheerajmpai23 | 0:e80c23aacae6 | 8 | #define ENDL "\r" << endl; |
dheerajmpai23 | 0:e80c23aacae6 | 9 | |
dheerajmpai23 | 0:e80c23aacae6 | 10 | #define MISO_PIN PTA17 |
dheerajmpai23 | 0:e80c23aacae6 | 11 | #define THRS 20 |
dheerajmpai23 | 0:e80c23aacae6 | 12 | #define STATE_ERR_THRS 20 |
dheerajmpai23 | 0:e80c23aacae6 | 13 | #define PHY_OFF_EXEC_TIME 300 |
dheerajmpai23 | 0:e80c23aacae6 | 14 | /******DEFINING OMMANDS*********/ |
dheerajmpai23 | 0:e80c23aacae6 | 15 | |
dheerajmpai23 | 0:e80c23aacae6 | 16 | #define CMD_HW_RESET 0xC8 |
dheerajmpai23 | 0:e80c23aacae6 | 17 | SPI adf(PTA16, MISO_PIN, PTA15); |
dheerajmpai23 | 0:e80c23aacae6 | 18 | //MOSI, MISO, CLOCK |
dheerajmpai23 | 0:e80c23aacae6 | 19 | DigitalOut CS(D10); |
dheerajmpai23 | 0:e80c23aacae6 | 20 | //DigitalOut CS(PTD4);//D10==PTD4 |
dheerajmpai23 | 0:e80c23aacae6 | 21 | Serial PC(USBTX, USBRX); |
dheerajmpai23 | 0:e80c23aacae6 | 22 | DigitalOut ledr(LED1); |
dheerajmpai23 | 0:e80c23aacae6 | 23 | DigitalOut led2(LED2); |
dheerajmpai23 | 0:e80c23aacae6 | 24 | InterruptIn IRQ(D8); |
dheerajmpai23 | 0:e80c23aacae6 | 25 | //InterruptIn IRQ(PTA13);//D8==PTA13 |
dheerajmpai23 | 0:e80c23aacae6 | 26 | Ticker ticker; |
dheerajmpai23 | 0:e80c23aacae6 | 27 | //Timer t; |
dheerajmpai23 | 0:e80c23aacae6 | 28 | //Timer stop; |
dheerajmpai23 | 0:e80c23aacae6 | 29 | int x=IRQ; |
dheerajmpai23 | 0:e80c23aacae6 | 30 | int src=0; |
dheerajmpai23 | 0:e80c23aacae6 | 31 | int irqsrc = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 32 | int j = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 33 | int k = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 34 | int irq1=0; |
dheerajmpai23 | 0:e80c23aacae6 | 35 | int r = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 36 | unsigned char data[]={0x65,0xD3,0x06,0x08,0xBB,0xE7,0xCD,0x16,0x65,0xD3,0x06,0x08,0xBB,0xE7,0xCD,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x10,0x83,0x11,0x24,0x67,0xCE,0x05,0x50,0x01,0x45,0x9D,0x46,0x0D,0x6B,0xC1,0xF2,0xF3,0xE8,0xFE,0x52,0x0A,0x27,0x90,0x0A,0x3F,0x15,0xD1,0x68,0xD0,0x48,0x75,0x06,0x04,0xB7,0xE6,0xA0,0x82,0xF2,0x50,0x20,0x75,0x09,0x65,0x68,0x1A,0x9A,0xDD,0x1C,0x3F,0xC6,0xF5,0xD8,0xBD,0x96,0xB1,0xA0,0x92,0x29,0x44,0x78,0x60,0x0C,0x5D,0xCE,0xED,0x7A,0x85,0xF0,0x70,0x1C,0x7F,0x52,0x7B,0x14,0x43,0x4C,0x76,0xDD,0x41,0x86,0x59,0x6D,0x18,0x7C,0x63,0xF3,0x9F,0x74,0xB8,0x00,0x77,0xC0,0x18,0xDD,0xCE,0xA2,0xD1,0x2A,0xF3,0xFE,0x22,0xB5,0x0E,0x42,0xAF,0xB7,0x89,0x38,0x15,0xB0,0xCD,0xD6,0x27,0xEB,0x3F,0x5C,0x05,0xF7,0x26,0x5A,0x6A,0x4B,0x08,0x9E,0xAA,0x74,0xFF,0x30,0x0A,0x0A,0xBD,0x72,0xA2,0x44,0x20,0xC6,0x92,0x59,0xF3,0x80,0x55,0x00,0x51,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0xD4,0x63,0x5A,0xF0,0x1F,0x1C,0xFA,0x3C,0xE5,0x22,0x89,0xE4,0x00,0xAF,0xC5,0x74,0x16,0xB4,0x12,0x1C,0x50,0x61,0x2D,0xF8,0x6A,0x20,0xBC,0x96,0x82,0x1D,0x42,0x5A,0xD6,0x86,0xA6,0xB4,0xD1,0xCF,0xF1,0xBC,0x5D,0xAF,0x65,0xAE,0x9A,0x24,0x8A,0x52,0xC7,0x98,0x03,0x14,0xDC,0xDB,0x5E,0xA0,0x5F,0x1C,0x07,0x1E,0x75,0x3E,0xC5,0x12,0xB4,0xDD,0xB7,0x50,0x18,0x76,0x5B,0x44,0x87,0xD8,0xFC,0xE4,0xF7,0x6E,0x00,0x1E,0xFC,0x06,0x37,0x70,0xEA,0x14,0x4A,0xBE,0xBF,0xE8,0xAD,0x42,0x64,0x0B,0xED,0xE2,0x13,0x85,0x6C,0x30,0xDD,0x69,0xFA,0xCC,0xF5,0xC1,0x7D,0xC8,0x65,0xBA,0x92,0xC0,0x89,0xCA,0x9D,0x3C,0xF3,0x02,0x82,0xAE,0x57,0x08,0x91,0x08,0x0C,0x44,0x96,0x7E,0xB8,0x15,0x40,0x14,0x16,0x75,0x18,0xD4,0xAF,0x07,0xC7,0x3C,0xA3,0xF9,0x48,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x9E,0x40,0x2B,0xF0,0x57,0x45,0xAD,0x04,0x21,0xD4,0x18,0x48,0xDF,0x9A,0x88,0x2C,0xC9,0x40,0x87,0x52,0xA5,0x95,0xA1,0xA8,0x6B,0x74,0x73,0xFC,0x1B,0xD7,0x6B,0xDA,0xDA,0xC6,0x89,0x22,0x25,0x11,0xE6,0x00,0x31,0x77,0x36,0xD6,0x6A,0x17,0xC7,0x02,0xF1,0xFD,0x4F,0xB0,0x51,0x0D,0x37,0x6E,0xF5,0x06,0x1D,0x96,0x34,0x61,0xF6,0x3C,0xCE,0x7D,0xDB,0x80,0x01,0xDF,0x01,0x8C,0x77,0x3A,0x85,0x10,0xAB,0xCF,0xFA,0x2A,0x54,0x39,0x02,0xFA,0x5E,0x24,0xE1,0x58,0xC3,0x37,0x5A,0x7C,0xAC,0xFD,0x70,0x5C,0xDC,0x99,0x6E,0xA6,0xAC,0x22,0x72,0xA6,0x53,0xFC,0xC0,0xA0,0x2A,0xF5,0xC2,0x24,0x10,0x83,0x11,0x24,0x67,0xCE,0x05,0x50,0x01,0x45,0x9D,0x46,0x0D,0x6B,0xC1,0xF2,0xF3,0xE8,0xFE,0x52,0x0A,0x27,0x90,0x0A,0x3F,0x15,0xD1,0x68,0xD0,0x48,0x75,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x04,0xB7,0xE6,0xA0,0x82,0xF2,0x50,0x20,0x75,0x09,0x65,0x68,0x1A,0x9A,0xDD,0x1C,0x3F,0xC6,0xF5,0xD8,0xBD,0x96,0xB1,0xA0,0x92,0x29,0x44,0x78,0x60,0x0C,0x5D,0xCE,0xED,0x7A,0x85,0xF0,0x70,0x1C,0x7F,0x52,0x7B,0x14,0x43,0x4C,0x76,0xDD,0x41,0x86,0x59,0x6D,0x18,0x7C,0x63,0xF3,0x9F,0x74,0xB8,0x00,0x77,0xC0,0x18,0xDD,0xCE,0xA2,0xD1,0x2A,0xF3,0xFE,0x22,0xB5,0x0E,0x42,0xAF,0xB7,0x89,0x38,0x15,0xB0,0xCD,0xD6,0x27,0xEB,0x3F,0x5C,0x05,0xF7,0x26,0x5A,0x6A,0x4B,0x08,0x9E,0xAA,0x74,0xFF,0x30,0x0A,0x0A,0xBD,0x72,0xA2,0x44,0x20,0xC6,0x92,0x59,0xF3,0x80,0x55,0x00,0x51,0x64,0xD4,0x63,0x5A,0xF0,0x1F,0x1C,0xFA,0x3C,0xE5,0x22,0x89,0xE4,0x00,0xAF,0xC5,0x74,0x16,0xB4,0x12,0x1C,0x50,0x61,0x2D,0xF8,0x6A,0x20,0xBC,0x96,0x82,0x1D,0x42,0x5A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0xD6,0x86,0xA6,0xB4,0xD1,0xCF,0xF1,0xBC,0x5D,0xAF,0x65,0xAE,0x9A,0x24,0x8A,0x52,0xC7,0x98,0x03,0x14,0xDC,0xDB,0x5E,0xA0,0x5F,0x1C,0x07,0x1E,0x75,0x3E,0xC5,0x12,0xB4,0xDD,0xB7,0x50,0x18,0x76,0x5B,0x44,0x87,0xD8,0xFC,0xE4,0xF7,0x6E,0x00,0x1E,0xFC,0x06,0x37,0x70,0xEA,0x14,0x4A,0xBE,0xBF,0xE8,0xAD,0x42,0x64,0x0B,0xED,0xE2,0x13,0x85,0x6C,0x30,0xDD,0x69,0xFA,0xCC,0xF5,0xC1,0x7D,0xC8,0x65,0xBA,0x92,0xC0,0x89,0xCA,0x9D,0x3C,0xF3,0x02,0x82,0xAE,0x57,0x08,0x91,0x08,0x0C,0x44,0x96,0x7E,0xB8,0x15,0x40,0x14,0x16,0x75,0x18,0xD4,0xAF,0x07,0xC7,0x3C,0xA3,0xF9,0x48,0xA0,0x9E,0x40,0x2B,0xF0,0x57,0x45,0xAD,0x04,0x21,0xD4,0x18,0x48,0xDF,0x9A,0x88,0x2C,0xC9,0x40,0x87,0x52,0xA5,0x95,0xA1,0xA8,0x6B,0x74,0x73,0xFC,0x1B,0xD7,0x6B,0xDA,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x59,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x59,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
dheerajmpai23 | 0:e80c23aacae6 | 37 | int a[100]; |
dheerajmpai23 | 0:e80c23aacae6 | 38 | int b[100]; |
dheerajmpai23 | 0:e80c23aacae6 | 39 | int c[100]; |
dheerajmpai23 | 0:e80c23aacae6 | 40 | |
dheerajmpai23 | 0:e80c23aacae6 | 41 | /*****ERROR CHECKING ALGO*****/ |
dheerajmpai23 | 0:e80c23aacae6 | 42 | unsigned char status =0; |
dheerajmpai23 | 0:e80c23aacae6 | 43 | unsigned int cmd_err_cnt=0; |
dheerajmpai23 | 0:e80c23aacae6 | 44 | unsigned int state_err_cnt=0; |
dheerajmpai23 | 0:e80c23aacae6 | 45 | /***********/ |
dheerajmpai23 | 0:e80c23aacae6 | 46 | |
dheerajmpai23 | 0:e80c23aacae6 | 47 | #define SPI_NOP 0xFF |
dheerajmpai23 | 0:e80c23aacae6 | 48 | /***********************************************************************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 49 | void bbram_write() |
dheerajmpai23 | 0:e80c23aacae6 | 50 | { |
dheerajmpai23 | 0:e80c23aacae6 | 51 | /* CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 52 | adf.write(0xB0);//PHY_OFF |
dheerajmpai23 | 0:e80c23aacae6 | 53 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 54 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 55 | *///Commented on 21st October debugging |
dheerajmpai23 | 0:e80c23aacae6 | 56 | // Write bbram |
dheerajmpai23 | 0:e80c23aacae6 | 57 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 58 | adf.write(0x19); |
dheerajmpai23 | 0:e80c23aacae6 | 59 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 60 | adf.write(0x60); |
dheerajmpai23 | 0:e80c23aacae6 | 61 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 62 | |
dheerajmpai23 | 0:e80c23aacae6 | 63 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 64 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 65 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 66 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 67 | |
dheerajmpai23 | 0:e80c23aacae6 | 68 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 69 | adf.write(0x33); |
dheerajmpai23 | 0:e80c23aacae6 | 70 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 71 | adf.write(0xF4);//Frequency Register F9 = 435.802 MHz F4 = 435.800 MHz |
dheerajmpai23 | 0:e80c23aacae6 | 72 | |
dheerajmpai23 | 0:e80c23aacae6 | 73 | adf.write(0xC2); |
dheerajmpai23 | 0:e80c23aacae6 | 74 | adf.write(0x10); |
dheerajmpai23 | 0:e80c23aacae6 | 75 | adf.write(0xC0); |
dheerajmpai23 | 0:e80c23aacae6 | 76 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 77 | |
dheerajmpai23 | 0:e80c23aacae6 | 78 | adf.write(0x30); |
dheerajmpai23 | 0:e80c23aacae6 | 79 | adf.write(0x31); |
dheerajmpai23 | 0:e80c23aacae6 | 80 | adf.write(0x07); |
dheerajmpai23 | 0:e80c23aacae6 | 81 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 82 | |
dheerajmpai23 | 0:e80c23aacae6 | 83 | adf.write(0x01); |
dheerajmpai23 | 0:e80c23aacae6 | 84 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 85 | adf.write(0x7F); |
dheerajmpai23 | 0:e80c23aacae6 | 86 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 87 | |
dheerajmpai23 | 0:e80c23aacae6 | 88 | adf.write(0x0B); |
dheerajmpai23 | 0:e80c23aacae6 | 89 | adf.write(0x37); |
dheerajmpai23 | 0:e80c23aacae6 | 90 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 91 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 92 | |
dheerajmpai23 | 0:e80c23aacae6 | 93 | adf.write(0x40); |
dheerajmpai23 | 0:e80c23aacae6 | 94 | adf.write(0x0C); |
dheerajmpai23 | 0:e80c23aacae6 | 95 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 96 | adf.write(0x05); |
dheerajmpai23 | 0:e80c23aacae6 | 97 | |
dheerajmpai23 | 0:e80c23aacae6 | 98 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 99 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 100 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 101 | adf.write(0x12); |
dheerajmpai23 | 0:e80c23aacae6 | 102 | |
dheerajmpai23 | 0:e80c23aacae6 | 103 | adf.write(0x34); |
dheerajmpai23 | 0:e80c23aacae6 | 104 | adf.write(0x56); |
dheerajmpai23 | 0:e80c23aacae6 | 105 | adf.write(0x10); |
dheerajmpai23 | 0:e80c23aacae6 | 106 | adf.write(0x10); |
dheerajmpai23 | 0:e80c23aacae6 | 107 | |
dheerajmpai23 | 0:e80c23aacae6 | 108 | adf.write(0xC4); // Different |
dheerajmpai23 | 0:e80c23aacae6 | 109 | adf.write(0x14); |
dheerajmpai23 | 0:e80c23aacae6 | 110 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 111 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 112 | |
dheerajmpai23 | 0:e80c23aacae6 | 113 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 114 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 115 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 116 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 117 | |
dheerajmpai23 | 0:e80c23aacae6 | 118 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 119 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 120 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 121 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 122 | |
dheerajmpai23 | 0:e80c23aacae6 | 123 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 124 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 125 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 126 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 127 | |
dheerajmpai23 | 0:e80c23aacae6 | 128 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 129 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 130 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 131 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 132 | |
dheerajmpai23 | 0:e80c23aacae6 | 133 | adf.write(0x04); |
dheerajmpai23 | 0:e80c23aacae6 | 134 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 135 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 136 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 137 | |
dheerajmpai23 | 0:e80c23aacae6 | 138 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 139 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 140 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 141 | wait(1); |
dheerajmpai23 | 0:e80c23aacae6 | 142 | |
dheerajmpai23 | 0:e80c23aacae6 | 143 | } |
dheerajmpai23 | 0:e80c23aacae6 | 144 | |
dheerajmpai23 | 0:e80c23aacae6 | 145 | |
dheerajmpai23 | 0:e80c23aacae6 | 146 | /******************************************************************************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 147 | |
dheerajmpai23 | 0:e80c23aacae6 | 148 | void initiate(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 149 | |
dheerajmpai23 | 0:e80c23aacae6 | 150 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 151 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 152 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 153 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 154 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 155 | |
dheerajmpai23 | 0:e80c23aacae6 | 156 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 157 | adf.write(0x08); // TRANSMIT_DATA LENGTH |
dheerajmpai23 | 0:e80c23aacae6 | 158 | adf.write(0x14); |
dheerajmpai23 | 0:e80c23aacae6 | 159 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 160 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 161 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 162 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 163 | adf.write(0x08); // TRANSMIT_DATA LENGTH |
dheerajmpai23 | 0:e80c23aacae6 | 164 | adf.write(0x15); |
dheerajmpai23 | 0:e80c23aacae6 | 165 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 166 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 167 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 168 | |
dheerajmpai23 | 0:e80c23aacae6 | 169 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 170 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 171 | adf.write(0x24); // TX_BASE ADDRESS 0x20(starting Tx Byte) |
dheerajmpai23 | 0:e80c23aacae6 | 172 | adf.write(0x20); |
dheerajmpai23 | 0:e80c23aacae6 | 173 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 174 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 175 | |
dheerajmpai23 | 0:e80c23aacae6 | 176 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 177 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 178 | adf.write(0x37);// BUFFER SIZE 0xE0=224 Bytes 0x137 is adress of buffer size |
dheerajmpai23 | 0:e80c23aacae6 | 179 | adf.write(0xE0); |
dheerajmpai23 | 0:e80c23aacae6 | 180 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 181 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 182 | |
dheerajmpai23 | 0:e80c23aacae6 | 183 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 184 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 185 | adf.write(0x36);//BB_Tx_Buffer Signal when Buffer is half filled |
dheerajmpai23 | 0:e80c23aacae6 | 186 | adf.write(0x70);//0x70 = 112 >> When Half buffer interrupt is given |
dheerajmpai23 | 0:e80c23aacae6 | 187 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 188 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 189 | |
dheerajmpai23 | 0:e80c23aacae6 | 190 | |
dheerajmpai23 | 0:e80c23aacae6 | 191 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 192 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 193 | adf.write(0x39);//BB_Tx_Buffer Signal when Buffer is half filled |
dheerajmpai23 | 0:e80c23aacae6 | 194 | adf.write(0x10);//0x70 = 112 >> When Half buffer interrupt is given |
dheerajmpai23 | 0:e80c23aacae6 | 195 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 196 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 197 | |
dheerajmpai23 | 0:e80c23aacae6 | 198 | } |
dheerajmpai23 | 0:e80c23aacae6 | 199 | |
dheerajmpai23 | 0:e80c23aacae6 | 200 | |
dheerajmpai23 | 0:e80c23aacae6 | 201 | |
dheerajmpai23 | 0:e80c23aacae6 | 202 | /*int irq_src(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 203 | |
dheerajmpai23 | 0:e80c23aacae6 | 204 | adf.write(0x2B); |
dheerajmpai23 | 0:e80c23aacae6 | 205 | adf.write(0x36); |
dheerajmpai23 | 0:e80c23aacae6 | 206 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 207 | irqsrc = adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 208 | |
dheerajmpai23 | 0:e80c23aacae6 | 209 | irqsrc &= 0x60; |
dheerajmpai23 | 0:e80c23aacae6 | 210 | if (irqsrc == 0x20) |
dheerajmpai23 | 0:e80c23aacae6 | 211 | return 1;//Buffer is almost full |
dheerajmpai23 | 0:e80c23aacae6 | 212 | else if (irqsrc == 0x40) |
dheerajmpai23 | 0:e80c23aacae6 | 213 | return 2;// Buffer is Full |
dheerajmpai23 | 0:e80c23aacae6 | 214 | else |
dheerajmpai23 | 0:e80c23aacae6 | 215 | return 0; |
dheerajmpai23 | 0:e80c23aacae6 | 216 | } |
dheerajmpai23 | 0:e80c23aacae6 | 217 | */ |
dheerajmpai23 | 0:e80c23aacae6 | 218 | int p=112; |
dheerajmpai23 | 0:e80c23aacae6 | 219 | int count = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 220 | int intcount =0; |
dheerajmpai23 | 0:e80c23aacae6 | 221 | |
dheerajmpai23 | 0:e80c23aacae6 | 222 | void write_data(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 223 | // t.reset(); |
dheerajmpai23 | 0:e80c23aacae6 | 224 | // count++; |
dheerajmpai23 | 0:e80c23aacae6 | 225 | // cout<<"3"<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 226 | // ledr=!ledr; |
dheerajmpai23 | 0:e80c23aacae6 | 227 | // cout<<"irq detected"<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 228 | // src = irq_src(); |
dheerajmpai23 | 0:e80c23aacae6 | 229 | p+=112; |
dheerajmpai23 | 0:e80c23aacae6 | 230 | |
dheerajmpai23 | 0:e80c23aacae6 | 231 | //CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 232 | // adf.write(0x0B);//IRQ_SOURCE_Random write //To read CMD = 2B 36 FF FF |
dheerajmpai23 | 0:e80c23aacae6 | 233 | // adf.write(0x36);//Address : 0x336 |
dheerajmpai23 | 0:e80c23aacae6 | 234 | // adf.write(0xFF);//Put Low |
dheerajmpai23 | 0:e80c23aacae6 | 235 | // CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 236 | // wait_us(80); |
dheerajmpai23 | 0:e80c23aacae6 | 237 | // CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 238 | // k=0; |
dheerajmpai23 | 0:e80c23aacae6 | 239 | |
dheerajmpai23 | 0:e80c23aacae6 | 240 | if(!j){ |
dheerajmpai23 | 0:e80c23aacae6 | 241 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 242 | adf.write(0x20); |
dheerajmpai23 | 0:e80c23aacae6 | 243 | while(k<=223){ |
dheerajmpai23 | 0:e80c23aacae6 | 244 | |
dheerajmpai23 | 0:e80c23aacae6 | 245 | adf.write(data[k]); |
dheerajmpai23 | 0:e80c23aacae6 | 246 | k++; |
dheerajmpai23 | 0:e80c23aacae6 | 247 | } |
dheerajmpai23 | 0:e80c23aacae6 | 248 | |
dheerajmpai23 | 0:e80c23aacae6 | 249 | } |
dheerajmpai23 | 0:e80c23aacae6 | 250 | |
dheerajmpai23 | 0:e80c23aacae6 | 251 | else if(k<sizeof(data)){ |
dheerajmpai23 | 0:e80c23aacae6 | 252 | // if(src == 1){ |
dheerajmpai23 | 0:e80c23aacae6 | 253 | if(j%2){ //src== Buffer Half Full src == 1 |
dheerajmpai23 | 0:e80c23aacae6 | 254 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 255 | adf.write(0x20); |
dheerajmpai23 | 0:e80c23aacae6 | 256 | } |
dheerajmpai23 | 0:e80c23aacae6 | 257 | |
dheerajmpai23 | 0:e80c23aacae6 | 258 | // else if(src==2){ |
dheerajmpai23 | 0:e80c23aacae6 | 259 | else{ //src== Buffer is Full src==2 |
dheerajmpai23 | 0:e80c23aacae6 | 260 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 261 | adf.write(0x90); |
dheerajmpai23 | 0:e80c23aacae6 | 262 | } |
dheerajmpai23 | 0:e80c23aacae6 | 263 | |
dheerajmpai23 | 0:e80c23aacae6 | 264 | |
dheerajmpai23 | 0:e80c23aacae6 | 265 | while(k<p){ |
dheerajmpai23 | 0:e80c23aacae6 | 266 | adf.write(data[k]); |
dheerajmpai23 | 0:e80c23aacae6 | 267 | k++; |
dheerajmpai23 | 0:e80c23aacae6 | 268 | |
dheerajmpai23 | 0:e80c23aacae6 | 269 | } |
dheerajmpai23 | 0:e80c23aacae6 | 270 | // if((k)>=sizeof(data)) |
dheerajmpai23 | 0:e80c23aacae6 | 271 | // { |
dheerajmpai23 | 0:e80c23aacae6 | 272 | // ticker.detach();//Stop interrupt detection |
dheerajmpai23 | 0:e80c23aacae6 | 273 | // cout<<src<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 274 | // } |
dheerajmpai23 | 0:e80c23aacae6 | 275 | |
dheerajmpai23 | 0:e80c23aacae6 | 276 | |
dheerajmpai23 | 0:e80c23aacae6 | 277 | } |
dheerajmpai23 | 0:e80c23aacae6 | 278 | |
dheerajmpai23 | 0:e80c23aacae6 | 279 | else if(k>=(sizeof(data)) ){ |
dheerajmpai23 | 0:e80c23aacae6 | 280 | k=0; |
dheerajmpai23 | 0:e80c23aacae6 | 281 | j=1; |
dheerajmpai23 | 0:e80c23aacae6 | 282 | p=0; |
dheerajmpai23 | 0:e80c23aacae6 | 283 | // cout<<count<<" "<<sizeof(data)/112<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 284 | } |
dheerajmpai23 | 0:e80c23aacae6 | 285 | |
dheerajmpai23 | 0:e80c23aacae6 | 286 | |
dheerajmpai23 | 0:e80c23aacae6 | 287 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 288 | adf.write(0x0B);//IRQ_SOURCE_Random write //To read CMD = 2B 36 FF FF |
dheerajmpai23 | 0:e80c23aacae6 | 289 | adf.write(0x36);//Address : 0x336 |
dheerajmpai23 | 0:e80c23aacae6 | 290 | adf.write(0xFF);//Put Low |
dheerajmpai23 | 0:e80c23aacae6 | 291 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 292 | wait_us(80); |
dheerajmpai23 | 0:e80c23aacae6 | 293 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 294 | |
dheerajmpai23 | 0:e80c23aacae6 | 295 | // a[r]=t.read_us(); |
dheerajmpai23 | 0:e80c23aacae6 | 296 | j++; |
dheerajmpai23 | 0:e80c23aacae6 | 297 | // r++; |
dheerajmpai23 | 0:e80c23aacae6 | 298 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 299 | wait_us(1); |
dheerajmpai23 | 0:e80c23aacae6 | 300 | } |
dheerajmpai23 | 0:e80c23aacae6 | 301 | |
dheerajmpai23 | 0:e80c23aacae6 | 302 | void Interrupt(){ |
dheerajmpai23 | 0:e80c23aacae6 | 303 | x = IRQ; |
dheerajmpai23 | 0:e80c23aacae6 | 304 | // intcount++; |
dheerajmpai23 | 0:e80c23aacae6 | 305 | if(x) |
dheerajmpai23 | 0:e80c23aacae6 | 306 | { |
dheerajmpai23 | 0:e80c23aacae6 | 307 | write_data(); |
dheerajmpai23 | 0:e80c23aacae6 | 308 | } |
dheerajmpai23 | 0:e80c23aacae6 | 309 | } |
dheerajmpai23 | 0:e80c23aacae6 | 310 | |
dheerajmpai23 | 0:e80c23aacae6 | 311 | |
dheerajmpai23 | 0:e80c23aacae6 | 312 | |
dheerajmpai23 | 0:e80c23aacae6 | 313 | |
dheerajmpai23 | 0:e80c23aacae6 | 314 | void send_data(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 315 | |
dheerajmpai23 | 0:e80c23aacae6 | 316 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 317 | adf.write(0xBB); |
dheerajmpai23 | 0:e80c23aacae6 | 318 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 319 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 320 | |
dheerajmpai23 | 0:e80c23aacae6 | 321 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 322 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 323 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 324 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 325 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 326 | |
dheerajmpai23 | 0:e80c23aacae6 | 327 | write_data(); |
dheerajmpai23 | 0:e80c23aacae6 | 328 | |
dheerajmpai23 | 0:e80c23aacae6 | 329 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 330 | adf.write(0xB1); |
dheerajmpai23 | 0:e80c23aacae6 | 331 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 332 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 333 | |
dheerajmpai23 | 0:e80c23aacae6 | 334 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 335 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 336 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 337 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 338 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 339 | |
dheerajmpai23 | 0:e80c23aacae6 | 340 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 341 | adf.write(0xB5); |
dheerajmpai23 | 0:e80c23aacae6 | 342 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 343 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 344 | |
dheerajmpai23 | 0:e80c23aacae6 | 345 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 346 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 347 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 348 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 349 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 350 | } |
dheerajmpai23 | 0:e80c23aacae6 | 351 | /*******ADDITIONAL STUFF****************/ |
dheerajmpai23 | 0:e80c23aacae6 | 352 | unsigned char check_status(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 353 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 354 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 355 | unsigned char stat = adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 356 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 357 | return stat; |
dheerajmpai23 | 0:e80c23aacae6 | 358 | } |
dheerajmpai23 | 0:e80c23aacae6 | 359 | |
dheerajmpai23 | 0:e80c23aacae6 | 360 | unsigned char assrt_phy_off(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
dheerajmpai23 | 0:e80c23aacae6 | 361 | status=check_status(); |
dheerajmpai23 | 0:e80c23aacae6 | 362 | if(status==0xB1){ |
dheerajmpai23 | 0:e80c23aacae6 | 363 | return 0; |
dheerajmpai23 | 0:e80c23aacae6 | 364 | } |
dheerajmpai23 | 0:e80c23aacae6 | 365 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
dheerajmpai23 | 0:e80c23aacae6 | 366 | return 1;//You need to Reset the hardware |
dheerajmpai23 | 0:e80c23aacae6 | 367 | } |
dheerajmpai23 | 0:e80c23aacae6 | 368 | else if(state_err_cnt>STATE_ERR_THRS){ |
dheerajmpai23 | 0:e80c23aacae6 | 369 | return 1;//Again reset the hardware |
dheerajmpai23 | 0:e80c23aacae6 | 370 | } |
dheerajmpai23 | 0:e80c23aacae6 | 371 | else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
dheerajmpai23 | 0:e80c23aacae6 | 372 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 373 | adf.write(0xB0); //CMD_PHY_OFF |
dheerajmpai23 | 0:e80c23aacae6 | 374 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 375 | wait_us(PHY_OFF_EXEC_TIME);// Typical = 24us We are giving 300us |
dheerajmpai23 | 0:e80c23aacae6 | 376 | return assrt_phy_off(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
dheerajmpai23 | 0:e80c23aacae6 | 377 | } |
dheerajmpai23 | 0:e80c23aacae6 | 378 | else if(status&0x80==0x00){ |
dheerajmpai23 | 0:e80c23aacae6 | 379 | wait_ms(5); |
dheerajmpai23 | 0:e80c23aacae6 | 380 | //Error: SPI=0 Not ready CMD= Dont care |
dheerajmpai23 | 0:e80c23aacae6 | 381 | return assrt_phy_off(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
dheerajmpai23 | 0:e80c23aacae6 | 382 | } |
dheerajmpai23 | 0:e80c23aacae6 | 383 | else {//if(status&0xA0==0x80){ |
dheerajmpai23 | 0:e80c23aacae6 | 384 | wait_ms(1); |
dheerajmpai23 | 0:e80c23aacae6 | 385 | //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
dheerajmpai23 | 0:e80c23aacae6 | 386 | return assrt_phy_off(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
dheerajmpai23 | 0:e80c23aacae6 | 387 | } |
dheerajmpai23 | 0:e80c23aacae6 | 388 | } |
dheerajmpai23 | 0:e80c23aacae6 | 389 | |
dheerajmpai23 | 0:e80c23aacae6 | 390 | /***************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 391 | bool hardware_reset(int bcn_call){ |
dheerajmpai23 | 0:e80c23aacae6 | 392 | if (bcn_call>20){ |
dheerajmpai23 | 0:e80c23aacae6 | 393 | return 1; |
dheerajmpai23 | 0:e80c23aacae6 | 394 | } |
dheerajmpai23 | 0:e80c23aacae6 | 395 | int count=0; |
dheerajmpai23 | 0:e80c23aacae6 | 396 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 397 | adf.write(CMD_HW_RESET); |
dheerajmpai23 | 0:e80c23aacae6 | 398 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 399 | wait_us(2);// Typically 1 us |
dheerajmpai23 | 0:e80c23aacae6 | 400 | while(count<1000){ |
dheerajmpai23 | 0:e80c23aacae6 | 401 | if(MISO_PIN){ |
dheerajmpai23 | 0:e80c23aacae6 | 402 | |
dheerajmpai23 | 0:e80c23aacae6 | 403 | if(!assrt_phy_off(0,0,0)){ |
dheerajmpai23 | 0:e80c23aacae6 | 404 | break; |
dheerajmpai23 | 0:e80c23aacae6 | 405 | } |
dheerajmpai23 | 0:e80c23aacae6 | 406 | count++; |
dheerajmpai23 | 0:e80c23aacae6 | 407 | } |
dheerajmpai23 | 0:e80c23aacae6 | 408 | } |
dheerajmpai23 | 0:e80c23aacae6 | 409 | if(count==10){ |
dheerajmpai23 | 0:e80c23aacae6 | 410 | return hardware_reset(bcn_call+1); |
dheerajmpai23 | 0:e80c23aacae6 | 411 | } |
dheerajmpai23 | 0:e80c23aacae6 | 412 | else |
dheerajmpai23 | 0:e80c23aacae6 | 413 | return 0; |
dheerajmpai23 | 0:e80c23aacae6 | 414 | |
dheerajmpai23 | 0:e80c23aacae6 | 415 | } |
dheerajmpai23 | 0:e80c23aacae6 | 416 | |
dheerajmpai23 | 0:e80c23aacae6 | 417 | |
dheerajmpai23 | 0:e80c23aacae6 | 418 | /*******************************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 419 | int main() |
dheerajmpai23 | 0:e80c23aacae6 | 420 | { |
dheerajmpai23 | 0:e80c23aacae6 | 421 | adf.format(8,0); |
dheerajmpai23 | 0:e80c23aacae6 | 422 | adf.frequency(1000000); |
dheerajmpai23 | 0:e80c23aacae6 | 423 | /**ADDED On 21/10/2015 ***/ |
dheerajmpai23 | 0:e80c23aacae6 | 424 | /******************/ |
dheerajmpai23 | 0:e80c23aacae6 | 425 | /***********/ |
dheerajmpai23 | 0:e80c23aacae6 | 426 | bool state_0=0; |
dheerajmpai23 | 0:e80c23aacae6 | 427 | state_0=assrt_phy_off(0,0,0); |
dheerajmpai23 | 0:e80c23aacae6 | 428 | while(1){ |
dheerajmpai23 | 0:e80c23aacae6 | 429 | if(!state_0){ |
dheerajmpai23 | 0:e80c23aacae6 | 430 | bbram_write(); |
dheerajmpai23 | 0:e80c23aacae6 | 431 | break; |
dheerajmpai23 | 0:e80c23aacae6 | 432 | } |
dheerajmpai23 | 0:e80c23aacae6 | 433 | else{ |
dheerajmpai23 | 0:e80c23aacae6 | 434 | hardware_reset(0); |
dheerajmpai23 | 0:e80c23aacae6 | 435 | } |
dheerajmpai23 | 0:e80c23aacae6 | 436 | } |
dheerajmpai23 | 0:e80c23aacae6 | 437 | state_0=assrt_phy_off(0,0,0);// We actually do not need this but make sure "we do not need this" |
dheerajmpai23 | 0:e80c23aacae6 | 438 | |
dheerajmpai23 | 0:e80c23aacae6 | 439 | initiate(); |
dheerajmpai23 | 0:e80c23aacae6 | 440 | send_data(); |
dheerajmpai23 | 0:e80c23aacae6 | 441 | cout<<"Work"<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 442 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 443 | adf.write(0x0B);//IRQ_SOURCE_Random write //To read CMD = 2B 36 FF FF |
dheerajmpai23 | 0:e80c23aacae6 | 444 | adf.write(0x36);//Address : 0x336 |
dheerajmpai23 | 0:e80c23aacae6 | 445 | adf.write(0xFF);//Put Low Clearing the MCR Value of the Source Register |
dheerajmpai23 | 0:e80c23aacae6 | 446 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 447 | |
dheerajmpai23 | 0:e80c23aacae6 | 448 | ticker.attach_us(&Interrupt,32000); |
dheerajmpai23 | 0:e80c23aacae6 | 449 | |
dheerajmpai23 | 0:e80c23aacae6 | 450 | } |