![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Repo for beacon testing
main.cpp@6:f0fb224c958b, 2015-10-04 (annotated)
- Committer:
- shekhar
- Date:
- Sun Oct 04 10:35:31 2015 +0000
- Revision:
- 6:f0fb224c958b
- Parent:
- 5:3d447f4786f1
Changes made : Manchester coding disabled, freq_dev removed, power raised, ready mode not directly set before TXON since it is automatically initialised in POR, ; Doubts : Do we need SDN mode, should wut be ON for temp sensor, TX length for >255
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shekhar | 0:15b2487c185c | 1 | #include "beacon.h" |
shekhar | 0:15b2487c185c | 2 | Serial pc(USBTX, USBRX); // tx, rx |
shekhar | 0:15b2487c185c | 3 | SPI spi(D11, D12, D13); // mosi, miso, sclk |
shekhar | 0:15b2487c185c | 4 | //SPI spi(PTA16, PTA17, PTA15); // mosi, miso, sclk |
shekhar | 0:15b2487c185c | 5 | DigitalOut cs(D10); //slave select or chip select |
shekhar | 0:15b2487c185c | 6 | |
shekhar | 0:15b2487c185c | 7 | void writereg(uint8_t reg,uint8_t val) |
shekhar | 0:15b2487c185c | 8 | { |
shekhar | 6:f0fb224c958b | 9 | int ret_val;cs = 0;spi.write(reg | 0x80);ret_val = spi.write(val);cs = 1; if(ret_val != val) pc.printf("unable to write through spi ... writereg() not working \n"); |
shekhar | 0:15b2487c185c | 10 | } |
shekhar | 0:15b2487c185c | 11 | uint8_t readreg(uint8_t reg) |
shekhar | 0:15b2487c185c | 12 | { |
shekhar | 5:3d447f4786f1 | 13 | int val;cs = 0;spi.write(reg & ~0x80);val = spi.write(0);cs = 1;return val; |
shekhar | 0:15b2487c185c | 14 | } |
shekhar | 0:15b2487c185c | 15 | void clearTxBuf() |
shekhar | 0:15b2487c185c | 16 | { |
shekhar | 0:15b2487c185c | 17 | writereg(RF22_REG_08_OPERATING_MODE2,0x01); |
shekhar | 0:15b2487c185c | 18 | writereg(RF22_REG_08_OPERATING_MODE2,0x00); |
shekhar | 0:15b2487c185c | 19 | } |
shekhar | 0:15b2487c185c | 20 | void clearRxBuf() |
shekhar | 0:15b2487c185c | 21 | { |
shekhar | 0:15b2487c185c | 22 | writereg(RF22_REG_08_OPERATING_MODE2,0x02); |
shekhar | 0:15b2487c185c | 23 | writereg(RF22_REG_08_OPERATING_MODE2,0x00); |
shekhar | 0:15b2487c185c | 24 | } |
shekhar | 0:15b2487c185c | 25 | int setFrequency(float centre,float afcPullInRange) |
shekhar | 0:15b2487c185c | 26 | { |
shekhar | 0:15b2487c185c | 27 | //freq setting begins |
shekhar | 0:15b2487c185c | 28 | uint8_t fbsel = 0x40; |
shekhar | 0:15b2487c185c | 29 | uint8_t afclimiter; |
shekhar | 0:15b2487c185c | 30 | if (centre >= 480.0) { |
shekhar | 0:15b2487c185c | 31 | centre /= 2; |
shekhar | 0:15b2487c185c | 32 | fbsel |= 0x20; |
shekhar | 0:15b2487c185c | 33 | afclimiter = afcPullInRange * 1000000.0 / 1250.0; |
shekhar | 0:15b2487c185c | 34 | } else { |
shekhar | 0:15b2487c185c | 35 | if (afcPullInRange < 0.0 || afcPullInRange > 0.159375) |
shekhar | 0:15b2487c185c | 36 | return false; |
shekhar | 0:15b2487c185c | 37 | afclimiter = afcPullInRange * 1000000.0 / 625.0; |
shekhar | 0:15b2487c185c | 38 | } |
shekhar | 0:15b2487c185c | 39 | centre /= 10.0; |
shekhar | 0:15b2487c185c | 40 | float integerPart = floor(centre); |
shekhar | 0:15b2487c185c | 41 | float fractionalPart = centre - integerPart; |
shekhar | 0:15b2487c185c | 42 | |
shekhar | 0:15b2487c185c | 43 | uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23 |
shekhar | 0:15b2487c185c | 44 | fbsel |= fb; |
shekhar | 0:15b2487c185c | 45 | uint16_t fc = fractionalPart * 64000; |
shekhar | 0:15b2487c185c | 46 | writereg(RF22_REG_73_FREQUENCY_OFFSET1, 0); // REVISIT |
shekhar | 0:15b2487c185c | 47 | writereg(RF22_REG_74_FREQUENCY_OFFSET2, 0); |
shekhar | 0:15b2487c185c | 48 | writereg(RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel); |
shekhar | 0:15b2487c185c | 49 | writereg(RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8); |
shekhar | 0:15b2487c185c | 50 | writereg(RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff); |
shekhar | 0:15b2487c185c | 51 | writereg(RF22_REG_2A_AFC_LIMITER, afclimiter); |
shekhar | 0:15b2487c185c | 52 | return 0; |
shekhar | 0:15b2487c185c | 53 | } |
shekhar | 0:15b2487c185c | 54 | |
shekhar | 0:15b2487c185c | 55 | void init() |
shekhar | 0:15b2487c185c | 56 | { |
shekhar | 0:15b2487c185c | 57 | //reset() |
shekhar | 0:15b2487c185c | 58 | writereg(RF22_REG_07_OPERATING_MODE1,0x80); //sw_reset |
shekhar | 0:15b2487c185c | 59 | wait(1); //takes time to reset |
shekhar | 0:15b2487c185c | 60 | |
shekhar | 0:15b2487c185c | 61 | clearTxBuf(); |
shekhar | 0:15b2487c185c | 62 | clearRxBuf(); |
shekhar | 0:15b2487c185c | 63 | //txfifoalmostempty |
shekhar | 0:15b2487c185c | 64 | writereg(RF22_REG_7D_TX_FIFO_CONTROL2,10); |
shekhar | 6:f0fb224c958b | 65 | |
shekhar | 0:15b2487c185c | 66 | //Packet-engine registers |
shekhar | 2:298924eb2b41 | 67 | writereg(RF22_REG_30_DATA_ACCESS_CONTROL,0x00); //RF22_REG_30_DATA_ACCESS_CONTROL, RF22_ENPACRX | RF22_ENPACTX | RF22_ENCRC | RF22_CRC_CRC_16_IBM |
shekhar | 2:298924eb2b41 | 68 | //0x00 |
shekhar | 1:91c435a6966b | 69 | |
shekhar | 1:91c435a6966b | 70 | |
shekhar | 2:298924eb2b41 | 71 | //writereg(RF22_REG_32_HEADER_CONTROL1,0x88); //RF22_REG_32_HEADER_CONTROL1, RF22_BCEN_HEADER3 | RF22_HDCH_HEADER3 //not reqiured for tx |
shekhar | 2:298924eb2b41 | 72 | writereg(RF22_REG_33_HEADER_CONTROL2,0x08); //RF22_REG_33_HEADER_CONTROL2, RF22_HDLEN_4 | RF22_SYNCLEN_2 |
shekhar | 2:298924eb2b41 | 73 | //why 0x42 //or 0x00?? |
shekhar | 2:298924eb2b41 | 74 | |
shekhar | 2:298924eb2b41 | 75 | writereg(RF22_REG_34_PREAMBLE_LENGTH,0x00); //RF22_REG_34_PREAMBLE_LENGTH, nibbles); preamble length = 8; |
shekhar | 1:91c435a6966b | 76 | //why is preamble used?? |
shekhar | 1:91c435a6966b | 77 | |
shekhar | 2:298924eb2b41 | 78 | //writereg(RF22_REG_36_SYNC_WORD3,0x2D); //syncword3=2D |
shekhar | 1:91c435a6966b | 79 | //why?? |
shekhar | 1:91c435a6966b | 80 | |
shekhar | 2:298924eb2b41 | 81 | //writereg(RF22_REG_37_SYNC_WORD2,0xD4); //syncword2=D4 |
shekhar | 1:91c435a6966b | 82 | //why?? |
shekhar | 1:91c435a6966b | 83 | |
shekhar | 2:298924eb2b41 | 84 | //writereg(RF22_REG_3F_CHECK_HEADER3,0); //RF22_REG_3F_CHECK_HEADER3, RF22_DEFAULT_NODE_ADDRESS |
shekhar | 1:91c435a6966b | 85 | |
shekhar | 1:91c435a6966b | 86 | |
shekhar | 1:91c435a6966b | 87 | //why all these headers |
shekhar | 2:298924eb2b41 | 88 | //writereg(RF22_REG_3A_TRANSMIT_HEADER3,0xab); //header_to |
shekhar | 2:298924eb2b41 | 89 | //writereg(RF22_REG_3B_TRANSMIT_HEADER2,0xbc); //header_from |
shekhar | 2:298924eb2b41 | 90 | //writereg(RF22_REG_3C_TRANSMIT_HEADER1,0xcd); //header_ids |
shekhar | 2:298924eb2b41 | 91 | //writereg(RF22_REG_3D_TRANSMIT_HEADER0,0xde); //header_flags |
shekhar | 2:298924eb2b41 | 92 | //writereg(RF22_REG_3F_CHECK_HEADER3,0xab); |
shekhar | 2:298924eb2b41 | 93 | //writereg(RF22_REG_40_CHECK_HEADER2,0xbc); |
shekhar | 2:298924eb2b41 | 94 | //writereg(RF22_REG_41_CHECK_HEADER1,0xcd); |
shekhar | 2:298924eb2b41 | 95 | //writereg(RF22_REG_42_CHECK_HEADER0,0xde); |
shekhar | 0:15b2487c185c | 96 | |
shekhar | 1:91c435a6966b | 97 | //RSSI threshold for clear channel indicator //rx |
shekhar | 2:298924eb2b41 | 98 | //writereg(RF22_REG_27_RSSI_THRESHOLD,0xA5); //55 for -80dBm, 2D for -100dBm, 7D for -60dBm, A5 for -40dBm, CD for -20 dBm |
shekhar | 0:15b2487c185c | 99 | |
shekhar | 0:15b2487c185c | 100 | writereg(RF22_REG_0B_GPIO_CONFIGURATION0,0x15); // TX state ?? |
shekhar | 0:15b2487c185c | 101 | writereg(RF22_REG_0C_GPIO_CONFIGURATION1,0x12); // RX state ?? |
shekhar | 0:15b2487c185c | 102 | |
shekhar | 0:15b2487c185c | 103 | //interrupts |
shekhar | 0:15b2487c185c | 104 | // spiWrite(RF22_REG_05_INTERRUPT_ENABLE1, RF22_ENTXFFAEM |RF22_ENRXFFAFULL | RF22_ENPKSENT |RF22_ENPKVALID| RF22_ENCRCERROR); |
shekhar | 0:15b2487c185c | 105 | // spiWrite(RF22_REG_06_INTERRUPT_ENABLE2, RF22_ENPREAVAL); |
shekhar | 0:15b2487c185c | 106 | |
shekhar | 1:91c435a6966b | 107 | setFrequency(435.0, 0.05);//check |
shekhar | 0:15b2487c185c | 108 | |
shekhar | 0:15b2487c185c | 109 | //return !(statusRead() & RF22_FREQERR); |
shekhar | 0:15b2487c185c | 110 | if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00) |
shekhar | 0:15b2487c185c | 111 | pc.printf("frequency not set properly\n"); |
shekhar | 0:15b2487c185c | 112 | //frequency set |
shekhar | 0:15b2487c185c | 113 | |
shekhar | 0:15b2487c185c | 114 | //setModemConfig(FSK_Rb2_4Fd36); FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz |
shekhar | 0:15b2487c185c | 115 | //setmodemregisters |
shekhar | 0:15b2487c185c | 116 | //0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a = FSK_RB2_4FD36 |
shekhar | 0:15b2487c185c | 117 | //0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 = OOK,2.4, 335 |
shekhar | 0:15b2487c185c | 118 | writereg(RF22_REG_1C_IF_FILTER_BANDWIDTH,0xdf); |
shekhar | 0:15b2487c185c | 119 | writereg(RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE,0x03); |
shekhar | 0:15b2487c185c | 120 | writereg(RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE,0x39); |
shekhar | 0:15b2487c185c | 121 | writereg(RF22_REG_21_CLOCK_RECOVERY_OFFSET2,0x20); |
shekhar | 0:15b2487c185c | 122 | writereg(RF22_REG_22_CLOCK_RECOVERY_OFFSET1,0x68); //updated 20 to 25 reg values from excel sheet for 1.2 Khz freq. deviation,fsk |
shekhar | 0:15b2487c185c | 123 | writereg(RF22_REG_23_CLOCK_RECOVERY_OFFSET0,0xdc); |
shekhar | 0:15b2487c185c | 124 | writereg(RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1,0x00); |
shekhar | 0:15b2487c185c | 125 | writereg(RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0,0x6B); |
shekhar | 0:15b2487c185c | 126 | writereg(RF22_REG_2C_OOK_COUNTER_VALUE_1,0x2C); |
shekhar | 0:15b2487c185c | 127 | writereg(RF22_REG_2D_OOK_COUNTER_VALUE_2,0x11); //not required for fsk (OOK counter value) |
shekhar | 0:15b2487c185c | 128 | writereg(RF22_REG_2E_SLICER_PEAK_HOLD,0x2A); //?? |
shekhar | 0:15b2487c185c | 129 | writereg(RF22_REG_58,0x80); |
shekhar | 0:15b2487c185c | 130 | writereg(RF22_REG_69_AGC_OVERRIDE1,0x60); |
shekhar | 1:91c435a6966b | 131 | |
shekhar | 2:298924eb2b41 | 132 | //check...//also depends on 0x70[5] |
shekhar | 4:b51ca6ee9136 | 133 | writereg(RF22_REG_6E_TX_DATA_RATE1,0x02);//TX at 0.123kbps=:6E=0x01; 6F=0x06 |
shekhar | 4:b51ca6ee9136 | 134 | writereg(RF22_REG_6F_TX_DATA_RATE0,0x9F);//TX at 1.2kbps: 6E=0x09; 6F=0xd5 //Formula: tx_datarate*(2^21)/10^6 |
shekhar | 4:b51ca6ee9136 | 135 | //For 0.160kbps 6E = 01 6F=50 |
shekhar | 4:b51ca6ee9136 | 136 | //for 0.320kbps 029F |
shekhar | 1:91c435a6966b | 137 | |
shekhar | 6:f0fb224c958b | 138 | writereg(RF22_REG_70_MODULATION_CONTROL1,0x20);//changed from 0x2c to 0x20 since machester is not required |
shekhar | 0:15b2487c185c | 139 | writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//ook = 0x21 //fsk = 0x22 |
shekhar | 1:91c435a6966b | 140 | |
shekhar | 6:f0fb224c958b | 141 | //writereg(RF22_REG_72_FREQUENCY_DEVIATION,0x50); |
shekhar | 1:91c435a6966b | 142 | //required for OOK??? |
shekhar | 1:91c435a6966b | 143 | |
shekhar | 0:15b2487c185c | 144 | //set tx power |
shekhar | 2:298924eb2b41 | 145 | writereg(RF22_REG_6D_TX_POWER,0x07); //20dbm |
shekhar | 2:298924eb2b41 | 146 | //why 0x06?? 0x07 is for max//is the previous bits required? |
shekhar | 1:91c435a6966b | 147 | |
shekhar | 3:b2acafb06072 | 148 | writereg(RF22_REG_3E_PACKET_LENGTH,TX_DATA); //packet length |
shekhar | 1:91c435a6966b | 149 | //packet length not required |
shekhar | 1:91c435a6966b | 150 | |
shekhar | 0:15b2487c185c | 151 | } |
shekhar | 0:15b2487c185c | 152 | int main() |
shekhar | 0:15b2487c185c | 153 | { |
shekhar | 0:15b2487c185c | 154 | wait(1); // wait for POR to complete //change the timing later |
shekhar | 0:15b2487c185c | 155 | cs=1; // chip must be deselected |
shekhar | 0:15b2487c185c | 156 | wait(1); //change the time later |
shekhar | 0:15b2487c185c | 157 | spi.format(8,0); |
shekhar | 0:15b2487c185c | 158 | spi.frequency(10000000); //10MHz SCLK |
shekhar | 0:15b2487c185c | 159 | if (readreg(RF22_REG_00_DEVICE_TYPE) == 0x08) pc.printf("spi connection valid\n"); |
shekhar | 0:15b2487c185c | 160 | else pc.printf("error in spi connection\n"); |
shekhar | 0:15b2487c185c | 161 | |
shekhar | 0:15b2487c185c | 162 | init(); |
shekhar | 0:15b2487c185c | 163 | |
shekhar | 0:15b2487c185c | 164 | |
shekhar | 0:15b2487c185c | 165 | //init complete |
shekhar | 0:15b2487c185c | 166 | pc.printf("init complete.....press t to send\n"); |
shekhar | 0:15b2487c185c | 167 | |
shekhar | 0:15b2487c185c | 168 | |
shekhar | 0:15b2487c185c | 169 | //******** |
shekhar | 0:15b2487c185c | 170 | |
shekhar | 0:15b2487c185c | 171 | while(pc.getc()=='t') //1 |
shekhar | 0:15b2487c185c | 172 | { |
shekhar | 0:15b2487c185c | 173 | /*uint8_t data[] = "Hello World!"; |
shekhar | 0:15b2487c185c | 174 | pc.printf("%d %d %d %d %d %d %d %d %d %d %d %d",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9],data[10],data[11],data[12]);*/ |
shekhar | 0:15b2487c185c | 175 | |
shekhar | 0:15b2487c185c | 176 | uint8_t data[255]; //starts from 0,1,2,3,4!!!; |
shekhar | 0:15b2487c185c | 177 | int i = 0; //for loops |
shekhar | 0:15b2487c185c | 178 | int u = 0; //universal count for hk array |
shekhar | 0:15b2487c185c | 179 | int bar = 0; |
shekhar | 0:15b2487c185c | 180 | //filling hk data |
shekhar | 0:15b2487c185c | 181 | /*for(int n=0; n<1; n++) |
shekhar | 0:15b2487c185c | 182 | data[n] = 0xAA; |
shekhar | 0:15b2487c185c | 183 | data[1] = 0x3A; */ |
shekhar | 0:15b2487c185c | 184 | //for(int n=0; n<15; n++) |
shekhar | 0:15b2487c185c | 185 | /*data[0] = 0xAB; |
shekhar | 0:15b2487c185c | 186 | data[1] = 0x8A; |
shekhar | 0:15b2487c185c | 187 | data[2] = 0xE2; |
shekhar | 0:15b2487c185c | 188 | data[3] = 0xBB; |
shekhar | 0:15b2487c185c | 189 | data[4] = 0xB8; |
shekhar | 0:15b2487c185c | 190 | data[5] = 0xA2; |
shekhar | 0:15b2487c185c | 191 | data[6] = 0x8E; |
shekhar | 0:15b2487c185c | 192 | data[7] = 0x88; |
shekhar | 0:15b2487c185c | 193 | data[8] = 0x99; |
shekhar | 0:15b2487c185c | 194 | data[9] = 0xAA; |
shekhar | 0:15b2487c185c | 195 | data[10] = 0xAA; |
shekhar | 0:15b2487c185c | 196 | data[11] = 0xAA; |
shekhar | 0:15b2487c185c | 197 | data[12] = 0xDD; |
shekhar | 0:15b2487c185c | 198 | data[13] = 0xEE; |
shekhar | 0:15b2487c185c | 199 | data[14] = 0x00; |
shekhar | 0:15b2487c185c | 200 | */ |
shekhar | 0:15b2487c185c | 201 | /*for(int n=50; n<60; n++) |
shekhar | 0:15b2487c185c | 202 | data[n] = n; */ |
shekhar | 0:15b2487c185c | 203 | //for(int n=60; n<120; n++) |
shekhar | 0:15b2487c185c | 204 | // data[n] = 0x11; |
shekhar | 0:15b2487c185c | 205 | /*for(int n=75; n<97; n++) |
shekhar | 0:15b2487c185c | 206 | data[n] = 0xBC; |
shekhar | 0:15b2487c185c | 207 | for(int n=97; n<110; n++) |
shekhar | 0:15b2487c185c | 208 | data[n] = 0xEC; |
shekhar | 0:15b2487c185c | 209 | for(int n=110; n<120; n++) |
shekhar | 0:15b2487c185c | 210 | data[n] = 0xFC; */ |
shekhar | 0:15b2487c185c | 211 | for(int n=0; n<255; n++) |
shekhar | 0:15b2487c185c | 212 | data[n] = 0xAB; |
shekhar | 0:15b2487c185c | 213 | /*uint8_t stuff[] = "IITMSAT IITMSAT"; |
shekhar | 0:15b2487c185c | 214 | for(int i = 0 ; i < 15 ; ++i){ |
shekhar | 0:15b2487c185c | 215 | data[i] = stuff[i]; |
shekhar | 0:15b2487c185c | 216 | }*/ |
shekhar | 0:15b2487c185c | 217 | |
shekhar | 0:15b2487c185c | 218 | //for(int n=150; n<TX_DATA; n++) |
shekhar | 0:15b2487c185c | 219 | // data[n] = 0x11; |
shekhar | 0:15b2487c185c | 220 | //tx settings begin |
shekhar | 0:15b2487c185c | 221 | |
shekhar | 0:15b2487c185c | 222 | //setModeIdle(); |
shekhar | 6:f0fb224c958b | 223 | //writereg(RF22_REG_07_OPERATING_MODE1,0x01); //ready mode //already in ready mode after POR |
shekhar | 0:15b2487c185c | 224 | //fillTxBuf(data, len); |
shekhar | 0:15b2487c185c | 225 | clearTxBuf(); |
shekhar | 0:15b2487c185c | 226 | //Filling Data into FIFO for the first time |
shekhar | 0:15b2487c185c | 227 | /*cs = 0; |
shekhar | 0:15b2487c185c | 228 | spi.write(0xFF); //fifo write access |
shekhar | 0:15b2487c185c | 229 | for(i=0; i<datalen; i++){ |
shekhar | 0:15b2487c185c | 230 | spi.write(data[i]); |
shekhar | 0:15b2487c185c | 231 | pc.printf("0x%X \n",data[u+i]); |
shekhar | 0:15b2487c185c | 232 | } |
shekhar | 0:15b2487c185c | 233 | u=i;//check its 64 |
shekhar | 0:15b2487c185c | 234 | cs = 1; */ |
shekhar | 0:15b2487c185c | 235 | |
shekhar | 0:15b2487c185c | 236 | //Set to Tx mode |
shekhar | 0:15b2487c185c | 237 | writereg(RF22_REG_07_OPERATING_MODE1,0x09); |
shekhar | 0:15b2487c185c | 238 | |
shekhar | 0:15b2487c185c | 239 | //Check for fifoempty Thresh |
shekhar | 3:b2acafb06072 | 240 | //while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20); |
shekhar | 0:15b2487c185c | 241 | |
shekhar | 3:b2acafb06072 | 242 | u = 0; |
shekhar | 0:15b2487c185c | 243 | while(u!=TX_DATA) { |
shekhar | 0:15b2487c185c | 244 | if((TX_DATA - u) >= TIMES) |
shekhar | 0:15b2487c185c | 245 | bar = TIMES; |
shekhar | 0:15b2487c185c | 246 | else |
shekhar | 0:15b2487c185c | 247 | bar = (TX_DATA - u); |
shekhar | 0:15b2487c185c | 248 | |
shekhar | 0:15b2487c185c | 249 | //writing again |
shekhar | 0:15b2487c185c | 250 | cs = 0; |
shekhar | 0:15b2487c185c | 251 | spi.write(0xFF); //FIFO write access |
shekhar | 4:b51ca6ee9136 | 252 | //for(i=0; i<bar; i++,u++) |
shekhar | 4:b51ca6ee9136 | 253 | for(i=0; i<(bar/2); i++) |
shekhar | 0:15b2487c185c | 254 | { |
shekhar | 4:b51ca6ee9136 | 255 | u=u+2; |
shekhar | 0:15b2487c185c | 256 | //spi.write(data[i]); |
shekhar | 4:b51ca6ee9136 | 257 | spi.write(0xFF); |
shekhar | 4:b51ca6ee9136 | 258 | spi.write(0x00); |
shekhar | 3:b2acafb06072 | 259 | pc.printf("%d\n",u); |
shekhar | 3:b2acafb06072 | 260 | } |
shekhar | 0:15b2487c185c | 261 | //u = u + i; |
shekhar | 0:15b2487c185c | 262 | cs = 1; |
shekhar | 0:15b2487c185c | 263 | //Check for fifoThresh |
shekhar | 0:15b2487c185c | 264 | while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20); |
shekhar | 0:15b2487c185c | 265 | } |
shekhar | 0:15b2487c185c | 266 | //rf22.waitPacketSent(); |
shekhar | 0:15b2487c185c | 267 | while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04)pc.printf(" chck pkt sent!\n"); |
shekhar | 0:15b2487c185c | 268 | pc.printf(" packet sent "); |
shekhar | 0:15b2487c185c | 269 | |
shekhar | 6:f0fb224c958b | 270 | |
shekhar | 6:f0fb224c958b | 271 | // set to sleep mode |
shekhar | 6:f0fb224c958b | 272 | |
shekhar | 6:f0fb224c958b | 273 | writereg(RF22_REG_07_OPERATING_MODE1,0x00); //standby mode |
shekhar | 6:f0fb224c958b | 274 | |
shekhar | 0:15b2487c185c | 275 | } |
shekhar | 0:15b2487c185c | 276 | } |