Dheeraj M Pai
/
XXX_INTEGRATE_WITH_KIRUBHA_CODE
ADF7023
main.cpp@2:24459bb3d5cf, 2015-06-27 (annotated)
- Committer:
- dheerajmpai23
- Date:
- Sat Jun 27 03:53:25 2015 +0000
- Revision:
- 2:24459bb3d5cf
- Parent:
- 1:0a1e3fd2d4e3
- Child:
- 3:dd63376a1030
WORKING CODE UNEDITED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dheerajmpai23 | 0:f8a9fca7e008 | 1 | #include "mbed.h" |
dheerajmpai23 | 0:f8a9fca7e008 | 2 | #include <iostream> |
dheerajmpai23 | 0:f8a9fca7e008 | 3 | using namespace std; |
dheerajmpai23 | 0:f8a9fca7e008 | 4 | #include <bitset> |
dheerajmpai23 | 0:f8a9fca7e008 | 5 | |
dheerajmpai23 | 0:f8a9fca7e008 | 6 | #define ENDL "\r" << endl; |
dheerajmpai23 | 0:f8a9fca7e008 | 7 | #define START_ADDRESS 0x020; |
dheerajmpai23 | 0:f8a9fca7e008 | 8 | |
dheerajmpai23 | 0:f8a9fca7e008 | 9 | |
dheerajmpai23 | 0:f8a9fca7e008 | 10 | |
dheerajmpai23 | 0:f8a9fca7e008 | 11 | //SPI |
dheerajmpai23 | 0:f8a9fca7e008 | 12 | |
dheerajmpai23 | 0:f8a9fca7e008 | 13 | SPI adf(PTD6, PTD7, PTD5); |
dheerajmpai23 | 0:f8a9fca7e008 | 14 | //MOSI, MISO, CLOCK |
dheerajmpai23 | 0:f8a9fca7e008 | 15 | |
dheerajmpai23 | 0:f8a9fca7e008 | 16 | DigitalOut CS(D10); |
dheerajmpai23 | 0:f8a9fca7e008 | 17 | Serial PC(USBTX, USBRX); |
dheerajmpai23 | 0:f8a9fca7e008 | 18 | DigitalOut ledr(LED_RED); |
dheerajmpai23 | 0:f8a9fca7e008 | 19 | |
dheerajmpai23 | 0:f8a9fca7e008 | 20 | DigitalIn clk(D8); |
dheerajmpai23 | 0:f8a9fca7e008 | 21 | DigitalOut DT(D9); |
dheerajmpai23 | 0:f8a9fca7e008 | 22 | int j=0; |
dheerajmpai23 | 2:24459bb3d5cf | 23 | int bitcount=1; |
dheerajmpai23 | 2:24459bb3d5cf | 24 | int times=0; |
dheerajmpai23 | 2:24459bb3d5cf | 25 | int bites=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 26 | |
dheerajmpai23 | 0:f8a9fca7e008 | 27 | #define SPI_NOP 0xFF |
dheerajmpai23 | 0:f8a9fca7e008 | 28 | |
dheerajmpai23 | 0:f8a9fca7e008 | 29 | enum con_type{ packet=0x18, bbram=0x19, mcr=0x1B, program=0x1E }; |
dheerajmpai23 | 0:f8a9fca7e008 | 30 | enum discon_type{ packet2=0x08, bbram2=0x09, mcr2=0x0B }; |
dheerajmpai23 | 0:f8a9fca7e008 | 31 | |
dheerajmpai23 | 0:f8a9fca7e008 | 32 | enum discon_type_RD{ packet3=0x28, bbram3=0x29, mcr3=0x2B }; |
dheerajmpai23 | 0:f8a9fca7e008 | 33 | |
dheerajmpai23 | 0:f8a9fca7e008 | 34 | unsigned char data_TX [] = {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,0xEB,0x3D,0x35,0x66,0xDC,0xDA,0x33,0xA1,0x80,0x62,0xB7,0xB8,0x88,0x8A,0xCE,0x99,0x18,0xFA,0x24,0x42,0xD1,0x7C,0x2D,0x0E,0x72,0x9E,0xE9,0x7C,0xF9,0xBA,0x18,0xAA,0x4B,0xEC,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0xCC,0xB3,0xB2,0x5B,0x96,0x38,0x71,0x96,0x54,0xE2,0x4A,0x7F,0xC9,0xB7,0x1E,0x56,0x09,0x30,0x18,0x5A,0x84,0xFA,0xC1,0x9D,0xA6,0x6A,0x17,0x50,0x6F,0xD4,0x34,0x1D,0xF0,0xE0,0xE2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x78,0xC9,0x9A,0x09,0xE2,0x34,0xF9,0x39,0x61,0x36,0x9C,0xC2,0x98,0xB9,0x54,0xC0,0xDC,0xE6,0x90,0xF6,0xF6,0x88,0xD1,0xA5,0x5A,0x75,0x83,0x78,0x08,0xD6,0x9D,0xDE,0xB8,0x58,0xD4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x13,0x3F,0x78,0xD9,0x4E,0xB7,0xE8,0xD6,0x0D,0x1E,0xF1,0xC4,0xB9,0xAB,0x90,0x39,0x6A,0x9E,0x8A,0xB8,0xC9,0xAF,0x5E,0x85,0x66,0xBF,0x4E,0xB3,0xD3,0x54,0x9B,0x7D,0xA3,0x3A,0x1A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x81,0x83,0x7B,0x88,0x8A,0xAB,0x31,0x91,0x8F,0xA0,0x91,0x05,0x17,0xC2,0xD2,0xB9,0xC1,0xEE,0x97,0xCE,0x66,0xE9,0x8A,0xA4,0xBC,0xB1,0xFC,0xCB,0x3B,0x24,0x6E,0x5B,0x87,0x19,0x64,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:f8a9fca7e008 | 35 | |
dheerajmpai23 | 0:f8a9fca7e008 | 36 | |
dheerajmpai23 | 0:f8a9fca7e008 | 37 | void send_data() |
dheerajmpai23 | 0:f8a9fca7e008 | 38 | { |
dheerajmpai23 | 0:f8a9fca7e008 | 39 | |
dheerajmpai23 | 0:f8a9fca7e008 | 40 | // static int current_byte = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 41 | static int current_bit = 7; |
dheerajmpai23 | 0:f8a9fca7e008 | 42 | |
dheerajmpai23 | 0:f8a9fca7e008 | 43 | DT = (data_TX[j] >> current_bit) & 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 44 | --current_bit; |
dheerajmpai23 | 0:f8a9fca7e008 | 45 | |
dheerajmpai23 | 0:f8a9fca7e008 | 46 | if(current_bit == -1){ |
dheerajmpai23 | 0:f8a9fca7e008 | 47 | current_bit = 7; |
dheerajmpai23 | 0:f8a9fca7e008 | 48 | j++; |
dheerajmpai23 | 2:24459bb3d5cf | 49 | bitcount=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 50 | cout<<"SENDING"<<ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 51 | if(j>=sizeof(data_TX)) |
dheerajmpai23 | 0:f8a9fca7e008 | 52 | { |
dheerajmpai23 | 0:f8a9fca7e008 | 53 | j=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 54 | |
dheerajmpai23 | 0:f8a9fca7e008 | 55 | |
dheerajmpai23 | 0:f8a9fca7e008 | 56 | // while(true); |
dheerajmpai23 | 0:f8a9fca7e008 | 57 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 58 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 59 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 60 | |
dheerajmpai23 | 0:f8a9fca7e008 | 61 | |
dheerajmpai23 | 0:f8a9fca7e008 | 62 | void write_con(con_type ram, uint8_t address, uint8_t *data, int length){ |
dheerajmpai23 | 0:f8a9fca7e008 | 63 | |
dheerajmpai23 | 0:f8a9fca7e008 | 64 | int *response = new int[length]; |
dheerajmpai23 | 0:f8a9fca7e008 | 65 | |
dheerajmpai23 | 0:f8a9fca7e008 | 66 | |
dheerajmpai23 | 0:f8a9fca7e008 | 67 | |
dheerajmpai23 | 0:f8a9fca7e008 | 68 | |
dheerajmpai23 | 0:f8a9fca7e008 | 69 | |
dheerajmpai23 | 0:f8a9fca7e008 | 70 | CS = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 71 | |
dheerajmpai23 | 0:f8a9fca7e008 | 72 | // ignore recevived data |
dheerajmpai23 | 0:f8a9fca7e008 | 73 | adf.write( ram ); |
dheerajmpai23 | 0:f8a9fca7e008 | 74 | |
dheerajmpai23 | 0:f8a9fca7e008 | 75 | // write start address |
dheerajmpai23 | 0:f8a9fca7e008 | 76 | int r = adf.write( address ); |
dheerajmpai23 | 0:f8a9fca7e008 | 77 | |
dheerajmpai23 | 0:f8a9fca7e008 | 78 | // write data |
dheerajmpai23 | 0:f8a9fca7e008 | 79 | for(int i = 0 ; i < length ; ++i){ |
dheerajmpai23 | 0:f8a9fca7e008 | 80 | response[i] = adf.write( data[i] ); |
dheerajmpai23 | 0:f8a9fca7e008 | 81 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 82 | |
dheerajmpai23 | 0:f8a9fca7e008 | 83 | CS = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 84 | |
dheerajmpai23 | 0:f8a9fca7e008 | 85 | cout << r << ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 86 | for(int i = 0 ; i < length ; ++i){ |
dheerajmpai23 | 0:f8a9fca7e008 | 87 | cout << response[i] << " "; |
dheerajmpai23 | 0:f8a9fca7e008 | 88 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 89 | cout << ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 90 | |
dheerajmpai23 | 0:f8a9fca7e008 | 91 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 92 | |
dheerajmpai23 | 0:f8a9fca7e008 | 93 | void write_discon(discon_type ram, uint8_t *address, uint8_t *data, int length){ |
dheerajmpai23 | 0:f8a9fca7e008 | 94 | |
dheerajmpai23 | 0:f8a9fca7e008 | 95 | int *response1 = new int[length]; |
dheerajmpai23 | 0:f8a9fca7e008 | 96 | int *response2 = new int[length]; |
dheerajmpai23 | 0:f8a9fca7e008 | 97 | |
dheerajmpai23 | 0:f8a9fca7e008 | 98 | CS = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 99 | |
dheerajmpai23 | 0:f8a9fca7e008 | 100 | // ignore recevived data |
dheerajmpai23 | 0:f8a9fca7e008 | 101 | adf.write( ram ); |
dheerajmpai23 | 0:f8a9fca7e008 | 102 | |
dheerajmpai23 | 0:f8a9fca7e008 | 103 | for(int i = 0 ; i < length ; ++i){ |
dheerajmpai23 | 0:f8a9fca7e008 | 104 | |
dheerajmpai23 | 0:f8a9fca7e008 | 105 | // address[7:0] next 8 bits |
dheerajmpai23 | 0:f8a9fca7e008 | 106 | response1[i] = adf.write( address[i] ); |
dheerajmpai23 | 0:f8a9fca7e008 | 107 | |
dheerajmpai23 | 0:f8a9fca7e008 | 108 | // data next 8 bits |
dheerajmpai23 | 0:f8a9fca7e008 | 109 | response2[i] = adf.write( data[i] ); |
dheerajmpai23 | 0:f8a9fca7e008 | 110 | |
dheerajmpai23 | 0:f8a9fca7e008 | 111 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 112 | |
dheerajmpai23 | 0:f8a9fca7e008 | 113 | CS = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 114 | |
dheerajmpai23 | 0:f8a9fca7e008 | 115 | for(int i = 0 ; i < length ; ++i){ |
dheerajmpai23 | 0:f8a9fca7e008 | 116 | cout << response1[i] << "\t" << response2[i] << ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 117 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 118 | |
dheerajmpai23 | 0:f8a9fca7e008 | 119 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 120 | |
dheerajmpai23 | 0:f8a9fca7e008 | 121 | int read_discon(discon_type_RD ram, uint8_t address){ |
dheerajmpai23 | 0:f8a9fca7e008 | 122 | |
dheerajmpai23 | 0:f8a9fca7e008 | 123 | CS = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 124 | |
dheerajmpai23 | 0:f8a9fca7e008 | 125 | // ignore the reply |
dheerajmpai23 | 0:f8a9fca7e008 | 126 | adf.write( ram ); |
dheerajmpai23 | 0:f8a9fca7e008 | 127 | |
dheerajmpai23 | 0:f8a9fca7e008 | 128 | int stat1 = adf.write( address ); |
dheerajmpai23 | 0:f8a9fca7e008 | 129 | int stat2 = adf.write( SPI_NOP ); |
dheerajmpai23 | 0:f8a9fca7e008 | 130 | int reply = adf.write( SPI_NOP ); |
dheerajmpai23 | 0:f8a9fca7e008 | 131 | |
dheerajmpai23 | 0:f8a9fca7e008 | 132 | CS = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 133 | |
dheerajmpai23 | 0:f8a9fca7e008 | 134 | return reply; |
dheerajmpai23 | 0:f8a9fca7e008 | 135 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 136 | |
dheerajmpai23 | 0:f8a9fca7e008 | 137 | void write_bbram_sequence(void){ |
dheerajmpai23 | 0:f8a9fca7e008 | 138 | |
dheerajmpai23 | 0:f8a9fca7e008 | 139 | adf.write(0x19); |
dheerajmpai23 | 0:f8a9fca7e008 | 140 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 141 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 142 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 143 | |
dheerajmpai23 | 0:f8a9fca7e008 | 144 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 145 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 146 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 147 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 148 | |
dheerajmpai23 | 0:f8a9fca7e008 | 149 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 150 | adf.write(0x33); |
dheerajmpai23 | 0:f8a9fca7e008 | 151 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 152 | adf.write(0xF9); |
dheerajmpai23 | 0:f8a9fca7e008 | 153 | |
dheerajmpai23 | 0:f8a9fca7e008 | 154 | adf.write(0xC2); |
dheerajmpai23 | 0:f8a9fca7e008 | 155 | adf.write(0x10); |
dheerajmpai23 | 0:f8a9fca7e008 | 156 | adf.write(0xC0); |
dheerajmpai23 | 0:f8a9fca7e008 | 157 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 158 | |
dheerajmpai23 | 0:f8a9fca7e008 | 159 | adf.write(0x30); |
dheerajmpai23 | 0:f8a9fca7e008 | 160 | adf.write(0x31); |
dheerajmpai23 | 0:f8a9fca7e008 | 161 | adf.write(0x07); |
dheerajmpai23 | 0:f8a9fca7e008 | 162 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 163 | |
dheerajmpai23 | 0:f8a9fca7e008 | 164 | adf.write(0x01); |
dheerajmpai23 | 0:f8a9fca7e008 | 165 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 166 | adf.write(0x7F); |
dheerajmpai23 | 0:f8a9fca7e008 | 167 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 168 | |
dheerajmpai23 | 0:f8a9fca7e008 | 169 | adf.write(0x0B); |
dheerajmpai23 | 0:f8a9fca7e008 | 170 | adf.write(0x37); |
dheerajmpai23 | 0:f8a9fca7e008 | 171 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 172 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 173 | adf.write(0x40); |
dheerajmpai23 | 0:f8a9fca7e008 | 174 | adf.write(0x0C); |
dheerajmpai23 | 0:f8a9fca7e008 | 175 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 176 | adf.write(0x05); |
dheerajmpai23 | 0:f8a9fca7e008 | 177 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 178 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 179 | adf.write(0x18); |
dheerajmpai23 | 0:f8a9fca7e008 | 180 | adf.write(0x12); |
dheerajmpai23 | 0:f8a9fca7e008 | 181 | adf.write(0x34); |
dheerajmpai23 | 0:f8a9fca7e008 | 182 | adf.write(0x56); |
dheerajmpai23 | 0:f8a9fca7e008 | 183 | adf.write(0x10); |
dheerajmpai23 | 0:f8a9fca7e008 | 184 | adf.write(0x10); |
dheerajmpai23 | 0:f8a9fca7e008 | 185 | adf.write(0x08); |
dheerajmpai23 | 0:f8a9fca7e008 | 186 | adf.write(0x14); |
dheerajmpai23 | 0:f8a9fca7e008 | 187 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 188 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 189 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 190 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 191 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 192 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 193 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 194 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 195 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 196 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 197 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 198 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 199 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 200 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 201 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 202 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 203 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 204 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 205 | adf.write(0x04); |
dheerajmpai23 | 0:f8a9fca7e008 | 206 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 207 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 208 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 209 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 210 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 211 | |
dheerajmpai23 | 0:f8a9fca7e008 | 212 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 213 | |
dheerajmpai23 | 0:f8a9fca7e008 | 214 | void initiate(void){ |
dheerajmpai23 | 0:f8a9fca7e008 | 215 | |
dheerajmpai23 | 0:f8a9fca7e008 | 216 | // CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 217 | // adf.write(0xB0); |
dheerajmpai23 | 0:f8a9fca7e008 | 218 | // CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 219 | // wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 220 | |
dheerajmpai23 | 0:f8a9fca7e008 | 221 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 222 | adf.write(0x1B); |
dheerajmpai23 | 0:f8a9fca7e008 | 223 | adf.write(0xFA); |
dheerajmpai23 | 0:f8a9fca7e008 | 224 | adf.write(0xA0); |
dheerajmpai23 | 0:f8a9fca7e008 | 225 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 226 | wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 227 | |
dheerajmpai23 | 0:f8a9fca7e008 | 228 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 229 | adf.write(0x18); |
dheerajmpai23 | 0:f8a9fca7e008 | 230 | adf.write(0x0D); |
dheerajmpai23 | 0:f8a9fca7e008 | 231 | adf.write(0x00); |
dheerajmpai23 | 0:f8a9fca7e008 | 232 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 233 | wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 234 | |
dheerajmpai23 | 0:f8a9fca7e008 | 235 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 236 | adf.write(0xB0); |
dheerajmpai23 | 0:f8a9fca7e008 | 237 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 238 | wait_ms(3); |
dheerajmpai23 | 0:f8a9fca7e008 | 239 | |
dheerajmpai23 | 0:f8a9fca7e008 | 240 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 241 | adf.write(0xB0); |
dheerajmpai23 | 0:f8a9fca7e008 | 242 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 243 | wait_ms(3); |
dheerajmpai23 | 0:f8a9fca7e008 | 244 | |
dheerajmpai23 | 0:f8a9fca7e008 | 245 | |
dheerajmpai23 | 0:f8a9fca7e008 | 246 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 247 | write_bbram_sequence(); |
dheerajmpai23 | 0:f8a9fca7e008 | 248 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 249 | wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 250 | |
dheerajmpai23 | 0:f8a9fca7e008 | 251 | cout<<"BBRAM_SEQUENCE WRITTEN"<<ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 252 | |
dheerajmpai23 | 0:f8a9fca7e008 | 253 | |
dheerajmpai23 | 0:f8a9fca7e008 | 254 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 255 | adf.write(0xFF); |
dheerajmpai23 | 0:f8a9fca7e008 | 256 | adf.write(0xFF); |
dheerajmpai23 | 0:f8a9fca7e008 | 257 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 258 | wait_ms(1); |
dheerajmpai23 | 0:f8a9fca7e008 | 259 | |
dheerajmpai23 | 0:f8a9fca7e008 | 260 | |
dheerajmpai23 | 0:f8a9fca7e008 | 261 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 262 | adf.write(0xFF); |
dheerajmpai23 | 0:f8a9fca7e008 | 263 | adf.write(0xFF); |
dheerajmpai23 | 0:f8a9fca7e008 | 264 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 265 | wait_ms(1); |
dheerajmpai23 | 0:f8a9fca7e008 | 266 | |
dheerajmpai23 | 0:f8a9fca7e008 | 267 | |
dheerajmpai23 | 0:f8a9fca7e008 | 268 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 269 | adf.write(0xBB);//CONFIGURE_DEV |
dheerajmpai23 | 0:f8a9fca7e008 | 270 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 271 | wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 272 | |
dheerajmpai23 | 0:f8a9fca7e008 | 273 | cout<<"CONFIG_DEV"<<ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 274 | |
dheerajmpai23 | 0:f8a9fca7e008 | 275 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 276 | adf.write(0xB1);//PHY_ON |
dheerajmpai23 | 0:f8a9fca7e008 | 277 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 278 | wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 279 | |
dheerajmpai23 | 0:f8a9fca7e008 | 280 | CS=0; |
dheerajmpai23 | 0:f8a9fca7e008 | 281 | adf.write(0xB5);//PHY_TX |
dheerajmpai23 | 0:f8a9fca7e008 | 282 | CS=1; |
dheerajmpai23 | 0:f8a9fca7e008 | 283 | wait_ms(2); |
dheerajmpai23 | 0:f8a9fca7e008 | 284 | |
dheerajmpai23 | 0:f8a9fca7e008 | 285 | cout<<"PHY_TX"<<ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 286 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 287 | |
dheerajmpai23 | 0:f8a9fca7e008 | 288 | |
dheerajmpai23 | 0:f8a9fca7e008 | 289 | |
dheerajmpai23 | 0:f8a9fca7e008 | 290 | |
dheerajmpai23 | 0:f8a9fca7e008 | 291 | int main(){ |
dheerajmpai23 | 0:f8a9fca7e008 | 292 | |
dheerajmpai23 | 0:f8a9fca7e008 | 293 | |
dheerajmpai23 | 0:f8a9fca7e008 | 294 | CS = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 295 | adf.format(8,0); |
dheerajmpai23 | 0:f8a9fca7e008 | 296 | adf.frequency( 1000000 ); |
dheerajmpai23 | 0:f8a9fca7e008 | 297 | |
dheerajmpai23 | 0:f8a9fca7e008 | 298 | cout << "Press s" << ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 299 | ledr = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 300 | char c = 'a'; |
dheerajmpai23 | 0:f8a9fca7e008 | 301 | while( c != 's'){ |
dheerajmpai23 | 0:f8a9fca7e008 | 302 | c = PC.getc(); |
dheerajmpai23 | 0:f8a9fca7e008 | 303 | PC.putc(c); |
dheerajmpai23 | 0:f8a9fca7e008 | 304 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 305 | ledr = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 306 | |
dheerajmpai23 | 0:f8a9fca7e008 | 307 | initiate(); |
dheerajmpai23 | 0:f8a9fca7e008 | 308 | cout << "initiated" << ENDL; |
dheerajmpai23 | 0:f8a9fca7e008 | 309 | int state; |
dheerajmpai23 | 0:f8a9fca7e008 | 310 | if(clk == 0){ |
dheerajmpai23 | 0:f8a9fca7e008 | 311 | state = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 312 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 313 | else{ |
dheerajmpai23 | 0:f8a9fca7e008 | 314 | state = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 315 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 316 | |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 317 | int l=0; |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 318 | while(l<=1000){ |
dheerajmpai23 | 0:f8a9fca7e008 | 319 | cout << "in while" << ENDL; |
dheerajmpai23 | 2:24459bb3d5cf | 320 | cout<<bitcount<<ENDL; |
dheerajmpai23 | 2:24459bb3d5cf | 321 | bitcount++; |
dheerajmpai23 | 0:f8a9fca7e008 | 322 | |
dheerajmpai23 | 0:f8a9fca7e008 | 323 | if(clk == 0){ |
dheerajmpai23 | 0:f8a9fca7e008 | 324 | if(state == 1){ |
dheerajmpai23 | 0:f8a9fca7e008 | 325 | state = 0; |
dheerajmpai23 | 0:f8a9fca7e008 | 326 | send_data(); |
dheerajmpai23 | 0:f8a9fca7e008 | 327 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 328 | } |
dheerajmpai23 | 0:f8a9fca7e008 | 329 | else{ |
dheerajmpai23 | 0:f8a9fca7e008 | 330 | state = 1; |
dheerajmpai23 | 0:f8a9fca7e008 | 331 | } |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 332 | l++; |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 333 | } |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 334 | |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 335 | |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 336 | CS=0; |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 337 | adf.write(0xB1); |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 338 | CS=1; |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 339 | wait(1); |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 340 | cout<<"Transmission should have stopped by now "<<ENDL; |
dheerajmpai23 | 1:0a1e3fd2d4e3 | 341 | } |