pradeep shekhar
/
Beacon_BAE_intergration_test_3
General testings
Fork of BEACON_CODE_NEW by
Revision 19:de2bb3b0b0d2, committed 2015-10-27
- Comitter:
- shekhar
- Date:
- Tue Oct 27 11:50:05 2015 +0000
- Parent:
- 18:4113ef89cd78
- Child:
- 20:a7dbfbc462f1
- Commit message:
- Made changes for BAE integration
Changed in this revision
beacon.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/beacon.h Sun Oct 25 15:34:58 2015 +0000 +++ b/beacon.h Tue Oct 27 11:50:05 2015 +0000 @@ -1,6 +1,5 @@ #include "mbed.h" - //STATES #define BCN_RF_SILENCE 0 #define BCN_TX_DISABLED 1 @@ -12,7 +11,7 @@ #define SHORT_TX_DATA 60 //in bytes #define LONG_TX_DATA 75 //in bytes -//#define RF_SILENCE_TIME 5 //in seconds //shouldn't this be 35 mins in actual scenario +//#define RF_SILENCE_TIME 5 //in seconds #define RF_SILENCE_TIME 35*60 //GLOBAL VARIABLES @@ -20,7 +19,7 @@ uint8_t BCN_TX_MAIN_STATUS; uint8_t BCN_TX_STATUS; 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_FEN = 0; //write this to non-erasable memory. uint8_t BCN_STANDBY = 0; //hardcoding for now //check where is this variable toggled?? uint8_t BCN_TS_BUFFER; // For Temperature @@ -28,13 +27,13 @@ void P_BCN_INIT(); void P_BCN_FEN(); void P_BCN_TX_MAIN(); -void Set_BCN_TX_STATUS(uint8_t STATUS); +void Set_BCN_TX_STATUS(uint8_t); int check_Temperature(); void SHORT_BCN_TX(); void LONG_BCN_TX(); void Init_BEACON_HW(); -void writereg(uint8_t reg,uint8_t val); -uint8_t readreg(uint8_t reg); +void writereg(uint8_t,uint8_t); +uint8_t readreg(uint8_t); void clearTxBuf(); int setFrequency(double,float); bool Check_ACK_RECEIVED();
--- a/main.cpp Sun Oct 25 15:34:58 2015 +0000 +++ b/main.cpp Tue Oct 27 11:50:05 2015 +0000 @@ -1,22 +1,23 @@ -#include "tx.h" +#include "beacon.h" #include <stdio.h> -Ticker loop; Serial pc(USBTX, USBRX); //tx,rx SPI spi(D11, D12, D13); // mosi, miso, sclk DigitalOut cs(D10); //slave select or chip select Timer t; +Ticker loop; void P_BCN_INIT() { BCN_INIT_STATUS = 1; Init_BEACON_HW(); - t.start(); + if (BCN_FEN == 0) + t.start();//Start the timer for RF_Silence BCN_INIT_STATUS = 0; } void P_BCN_FEN() { - BCN_FEN = 1; + BCN_FEN = 1;//write this value to flash } void P_BCN_TX_MAIN() { @@ -38,29 +39,19 @@ // break; } else - { - //pc.printf("in BCN_TX_STANDBY != 1\r\n"); - - //t.start(); - //int begin = t.read_us(); + { //transmit short beacon and long beacon SHORT_BCN_TX(); LONG_BCN_TX(); - //int end = t.read_us(); - //pc.printf("The time required for short and long is %d microseconds\r\n", end-begin); - pc.printf("Short and Long packets sent\r\n"); - //include LONG_BCN_TX also + if(Check_ACK_RECEIVED() == 1) { Set_BCN_TX_STATUS(BCN_TX_SUCCESS); - BCN_TX_MAIN_STATUS = 0; - // break; - + BCN_TX_MAIN_STATUS = 0; } else { Set_BCN_TX_STATUS(BCN_TX_FAILURE); BCN_TX_MAIN_STATUS = 0; - // break; } } @@ -69,15 +60,12 @@ { Set_BCN_TX_STATUS(BCN_TX_DISABLED); BCN_TX_MAIN_STATUS = 0; - // break; - } } else { Set_BCN_TX_STATUS(BCN_RF_SILENCE); //Window of RF Silence: None of the Txs should be on. BCN_TX_MAIN_STATUS = 0; - // break; } } @@ -89,8 +77,8 @@ int check_Temperature() { int temperature; - writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80); //128 = 10000000 - writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20); //160 == 10100000 32 == 00100000 + writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80); + writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20); wait(1); temperature = readreg(RF22_REG_11_ADC_Value); temperature = (float)temperature*0.5 - 64; @@ -102,16 +90,13 @@ writereg(RF22_REG_6E_TX_DATA_RATE,0x01); writereg(RF22_REG_6F_TX_DATA_RATE,0x4F);//160bps writereg(RF22_REG_3E_PACKET_LENGTH,SHORT_TX_DATA); //short packet length - /* - init(); - //init complete - pc.printf("init complete.....press t to send\n"); - while(pc.getc()=='t') - { */ - //button.rise(&interrupt_func); //interrupt enabled ( rising edge of pin 9) - wait(0.02); // pl. update this value or even avoid it!!! - int i=0; - //extract values from short_beacon[] + + wait(0.02); + + + + //get short_beacon array + struct Short_beacon { uint8_t Voltage[1]; @@ -122,14 +107,11 @@ }Shortbeacon = { {0x88}, {0x99, 0xAA} , {0xAA},{0xAA,0xDD,0xEE}, {0x00} }; //filling hk data - //uint8_t short_beacon[] = { 0xAB, 0x8A, 0xE2, 0xBB, 0xB8, 0xA2, 0x8E,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]}; uint8_t short_beacon[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]}; - //mask - /*uint8_t data[] = "Hello World!"; - 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]);*/ - - //setModeIdle(); - //writereg(RF22_REG_07_OPERATING_MODE1,0x01); //ready mode ?? + + + + clearTxBuf(); //writing data first time int byte = 0; @@ -167,12 +149,11 @@ //Check for fifoThresh while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20); - //pc.printf("fifothresh1?\n"); - - //rf22.waitPacketSent(); + + //Check for packetsent interrupt while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04); - //pc.printf(" chk pkt sent!\r\n"); - pc.printf("Short packet sent\r\n"); + + //pc.printf("Short packet sent\r\n"); writereg(RF22_REG_07_OPERATING_MODE1,0x00); //standby mode @@ -180,18 +161,21 @@ void LONG_BCN_TX() { writereg(RF22_REG_6E_TX_DATA_RATE,0x04); - writereg(RF22_REG_6F_TX_DATA_RATE,0xea); + writereg(RF22_REG_6F_TX_DATA_RATE,0xEA);//600 bps writereg(RF22_REG_3E_PACKET_LENGTH,LONG_TX_DATA); //long packet length - wait(0.02); // pl. update this value or even avoid it!!! - //extract values from long_beacon[] - - //uint8_t Long_beacon[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,Longbeacon.Voltage[0],Longbeacon.AngularSpeed[0], Longbeacon.AngularSpeed[1],Longbeacon.SubsystemStatus[0],Longbeacon.Temp[0],Longbeacon.Temp[1],Longbeacon.Temp[2],Longbeacon.ErrorFlag[0]}; + wait(0.02); + + + //get long_beacon array uint8_t Long_beacon[75]; for(int i = 0;i<75;i++) { Long_beacon[i] = 0xA0; } + + + //setModeIdle(); writereg(RF22_REG_07_OPERATING_MODE1,0x01); //ready mode @@ -210,8 +194,7 @@ //Check for fifoThresh while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20); - //pc.printf("fifothresh1?\n"); - //writing data first time + cs = 0; spi.write(0xFF); for(int i=60; i<75;i++) @@ -222,11 +205,12 @@ wait(0.01); //Check for fifoThresh while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20); - //pc.printf("fifothresh2?\n"); - //rf22.waitPacketSent(); + + //Check for packetsent interrupt while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04); - //pc.printf(" chk pkt sent!]\r\n"); - pc.printf("Long packet sent\r\n"); + + //pc.printf("Long packet sent\r\n"); + writereg(RF22_REG_07_OPERATING_MODE1,0x00); //standby mode } void reset_uC() @@ -248,7 +232,6 @@ } int setFrequency(double centre,float afcPullInRange) { -//freq setting begins uint8_t fbsel = 0x40; uint8_t afclimiter; if (centre >= 480.0) { @@ -280,17 +263,16 @@ void Init_BEACON_HW() { cs=1; // chip must be deselected - //wait(1); //change the time later spi.format(8,0); spi.frequency(10000000); //10MHz SCLK //should either have a flag for invalid SPI or discard this for actual case or add reset if (readreg(RF22_REG_00_DEVICE_TYPE) == 0x08) - pc.printf("spi connection valid\r\n"); + /*pc.printf("spi connection valid\r\n")*/; else - pc.printf("error in spi connection\r\n"); - //reset() - + {//pc.printf("error in spi connection\r\n"); + reset_uC(); + } writereg(RF22_REG_07_OPERATING_MODE1,0x80); //sw_reset wait(1); //takes time to reset @@ -300,34 +282,26 @@ writereg(RF22_REG_07_OPERATING_MODE1,0x00); //standby mode //txfifoalmostempty - writereg(RF22_REG_7D_TX_FIFO_CONTROL2,10); + writereg(RF22_REG_7D_TX_FIFO_CONTROL2,30); //Packet-engine registers - 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 - //&0x77 = diasable packet rx-tx handling + writereg(RF22_REG_30_DATA_ACCESS_CONTROL,0x00); - writereg(RF22_REG_33_HEADER_CONTROL2,0x08); //RF22_REG_33_HEADER_CONTROL2, RF22_HDLEN_4 | RF22_SYNCLEN_2 - writereg(RF22_REG_34_PREAMBLE_LENGTH,0x00); //RF22_REG_34_PREAMBLE_LENGTH, nibbles); preamble length = 8; - //may be redundant since packethandler is disabled + writereg(RF22_REG_33_HEADER_CONTROL2,0x08); + writereg(RF22_REG_34_PREAMBLE_LENGTH,0x00); - writereg(RF22_REG_0B_GPIO_CONFIGURATION0,0x15); // TX state ?? - writereg(RF22_REG_0C_GPIO_CONFIGURATION1,0x12); // RX state ?? - - //interrupts - // spiWrite(RF22_REG_05_INTERRUPT_ENABLE1, RF22_ENTXFFAEM |RF22_ENRXFFAFULL | RF22_ENPKSENT |RF22_ENPKVALID| RF22_ENCRCERROR); - // spiWrite(RF22_REG_06_INTERRUPT_ENABLE2, RF22_ENPREAVAL); + writereg(RF22_REG_0B_GPIO_CONFIGURATION0,0x15); // TX state + writereg(RF22_REG_0C_GPIO_CONFIGURATION1,0x12); // RX state setFrequency(435.0,05); - //This may not be required if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00) - pc.printf("frequency not set properly\r\n"); - //frequency set + { + //pc.printf("frequency not set properly\r\n"); + reset_uC(); + } - //setModemConfig(FSK_Rb2_4Fd36); FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz - //setmodemregisters - //0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a = FSK_RB2_4FD36 - //0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 = OOK,2.4, 335 + //set Modem Configuration writereg(RF22_REG_1C_IF_FILTER_BANDWIDTH,0xdf); writereg(RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE,0x03); writereg(RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE,0x39); @@ -342,37 +316,27 @@ writereg(RF22_REG_58,0x80); writereg(RF22_REG_69_AGC_OVERRIDE1,0x60); - - //writereg(RF22_REG_6E_TX_DATA_RATE_0.125_1,0x09);//written later - //writereg(RF22_REG_6F_TX_DATA_RATE_0.125_0,0xd5);//written later - - writereg(RF22_REG_70_MODULATION_CONTROL1,0x20);//changed from 0x2c to 0x20 since machester is not required - writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//ook = 0x21 //fsk = 0x22 - - //writereg(RF22_REG_72_FREQUENCY_DEVIATION,0x50); - //required for OOK??? + //Data rate set later + + writereg(RF22_REG_70_MODULATION_CONTROL1,0x20); + writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//ook = 0x21 //set tx power writereg(RF22_REG_6D_TX_POWER,0x07); //20dbm - //why 0x06?? 0x07 is for max//is the previous bits required? - //writereg(RF22_REG_3E_PACKET_LENGTH,SHORT_TX_DATA); //short packet length //written later + //TX_packet_length written later } bool Check_ACK_RECEIVED() { - //logic: - if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04) //bit is set if the data packet is sent correctly + if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04) { - printf("Packet sent: ACK received\r\n"); - return 1; //for ACK received: yes - + //printf("Packet sent: ACK received\r\n"); + return 1; } else { - pc.printf("Packet not sent\r\n"); - return 0; //actual value - //return 1; //to make this function work in any condition //Why?? - + //pc.printf("Packet not sent\r\n"); + return 0; } } int main()