pradeep shekhar
/
Beacon_Code_testing
Final Beacon code for testing
Revision 2:44b63c859531, committed 2015-10-22
- Comitter:
- shekhar
- Date:
- Thu Oct 22 04:47:07 2015 +0000
- Parent:
- 1:8b18c140a710
- Commit message:
- Changed the datatype of frequency and removed afclimiter;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
tx.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8b18c140a710 -r 44b63c859531 main.cpp --- a/main.cpp Mon Oct 05 17:15:24 2015 +0000 +++ b/main.cpp Thu Oct 22 04:47:07 2015 +0000 @@ -6,6 +6,7 @@ SPI spi(D11, D12, D13); // mosi, miso, sclk DigitalOut cs(D10); //slave select or chip select +int once = 1; Timer t; void P_BCN_INIT() @@ -32,7 +33,8 @@ { pc.printf("line 33"); //Measure and store BCN temperature in BCN_TS_BUFFER - BCN_TS_BUFFER = ((check_Temperature())*0.5) - 64; + BCN_TS_BUFFER = check_Temperature(); + pc.printf("\n\ntemperature = %d\n\n",BCN_TS_BUFFER); pc.printf("line 36"); //Get BCN_HK data from BCN HW(SPI) //Store BCN_HK data in BCN_HK_BUFFER if(BCN_STANDBY == 1 ) @@ -48,12 +50,13 @@ //pc.printf("in BCN_TX_STANDBY != 1\r\n"); pc.printf("line 49"); t.start(); - int begin = t.read(); - pc.printf("line 52"); + int begin = t.read_us(); + //pc.printf("line 52"); SHORT_BCN_TX(); LONG_BCN_TX(); - pc.printf("line 55"); - int end = t.read(); + //pc.printf("line 55"); + t.stop(); + int end = t.read_us(); pc.printf("The time required for short and long is %d seconds\r\n", end-begin); pc.printf("Short and Long packets sent\r\n"); //include LONG_BCN_TX also @@ -95,19 +98,16 @@ } int check_Temperature() -{ +{ int temperature; - while((readreg(RF22_REG_0F_ADC_CONFIGURATION) && 0x80) == 0x0) - { - writereg(RF22_REG_0F_ADC_CONFIGURATION,128); //128 = 10000000 - writereg(RF22_REG_12_Temperature_Sensor_Calibration,32); //160 == 10100000 32 == 00100000 - wait(1); - temperature = readreg(RF22_REG_11_ADC_Value); - //pc.printf("Temperature: %d\r\n", temperature); - } + //P_BCN_INIT(); + writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80); //128 = 10000000 + writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20); //160 == 10100000 32 == 00100000 + wait(1); + temperature = readreg(RF22_REG_11_ADC_Value); + temperature = (float)temperature*0.5 - 64; return temperature; } - void SHORT_BCN_TX() { writereg(RF22_REG_6E_TX_DATA_RATE,0x01); @@ -151,10 +151,8 @@ pc.printf("line 151"); for (int byte_counter = 0; byte_counter <15 ; byte_counter++) { - pc.printf("%d byte counter\n", byte_counter); for(int j = 3; j >= 0 ; j--) { - pc.printf("%d j \n", j); if((short_beacon[byte_counter] & (uint8_t) pow(2.0,(j*2+1)))!= pow(2.0,(j*2+1))) { byte=0x00; @@ -254,31 +252,20 @@ writereg(RF22_REG_08_OPERATING_MODE2,0x01); writereg(RF22_REG_08_OPERATING_MODE2,0x00); } -void clearRxBuf() -{ - writereg(RF22_REG_08_OPERATING_MODE2,0x02); - writereg(RF22_REG_08_OPERATING_MODE2,0x00); -} -int setFrequency(float centre,float afcPullInRange) +int setFrequency(double centre) { //freq setting begins uint8_t fbsel = 0x40; - uint8_t afclimiter; if (centre >= 480.0) { centre /= 2; fbsel |= 0x20; - afclimiter = afcPullInRange * 1000000.0 / 1250.0; } else - { - if (afcPullInRange < 0.0 || afcPullInRange > 0.159375) - return false; - afclimiter = afcPullInRange * 1000000.0 / 625.0; - } + return false; centre /= 10.0; - float integerPart = floor(centre); - float fractionalPart = centre - integerPart; + double integerPart = floor(centre); + double fractionalPart = centre - integerPart; uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23 fbsel |= fb; @@ -288,7 +275,6 @@ writereg(RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel); writereg(RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8); writereg(RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff); - writereg(RF22_REG_2A_AFC_LIMITER, afclimiter); return 0; } @@ -310,9 +296,7 @@ writereg(RF22_REG_07_OPERATING_MODE1,0x80); //sw_reset wait(1); //takes time to reset - clearTxBuf(); - - clearRxBuf();//may not be required + clearTxBuf(); //txfifoalmostempty writereg(RF22_REG_7D_TX_FIFO_CONTROL2,10); @@ -332,7 +316,7 @@ // spiWrite(RF22_REG_05_INTERRUPT_ENABLE1, RF22_ENTXFFAEM |RF22_ENRXFFAFULL | RF22_ENPKSENT |RF22_ENPKVALID| RF22_ENCRCERROR); // spiWrite(RF22_REG_06_INTERRUPT_ENABLE2, RF22_ENPREAVAL); - setFrequency(435.0, 0.05); + setFrequency(435.0); //This may not be required if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00) @@ -411,15 +395,21 @@ P_BCN_FEN(); + P_BCN_TX_MAIN(); + t.stop(); + + while(1) { - - temp = check_Temperature(); - final_temp = (float)temp*0.5 - 64; - pc.printf("final temp = %d\r\n", final_temp);} + P_BCN_TX_MAIN(); + //temp = check_Temperature(); +// final_temp = (float)temp*0.5 - 64; +// P_BCN_INIT(); +// pc.printf("final temp = %d\r\n", final_temp); + } //while(1) // { // temp = check_Temperature();
diff -r 8b18c140a710 -r 44b63c859531 tx.h --- a/tx.h Mon Oct 05 17:15:24 2015 +0000 +++ b/tx.h Thu Oct 22 04:47:07 2015 +0000 @@ -23,15 +23,14 @@ uint8_t BCN_TX_EN = 1; //hardcoding for now //check where is this variable toggled?? uint8_t BCN_FEN = 0; //This variable is also toggled in P_BCN_FEN process. uint8_t BCN_STANDBY = 0; //hardcoding for now //check where is this variable toggled?? -uint8_t LOW_POWER_COUNTER; //toggled in a function uint8_t BCN_TS_BUFFER; // For Temperature //FUNCTION PROTOTYPING +void P_BCN_TEMP_INIT(); void P_BCN_INIT(); void P_BCN_FEN(); void P_BCN_TX_MAIN(); void Set_BCN_TX_STATUS(uint8_t STATUS); -int check_POWER_LEVEL(); int check_Temperature(); void SHORT_BCN_TX(); void LONG_BCN_TX(); @@ -39,10 +38,10 @@ void writereg(uint8_t reg,uint8_t val); uint8_t readreg(uint8_t reg); void clearTxBuf(); -void clearRxBuf(); -int setFrequency(float,float); +int setFrequency(double); bool Check_ACK_RECEIVED(); -void INC_BCN_LOW_POWER_COUNTER(); + + #define RF22_MAX_MESSAGE_LEN 255