Dheeraj M Pai
/
October_22_1_28AM
Partially made code for adf7023
main.cpp@2:599022fe2f99, 2016-03-17 (annotated)
- Committer:
- dheerajmpai23
- Date:
- Thu Mar 17 11:35:11 2016 +0000
- Revision:
- 2:599022fe2f99
- Parent:
- 1:434b2062426b
ADF_TEST_CODE;
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 | 2:599022fe2f99 | 10 | //#define MISO_PIN PTA17 |
dheerajmpai23 | 2:599022fe2f99 | 11 | #define MISO_PIN PTE3 |
dheerajmpai23 | 0:e80c23aacae6 | 12 | #define THRS 20 |
dheerajmpai23 | 0:e80c23aacae6 | 13 | #define STATE_ERR_THRS 20 |
dheerajmpai23 | 0:e80c23aacae6 | 14 | #define PHY_OFF_EXEC_TIME 300 |
dheerajmpai23 | 1:434b2062426b | 15 | #define PHY_ON_EXEC_TIME 300 |
dheerajmpai23 | 1:434b2062426b | 16 | #define PHY_TX_EXEC_TIME 600 |
dheerajmpai23 | 0:e80c23aacae6 | 17 | /******DEFINING OMMANDS*********/ |
dheerajmpai23 | 0:e80c23aacae6 | 18 | |
dheerajmpai23 | 0:e80c23aacae6 | 19 | #define CMD_HW_RESET 0xC8 |
dheerajmpai23 | 2:599022fe2f99 | 20 | SPI adf(PTE1, MISO_PIN, PTE2); |
dheerajmpai23 | 0:e80c23aacae6 | 21 | //MOSI, MISO, CLOCK |
dheerajmpai23 | 2:599022fe2f99 | 22 | DigitalOut CS(PTA15); |
dheerajmpai23 | 0:e80c23aacae6 | 23 | //DigitalOut CS(PTD4);//D10==PTD4 |
dheerajmpai23 | 0:e80c23aacae6 | 24 | Serial PC(USBTX, USBRX); |
dheerajmpai23 | 0:e80c23aacae6 | 25 | DigitalOut ledr(LED1); |
dheerajmpai23 | 0:e80c23aacae6 | 26 | DigitalOut led2(LED2); |
dheerajmpai23 | 2:599022fe2f99 | 27 | InterruptIn IRQ(PTA14); |
dheerajmpai23 | 0:e80c23aacae6 | 28 | //InterruptIn IRQ(PTA13);//D8==PTA13 |
dheerajmpai23 | 0:e80c23aacae6 | 29 | Ticker ticker; |
dheerajmpai23 | 0:e80c23aacae6 | 30 | //Timer t; |
dheerajmpai23 | 0:e80c23aacae6 | 31 | //Timer stop; |
dheerajmpai23 | 0:e80c23aacae6 | 32 | int x=IRQ; |
dheerajmpai23 | 0:e80c23aacae6 | 33 | int src=0; |
dheerajmpai23 | 0:e80c23aacae6 | 34 | int irqsrc = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 35 | int j = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 36 | int k = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 37 | int irq1=0; |
dheerajmpai23 | 0:e80c23aacae6 | 38 | int r = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 39 | 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 | 40 | int a[100]; |
dheerajmpai23 | 0:e80c23aacae6 | 41 | int b[100]; |
dheerajmpai23 | 0:e80c23aacae6 | 42 | int c[100]; |
dheerajmpai23 | 0:e80c23aacae6 | 43 | |
dheerajmpai23 | 0:e80c23aacae6 | 44 | /*****ERROR CHECKING ALGO*****/ |
dheerajmpai23 | 0:e80c23aacae6 | 45 | unsigned char status =0; |
dheerajmpai23 | 0:e80c23aacae6 | 46 | unsigned int cmd_err_cnt=0; |
dheerajmpai23 | 0:e80c23aacae6 | 47 | unsigned int state_err_cnt=0; |
dheerajmpai23 | 0:e80c23aacae6 | 48 | /***********/ |
dheerajmpai23 | 0:e80c23aacae6 | 49 | |
dheerajmpai23 | 0:e80c23aacae6 | 50 | #define SPI_NOP 0xFF |
dheerajmpai23 | 0:e80c23aacae6 | 51 | /***********************************************************************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 52 | void bbram_write() |
dheerajmpai23 | 0:e80c23aacae6 | 53 | { |
dheerajmpai23 | 0:e80c23aacae6 | 54 | /* CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 55 | adf.write(0xB0);//PHY_OFF |
dheerajmpai23 | 0:e80c23aacae6 | 56 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 57 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 58 | *///Commented on 21st October debugging |
dheerajmpai23 | 0:e80c23aacae6 | 59 | // Write bbram |
dheerajmpai23 | 0:e80c23aacae6 | 60 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 61 | adf.write(0x19); |
dheerajmpai23 | 0:e80c23aacae6 | 62 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 63 | adf.write(0x60); //INterrupt Mask |
dheerajmpai23 | 2:599022fe2f99 | 64 | adf.write(0x00); //Address 0x101 |
dheerajmpai23 | 0:e80c23aacae6 | 65 | |
dheerajmpai23 | 0:e80c23aacae6 | 66 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 67 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 68 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 69 | adf.write(0x00); //105 |
dheerajmpai23 | 0:e80c23aacae6 | 70 | |
dheerajmpai23 | 0:e80c23aacae6 | 71 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 72 | adf.write(0x33); |
dheerajmpai23 | 0:e80c23aacae6 | 73 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 74 | adf.write(0xF4);//Frequency Register F9 = 435.802 MHz F4 = 435.800 MHz |
dheerajmpai23 | 0:e80c23aacae6 | 75 | |
dheerajmpai23 | 0:e80c23aacae6 | 76 | adf.write(0xC2); |
dheerajmpai23 | 0:e80c23aacae6 | 77 | adf.write(0x10); |
dheerajmpai23 | 0:e80c23aacae6 | 78 | adf.write(0xC0); |
dheerajmpai23 | 2:599022fe2f99 | 79 | adf.write(0x00);//10D |
dheerajmpai23 | 0:e80c23aacae6 | 80 | |
dheerajmpai23 | 0:e80c23aacae6 | 81 | adf.write(0x30); |
dheerajmpai23 | 0:e80c23aacae6 | 82 | adf.write(0x31); |
dheerajmpai23 | 0:e80c23aacae6 | 83 | adf.write(0x07); |
dheerajmpai23 | 2:599022fe2f99 | 84 | adf.write(0x00);//111 |
dheerajmpai23 | 0:e80c23aacae6 | 85 | |
dheerajmpai23 | 0:e80c23aacae6 | 86 | adf.write(0x01); |
dheerajmpai23 | 0:e80c23aacae6 | 87 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 88 | adf.write(0x7F); |
dheerajmpai23 | 2:599022fe2f99 | 89 | adf.write(0x00);//115 |
dheerajmpai23 | 0:e80c23aacae6 | 90 | |
dheerajmpai23 | 0:e80c23aacae6 | 91 | adf.write(0x0B); |
dheerajmpai23 | 0:e80c23aacae6 | 92 | adf.write(0x37); |
dheerajmpai23 | 0:e80c23aacae6 | 93 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 94 | adf.write(0x00);//119 |
dheerajmpai23 | 0:e80c23aacae6 | 95 | |
dheerajmpai23 | 0:e80c23aacae6 | 96 | adf.write(0x40); |
dheerajmpai23 | 0:e80c23aacae6 | 97 | adf.write(0x0C); |
dheerajmpai23 | 0:e80c23aacae6 | 98 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 99 | adf.write(0x05);//11D |
dheerajmpai23 | 0:e80c23aacae6 | 100 | |
dheerajmpai23 | 0:e80c23aacae6 | 101 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 102 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 103 | adf.write(0x18); |
dheerajmpai23 | 2:599022fe2f99 | 104 | adf.write(0x12);//121 |
dheerajmpai23 | 0:e80c23aacae6 | 105 | |
dheerajmpai23 | 0:e80c23aacae6 | 106 | adf.write(0x34); |
dheerajmpai23 | 0:e80c23aacae6 | 107 | adf.write(0x56); |
dheerajmpai23 | 0:e80c23aacae6 | 108 | adf.write(0x10); |
dheerajmpai23 | 2:599022fe2f99 | 109 | adf.write(0x10);//125 |
dheerajmpai23 | 0:e80c23aacae6 | 110 | |
dheerajmpai23 | 0:e80c23aacae6 | 111 | adf.write(0xC4); // Different |
dheerajmpai23 | 0:e80c23aacae6 | 112 | adf.write(0x14); |
dheerajmpai23 | 0:e80c23aacae6 | 113 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 114 | adf.write(0x00);//129 |
dheerajmpai23 | 0:e80c23aacae6 | 115 | |
dheerajmpai23 | 0:e80c23aacae6 | 116 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 117 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 118 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 119 | adf.write(0x00);//12D |
dheerajmpai23 | 0:e80c23aacae6 | 120 | |
dheerajmpai23 | 0:e80c23aacae6 | 121 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 122 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 123 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 124 | adf.write(0x00);//131 |
dheerajmpai23 | 0:e80c23aacae6 | 125 | |
dheerajmpai23 | 0:e80c23aacae6 | 126 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 127 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 128 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 129 | adf.write(0x00);//135 |
dheerajmpai23 | 0:e80c23aacae6 | 130 | |
dheerajmpai23 | 0:e80c23aacae6 | 131 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 132 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 133 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 134 | adf.write(0x00);//139 |
dheerajmpai23 | 0:e80c23aacae6 | 135 | |
dheerajmpai23 | 0:e80c23aacae6 | 136 | adf.write(0x04); |
dheerajmpai23 | 0:e80c23aacae6 | 137 | adf.write(0x00); |
dheerajmpai23 | 0:e80c23aacae6 | 138 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 139 | adf.write(0x00);//13D |
dheerajmpai23 | 0:e80c23aacae6 | 140 | |
dheerajmpai23 | 0:e80c23aacae6 | 141 | adf.write(0x00); |
dheerajmpai23 | 2:599022fe2f99 | 142 | adf.write(0x00);//13F |
dheerajmpai23 | 0:e80c23aacae6 | 143 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 144 | wait(1); |
dheerajmpai23 | 0:e80c23aacae6 | 145 | |
dheerajmpai23 | 0:e80c23aacae6 | 146 | } |
dheerajmpai23 | 0:e80c23aacae6 | 147 | |
dheerajmpai23 | 0:e80c23aacae6 | 148 | |
dheerajmpai23 | 0:e80c23aacae6 | 149 | /******************************************************************************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 150 | |
dheerajmpai23 | 0:e80c23aacae6 | 151 | void initiate(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 152 | |
dheerajmpai23 | 0:e80c23aacae6 | 153 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 154 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 155 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 156 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 157 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 158 | |
dheerajmpai23 | 0:e80c23aacae6 | 159 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 160 | adf.write(0x08); // TRANSMIT_DATA LENGTH |
dheerajmpai23 | 0:e80c23aacae6 | 161 | adf.write(0x14); |
dheerajmpai23 | 2:599022fe2f99 | 162 | adf.write(0x0F); |
dheerajmpai23 | 0:e80c23aacae6 | 163 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 164 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 165 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 166 | adf.write(0x08); // TRANSMIT_DATA LENGTH |
dheerajmpai23 | 0:e80c23aacae6 | 167 | adf.write(0x15); |
dheerajmpai23 | 2:599022fe2f99 | 168 | adf.write(0x0F); |
dheerajmpai23 | 0:e80c23aacae6 | 169 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 170 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 171 | |
dheerajmpai23 | 0:e80c23aacae6 | 172 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 173 | adf.write(0x09); |
dheerajmpai23 | 2:599022fe2f99 | 174 | adf.write(0x24); // TX_BASE ADDRESS 0x20(starting Tx Byte) 0x124 is the reg that stores the starting point |
dheerajmpai23 | 0:e80c23aacae6 | 175 | adf.write(0x20); |
dheerajmpai23 | 0:e80c23aacae6 | 176 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 177 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 178 | |
dheerajmpai23 | 0:e80c23aacae6 | 179 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 180 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 181 | adf.write(0x37);// BUFFER SIZE 0xE0=224 Bytes 0x137 is adress of buffer size |
dheerajmpai23 | 0:e80c23aacae6 | 182 | adf.write(0xE0); |
dheerajmpai23 | 0:e80c23aacae6 | 183 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 184 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 185 | |
dheerajmpai23 | 0:e80c23aacae6 | 186 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 187 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 188 | adf.write(0x36);//BB_Tx_Buffer Signal when Buffer is half filled |
dheerajmpai23 | 0:e80c23aacae6 | 189 | adf.write(0x70);//0x70 = 112 >> When Half buffer interrupt is given |
dheerajmpai23 | 0:e80c23aacae6 | 190 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 191 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 192 | |
dheerajmpai23 | 0:e80c23aacae6 | 193 | |
dheerajmpai23 | 0:e80c23aacae6 | 194 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 195 | adf.write(0x09); |
dheerajmpai23 | 0:e80c23aacae6 | 196 | adf.write(0x39);//BB_Tx_Buffer Signal when Buffer is half filled |
dheerajmpai23 | 0:e80c23aacae6 | 197 | adf.write(0x10);//0x70 = 112 >> When Half buffer interrupt is given |
dheerajmpai23 | 0:e80c23aacae6 | 198 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 199 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 200 | |
dheerajmpai23 | 0:e80c23aacae6 | 201 | } |
dheerajmpai23 | 0:e80c23aacae6 | 202 | |
dheerajmpai23 | 0:e80c23aacae6 | 203 | |
dheerajmpai23 | 0:e80c23aacae6 | 204 | |
dheerajmpai23 | 0:e80c23aacae6 | 205 | /*int irq_src(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 206 | |
dheerajmpai23 | 0:e80c23aacae6 | 207 | adf.write(0x2B); |
dheerajmpai23 | 0:e80c23aacae6 | 208 | adf.write(0x36); |
dheerajmpai23 | 0:e80c23aacae6 | 209 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 210 | irqsrc = adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 211 | |
dheerajmpai23 | 0:e80c23aacae6 | 212 | irqsrc &= 0x60; |
dheerajmpai23 | 0:e80c23aacae6 | 213 | if (irqsrc == 0x20) |
dheerajmpai23 | 0:e80c23aacae6 | 214 | return 1;//Buffer is almost full |
dheerajmpai23 | 0:e80c23aacae6 | 215 | else if (irqsrc == 0x40) |
dheerajmpai23 | 0:e80c23aacae6 | 216 | return 2;// Buffer is Full |
dheerajmpai23 | 0:e80c23aacae6 | 217 | else |
dheerajmpai23 | 0:e80c23aacae6 | 218 | return 0; |
dheerajmpai23 | 0:e80c23aacae6 | 219 | } |
dheerajmpai23 | 0:e80c23aacae6 | 220 | */ |
dheerajmpai23 | 0:e80c23aacae6 | 221 | int p=112; |
dheerajmpai23 | 0:e80c23aacae6 | 222 | int count = 0; |
dheerajmpai23 | 0:e80c23aacae6 | 223 | int intcount =0; |
dheerajmpai23 | 0:e80c23aacae6 | 224 | |
dheerajmpai23 | 0:e80c23aacae6 | 225 | void write_data(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 226 | // t.reset(); |
dheerajmpai23 | 0:e80c23aacae6 | 227 | // count++; |
dheerajmpai23 | 0:e80c23aacae6 | 228 | // cout<<"3"<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 229 | // ledr=!ledr; |
dheerajmpai23 | 0:e80c23aacae6 | 230 | // cout<<"irq detected"<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 231 | // src = irq_src(); |
dheerajmpai23 | 0:e80c23aacae6 | 232 | p+=112; |
dheerajmpai23 | 0:e80c23aacae6 | 233 | |
dheerajmpai23 | 0:e80c23aacae6 | 234 | //CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 235 | // adf.write(0x0B);//IRQ_SOURCE_Random write //To read CMD = 2B 36 FF FF |
dheerajmpai23 | 0:e80c23aacae6 | 236 | // adf.write(0x36);//Address : 0x336 |
dheerajmpai23 | 0:e80c23aacae6 | 237 | // adf.write(0xFF);//Put Low |
dheerajmpai23 | 0:e80c23aacae6 | 238 | // CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 239 | // wait_us(80); |
dheerajmpai23 | 0:e80c23aacae6 | 240 | // CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 241 | // k=0; |
dheerajmpai23 | 0:e80c23aacae6 | 242 | |
dheerajmpai23 | 0:e80c23aacae6 | 243 | if(!j){ |
dheerajmpai23 | 0:e80c23aacae6 | 244 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 245 | adf.write(0x20); |
dheerajmpai23 | 0:e80c23aacae6 | 246 | while(k<=223){ |
dheerajmpai23 | 0:e80c23aacae6 | 247 | |
dheerajmpai23 | 0:e80c23aacae6 | 248 | adf.write(data[k]); |
dheerajmpai23 | 0:e80c23aacae6 | 249 | k++; |
dheerajmpai23 | 0:e80c23aacae6 | 250 | } |
dheerajmpai23 | 0:e80c23aacae6 | 251 | |
dheerajmpai23 | 0:e80c23aacae6 | 252 | } |
dheerajmpai23 | 0:e80c23aacae6 | 253 | |
dheerajmpai23 | 0:e80c23aacae6 | 254 | else if(k<sizeof(data)){ |
dheerajmpai23 | 0:e80c23aacae6 | 255 | // if(src == 1){ |
dheerajmpai23 | 0:e80c23aacae6 | 256 | if(j%2){ //src== Buffer Half Full src == 1 |
dheerajmpai23 | 0:e80c23aacae6 | 257 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 258 | adf.write(0x20); |
dheerajmpai23 | 0:e80c23aacae6 | 259 | } |
dheerajmpai23 | 0:e80c23aacae6 | 260 | |
dheerajmpai23 | 0:e80c23aacae6 | 261 | // else if(src==2){ |
dheerajmpai23 | 0:e80c23aacae6 | 262 | else{ //src== Buffer is Full src==2 |
dheerajmpai23 | 0:e80c23aacae6 | 263 | adf.write(0x18); |
dheerajmpai23 | 0:e80c23aacae6 | 264 | adf.write(0x90); |
dheerajmpai23 | 0:e80c23aacae6 | 265 | } |
dheerajmpai23 | 0:e80c23aacae6 | 266 | |
dheerajmpai23 | 0:e80c23aacae6 | 267 | |
dheerajmpai23 | 0:e80c23aacae6 | 268 | while(k<p){ |
dheerajmpai23 | 0:e80c23aacae6 | 269 | adf.write(data[k]); |
dheerajmpai23 | 0:e80c23aacae6 | 270 | k++; |
dheerajmpai23 | 0:e80c23aacae6 | 271 | |
dheerajmpai23 | 0:e80c23aacae6 | 272 | } |
dheerajmpai23 | 0:e80c23aacae6 | 273 | // if((k)>=sizeof(data)) |
dheerajmpai23 | 0:e80c23aacae6 | 274 | // { |
dheerajmpai23 | 0:e80c23aacae6 | 275 | // ticker.detach();//Stop interrupt detection |
dheerajmpai23 | 0:e80c23aacae6 | 276 | // cout<<src<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 277 | // } |
dheerajmpai23 | 0:e80c23aacae6 | 278 | |
dheerajmpai23 | 0:e80c23aacae6 | 279 | |
dheerajmpai23 | 0:e80c23aacae6 | 280 | } |
dheerajmpai23 | 0:e80c23aacae6 | 281 | |
dheerajmpai23 | 0:e80c23aacae6 | 282 | else if(k>=(sizeof(data)) ){ |
dheerajmpai23 | 0:e80c23aacae6 | 283 | k=0; |
dheerajmpai23 | 0:e80c23aacae6 | 284 | j=1; |
dheerajmpai23 | 0:e80c23aacae6 | 285 | p=0; |
dheerajmpai23 | 0:e80c23aacae6 | 286 | // cout<<count<<" "<<sizeof(data)/112<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 287 | } |
dheerajmpai23 | 0:e80c23aacae6 | 288 | |
dheerajmpai23 | 0:e80c23aacae6 | 289 | |
dheerajmpai23 | 0:e80c23aacae6 | 290 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 291 | adf.write(0x0B);//IRQ_SOURCE_Random write //To read CMD = 2B 36 FF FF |
dheerajmpai23 | 0:e80c23aacae6 | 292 | adf.write(0x36);//Address : 0x336 |
dheerajmpai23 | 0:e80c23aacae6 | 293 | adf.write(0xFF);//Put Low |
dheerajmpai23 | 0:e80c23aacae6 | 294 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 295 | wait_us(80); |
dheerajmpai23 | 0:e80c23aacae6 | 296 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 297 | |
dheerajmpai23 | 0:e80c23aacae6 | 298 | // a[r]=t.read_us(); |
dheerajmpai23 | 0:e80c23aacae6 | 299 | j++; |
dheerajmpai23 | 0:e80c23aacae6 | 300 | // r++; |
dheerajmpai23 | 0:e80c23aacae6 | 301 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 302 | wait_us(1); |
dheerajmpai23 | 0:e80c23aacae6 | 303 | } |
dheerajmpai23 | 0:e80c23aacae6 | 304 | |
dheerajmpai23 | 0:e80c23aacae6 | 305 | void Interrupt(){ |
dheerajmpai23 | 0:e80c23aacae6 | 306 | x = IRQ; |
dheerajmpai23 | 0:e80c23aacae6 | 307 | // intcount++; |
dheerajmpai23 | 0:e80c23aacae6 | 308 | if(x) |
dheerajmpai23 | 0:e80c23aacae6 | 309 | { |
dheerajmpai23 | 0:e80c23aacae6 | 310 | write_data(); |
dheerajmpai23 | 0:e80c23aacae6 | 311 | } |
dheerajmpai23 | 0:e80c23aacae6 | 312 | } |
dheerajmpai23 | 0:e80c23aacae6 | 313 | |
dheerajmpai23 | 0:e80c23aacae6 | 314 | |
dheerajmpai23 | 0:e80c23aacae6 | 315 | |
dheerajmpai23 | 0:e80c23aacae6 | 316 | |
dheerajmpai23 | 0:e80c23aacae6 | 317 | void send_data(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 318 | |
dheerajmpai23 | 0:e80c23aacae6 | 319 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 320 | adf.write(0xBB); |
dheerajmpai23 | 0:e80c23aacae6 | 321 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 322 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 323 | |
dheerajmpai23 | 0:e80c23aacae6 | 324 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 325 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 326 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 327 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 328 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 329 | |
dheerajmpai23 | 0:e80c23aacae6 | 330 | write_data(); |
dheerajmpai23 | 0:e80c23aacae6 | 331 | |
dheerajmpai23 | 0:e80c23aacae6 | 332 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 333 | adf.write(0xB1); |
dheerajmpai23 | 0:e80c23aacae6 | 334 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 335 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 336 | |
dheerajmpai23 | 0:e80c23aacae6 | 337 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 338 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 339 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 340 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 341 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 342 | |
dheerajmpai23 | 0:e80c23aacae6 | 343 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 344 | adf.write(0xB5); |
dheerajmpai23 | 0:e80c23aacae6 | 345 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 346 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 347 | |
dheerajmpai23 | 0:e80c23aacae6 | 348 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 349 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 350 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 351 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 352 | wait_ms(2); |
dheerajmpai23 | 0:e80c23aacae6 | 353 | } |
dheerajmpai23 | 0:e80c23aacae6 | 354 | /*******ADDITIONAL STUFF****************/ |
dheerajmpai23 | 0:e80c23aacae6 | 355 | unsigned char check_status(void){ |
dheerajmpai23 | 0:e80c23aacae6 | 356 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 357 | adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 358 | unsigned char stat = adf.write(0xFF); |
dheerajmpai23 | 0:e80c23aacae6 | 359 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 360 | return stat; |
dheerajmpai23 | 0:e80c23aacae6 | 361 | } |
dheerajmpai23 | 0:e80c23aacae6 | 362 | |
dheerajmpai23 | 0:e80c23aacae6 | 363 | unsigned char assrt_phy_off(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
dheerajmpai23 | 0:e80c23aacae6 | 364 | status=check_status(); |
dheerajmpai23 | 0:e80c23aacae6 | 365 | if(status==0xB1){ |
dheerajmpai23 | 0:e80c23aacae6 | 366 | return 0; |
dheerajmpai23 | 0:e80c23aacae6 | 367 | } |
dheerajmpai23 | 0:e80c23aacae6 | 368 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
dheerajmpai23 | 0:e80c23aacae6 | 369 | return 1;//You need to Reset the hardware |
dheerajmpai23 | 0:e80c23aacae6 | 370 | } |
dheerajmpai23 | 0:e80c23aacae6 | 371 | else if(state_err_cnt>STATE_ERR_THRS){ |
dheerajmpai23 | 0:e80c23aacae6 | 372 | return 1;//Again reset the hardware |
dheerajmpai23 | 0:e80c23aacae6 | 373 | } |
dheerajmpai23 | 0:e80c23aacae6 | 374 | else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
dheerajmpai23 | 0:e80c23aacae6 | 375 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 376 | adf.write(0xB0); //CMD_PHY_OFF |
dheerajmpai23 | 0:e80c23aacae6 | 377 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 378 | wait_us(PHY_OFF_EXEC_TIME);// Typical = 24us We are giving 300us |
dheerajmpai23 | 0:e80c23aacae6 | 379 | return assrt_phy_off(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
dheerajmpai23 | 0:e80c23aacae6 | 380 | } |
dheerajmpai23 | 0:e80c23aacae6 | 381 | else if(status&0x80==0x00){ |
dheerajmpai23 | 0:e80c23aacae6 | 382 | wait_ms(5); |
dheerajmpai23 | 0:e80c23aacae6 | 383 | //Error: SPI=0 Not ready CMD= Dont care |
dheerajmpai23 | 0:e80c23aacae6 | 384 | return assrt_phy_off(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
dheerajmpai23 | 0:e80c23aacae6 | 385 | } |
dheerajmpai23 | 0:e80c23aacae6 | 386 | else {//if(status&0xA0==0x80){ |
dheerajmpai23 | 0:e80c23aacae6 | 387 | wait_ms(1); |
dheerajmpai23 | 0:e80c23aacae6 | 388 | //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
dheerajmpai23 | 0:e80c23aacae6 | 389 | return assrt_phy_off(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
dheerajmpai23 | 0:e80c23aacae6 | 390 | } |
dheerajmpai23 | 0:e80c23aacae6 | 391 | } |
dheerajmpai23 | 1:434b2062426b | 392 | /*****************************/ |
dheerajmpai23 | 1:434b2062426b | 393 | unsigned char assrt_phy_on(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
dheerajmpai23 | 1:434b2062426b | 394 | status=check_status(); |
dheerajmpai23 | 1:434b2062426b | 395 | if(status==0xB2){ |
dheerajmpai23 | 1:434b2062426b | 396 | return 0; |
dheerajmpai23 | 1:434b2062426b | 397 | } |
dheerajmpai23 | 1:434b2062426b | 398 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
dheerajmpai23 | 1:434b2062426b | 399 | return 1;//You need to Reset the hardware |
dheerajmpai23 | 1:434b2062426b | 400 | } |
dheerajmpai23 | 1:434b2062426b | 401 | else if(state_err_cnt>STATE_ERR_THRS){ |
dheerajmpai23 | 1:434b2062426b | 402 | return 1;//Again reset the hardware |
dheerajmpai23 | 1:434b2062426b | 403 | } |
dheerajmpai23 | 1:434b2062426b | 404 | else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
dheerajmpai23 | 1:434b2062426b | 405 | CS=0; |
dheerajmpai23 | 1:434b2062426b | 406 | adf.write(0xB1); //CMD_PHY_OFF |
dheerajmpai23 | 1:434b2062426b | 407 | CS=1; |
dheerajmpai23 | 1:434b2062426b | 408 | wait_us(PHY_ON_EXEC_TIME);// Typical = 24us We are giving 300us |
dheerajmpai23 | 1:434b2062426b | 409 | return assrt_phy_on(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
dheerajmpai23 | 1:434b2062426b | 410 | } |
dheerajmpai23 | 1:434b2062426b | 411 | else if(status&0x80==0x00){ |
dheerajmpai23 | 1:434b2062426b | 412 | wait_ms(5); |
dheerajmpai23 | 1:434b2062426b | 413 | //Error: SPI=0 Not ready CMD= Dont care |
dheerajmpai23 | 1:434b2062426b | 414 | return assrt_phy_on(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
dheerajmpai23 | 1:434b2062426b | 415 | } |
dheerajmpai23 | 1:434b2062426b | 416 | else if(status&0xA0==0x80){ |
dheerajmpai23 | 1:434b2062426b | 417 | wait_ms(1); |
dheerajmpai23 | 1:434b2062426b | 418 | //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
dheerajmpai23 | 1:434b2062426b | 419 | return assrt_phy_on(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
dheerajmpai23 | 1:434b2062426b | 420 | } |
dheerajmpai23 | 1:434b2062426b | 421 | } |
dheerajmpai23 | 1:434b2062426b | 422 | /*****************************/ |
dheerajmpai23 | 1:434b2062426b | 423 | unsigned char assrt_phy_tx(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
dheerajmpai23 | 1:434b2062426b | 424 | status=check_status(); |
dheerajmpai23 | 1:434b2062426b | 425 | if((status & 0x1F) == 0xB4){ |
dheerajmpai23 | 1:434b2062426b | 426 | return 0; |
dheerajmpai23 | 1:434b2062426b | 427 | } |
dheerajmpai23 | 1:434b2062426b | 428 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
dheerajmpai23 | 1:434b2062426b | 429 | return 1;//You need to Reset the hardware |
dheerajmpai23 | 1:434b2062426b | 430 | } |
dheerajmpai23 | 1:434b2062426b | 431 | else if(state_err_cnt>STATE_ERR_THRS){ |
dheerajmpai23 | 1:434b2062426b | 432 | return 1;//Again reset the hardware |
dheerajmpai23 | 1:434b2062426b | 433 | } |
dheerajmpai23 | 1:434b2062426b | 434 | else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
dheerajmpai23 | 1:434b2062426b | 435 | CS=0; |
dheerajmpai23 | 1:434b2062426b | 436 | adf.write(0xB1); //CMD_PHY_OFF |
dheerajmpai23 | 1:434b2062426b | 437 | CS=1; |
dheerajmpai23 | 1:434b2062426b | 438 | wait_us(PHY_TX_EXEC_TIME);// Typical = 24us We are giving 300us |
dheerajmpai23 | 1:434b2062426b | 439 | return assrt_phy_tx(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
dheerajmpai23 | 1:434b2062426b | 440 | } |
dheerajmpai23 | 1:434b2062426b | 441 | else if(status&0x80==0x00){ |
dheerajmpai23 | 1:434b2062426b | 442 | wait_ms(1); |
dheerajmpai23 | 1:434b2062426b | 443 | //Error: SPI=0 Not ready CMD= Dont care |
dheerajmpai23 | 1:434b2062426b | 444 | return assrt_phy_tx(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
dheerajmpai23 | 1:434b2062426b | 445 | } |
dheerajmpai23 | 1:434b2062426b | 446 | else if(status&0xA0==0x80){ |
dheerajmpai23 | 1:434b2062426b | 447 | wait_us(50); |
dheerajmpai23 | 1:434b2062426b | 448 | //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
dheerajmpai23 | 1:434b2062426b | 449 | return assrt_phy_tx(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
dheerajmpai23 | 1:434b2062426b | 450 | } |
dheerajmpai23 | 1:434b2062426b | 451 | } |
dheerajmpai23 | 1:434b2062426b | 452 | |
dheerajmpai23 | 0:e80c23aacae6 | 453 | /***************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 454 | bool hardware_reset(int bcn_call){ |
dheerajmpai23 | 0:e80c23aacae6 | 455 | if (bcn_call>20){ |
dheerajmpai23 | 0:e80c23aacae6 | 456 | return 1; |
dheerajmpai23 | 0:e80c23aacae6 | 457 | } |
dheerajmpai23 | 0:e80c23aacae6 | 458 | int count=0; |
dheerajmpai23 | 0:e80c23aacae6 | 459 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 460 | adf.write(CMD_HW_RESET); |
dheerajmpai23 | 0:e80c23aacae6 | 461 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 462 | wait_us(2);// Typically 1 us |
dheerajmpai23 | 0:e80c23aacae6 | 463 | while(count<1000){ |
dheerajmpai23 | 0:e80c23aacae6 | 464 | if(MISO_PIN){ |
dheerajmpai23 | 0:e80c23aacae6 | 465 | |
dheerajmpai23 | 0:e80c23aacae6 | 466 | if(!assrt_phy_off(0,0,0)){ |
dheerajmpai23 | 0:e80c23aacae6 | 467 | break; |
dheerajmpai23 | 0:e80c23aacae6 | 468 | } |
dheerajmpai23 | 0:e80c23aacae6 | 469 | count++; |
dheerajmpai23 | 0:e80c23aacae6 | 470 | } |
dheerajmpai23 | 0:e80c23aacae6 | 471 | } |
dheerajmpai23 | 0:e80c23aacae6 | 472 | if(count==10){ |
dheerajmpai23 | 0:e80c23aacae6 | 473 | return hardware_reset(bcn_call+1); |
dheerajmpai23 | 0:e80c23aacae6 | 474 | } |
dheerajmpai23 | 0:e80c23aacae6 | 475 | else |
dheerajmpai23 | 0:e80c23aacae6 | 476 | return 0; |
dheerajmpai23 | 0:e80c23aacae6 | 477 | |
dheerajmpai23 | 0:e80c23aacae6 | 478 | } |
dheerajmpai23 | 0:e80c23aacae6 | 479 | |
dheerajmpai23 | 0:e80c23aacae6 | 480 | |
dheerajmpai23 | 0:e80c23aacae6 | 481 | /*******************************************/ |
dheerajmpai23 | 0:e80c23aacae6 | 482 | int main() |
dheerajmpai23 | 0:e80c23aacae6 | 483 | { |
dheerajmpai23 | 0:e80c23aacae6 | 484 | adf.format(8,0); |
dheerajmpai23 | 0:e80c23aacae6 | 485 | adf.frequency(1000000); |
dheerajmpai23 | 0:e80c23aacae6 | 486 | /**ADDED On 21/10/2015 ***/ |
dheerajmpai23 | 0:e80c23aacae6 | 487 | /******************/ |
dheerajmpai23 | 0:e80c23aacae6 | 488 | /***********/ |
dheerajmpai23 | 0:e80c23aacae6 | 489 | bool state_0=0; |
dheerajmpai23 | 0:e80c23aacae6 | 490 | state_0=assrt_phy_off(0,0,0); |
dheerajmpai23 | 0:e80c23aacae6 | 491 | while(1){ |
dheerajmpai23 | 0:e80c23aacae6 | 492 | if(!state_0){ |
dheerajmpai23 | 0:e80c23aacae6 | 493 | bbram_write(); |
dheerajmpai23 | 0:e80c23aacae6 | 494 | break; |
dheerajmpai23 | 0:e80c23aacae6 | 495 | } |
dheerajmpai23 | 0:e80c23aacae6 | 496 | else{ |
dheerajmpai23 | 0:e80c23aacae6 | 497 | hardware_reset(0); |
dheerajmpai23 | 0:e80c23aacae6 | 498 | } |
dheerajmpai23 | 0:e80c23aacae6 | 499 | } |
dheerajmpai23 | 0:e80c23aacae6 | 500 | 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 | 501 | |
dheerajmpai23 | 0:e80c23aacae6 | 502 | initiate(); |
dheerajmpai23 | 0:e80c23aacae6 | 503 | send_data(); |
dheerajmpai23 | 0:e80c23aacae6 | 504 | cout<<"Work"<<ENDL; |
dheerajmpai23 | 0:e80c23aacae6 | 505 | CS=0; |
dheerajmpai23 | 0:e80c23aacae6 | 506 | adf.write(0x0B);//IRQ_SOURCE_Random write //To read CMD = 2B 36 FF FF |
dheerajmpai23 | 0:e80c23aacae6 | 507 | adf.write(0x36);//Address : 0x336 |
dheerajmpai23 | 0:e80c23aacae6 | 508 | adf.write(0xFF);//Put Low Clearing the MCR Value of the Source Register |
dheerajmpai23 | 0:e80c23aacae6 | 509 | CS=1; |
dheerajmpai23 | 0:e80c23aacae6 | 510 | |
dheerajmpai23 | 0:e80c23aacae6 | 511 | ticker.attach_us(&Interrupt,32000); |
dheerajmpai23 | 0:e80c23aacae6 | 512 | |
dheerajmpai23 | 0:e80c23aacae6 | 513 | } |