pradeep shekhar
/
Beacon_BAE_intergration_test_3
General testings
Fork of BEACON_CODE_NEW by
Revision 20:a7dbfbc462f1, committed 2015-10-27
- Comitter:
- shekhar
- Date:
- Tue Oct 27 13:15:47 2015 +0000
- Parent:
- 19:de2bb3b0b0d2
- Child:
- 21:8826cc77ada8
- Commit message:
- minor bug fix
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 Tue Oct 27 11:50:05 2015 +0000 +++ b/beacon.h Tue Oct 27 13:15:47 2015 +0000 @@ -28,14 +28,14 @@ void P_BCN_FEN(); void P_BCN_TX_MAIN(); void Set_BCN_TX_STATUS(uint8_t); -int check_Temperature(); +uint8_t check_Temperature(); void SHORT_BCN_TX(); void LONG_BCN_TX(); void Init_BEACON_HW(); void writereg(uint8_t,uint8_t); uint8_t readreg(uint8_t); void clearTxBuf(); -int setFrequency(double,float); +uint8_t setFrequency(double,float); bool Check_ACK_RECEIVED(); void reset_uC();
--- a/main.cpp Tue Oct 27 11:50:05 2015 +0000 +++ b/main.cpp Tue Oct 27 13:15:47 2015 +0000 @@ -5,10 +5,12 @@ SPI spi(D11, D12, D13); // mosi, miso, sclk DigitalOut cs(D10); //slave select or chip select Timer t; +Timer t_i; Ticker loop; void P_BCN_INIT() { + //pc.printf("P_BCN_INIT\n"); BCN_INIT_STATUS = 1; Init_BEACON_HW(); if (BCN_FEN == 0) @@ -17,10 +19,12 @@ } void P_BCN_FEN() { + //pc.printf("P_FEN\n"); BCN_FEN = 1;//write this value to flash } void P_BCN_TX_MAIN() { + //pc.printf("P_BCN_TX_MAIN\n"); BCN_TX_MAIN_STATUS = 1; if(BCN_FEN == 1) @@ -29,7 +33,7 @@ { //Measure and store BCN temperature in BCN_TS_BUFFER BCN_TS_BUFFER = check_Temperature(); - + //pc.printf("\n\ntemperature = %d\n\n",BCN_TS_BUFFER); //Get BCN_HK data from BCN HW(SPI) //Store BCN_HK data in BCN_HK_BUFFER if(BCN_STANDBY == 1 ) { @@ -40,8 +44,13 @@ } else { //transmit short beacon and long beacon + //t_i.start(); + //int begin = t_i.read_us(); SHORT_BCN_TX(); LONG_BCN_TX(); + //t_i.stop(); + //int end = t_i.read_us(); + //pc.printf("The time required for short and long is %d seconds\r\n", end-begin); if(Check_ACK_RECEIVED() == 1) { @@ -74,9 +83,9 @@ BCN_TX_STATUS = STATUS; } -int check_Temperature() +uint8_t check_Temperature() { - int temperature; + uint8_t temperature; writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80); writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20); wait(1); @@ -114,7 +123,7 @@ clearTxBuf(); //writing data first time - int byte = 0; + uint8_t byte = 0; cs = 0; spi.write(0xFF); @@ -215,22 +224,40 @@ } void reset_uC() { - printf("reset uC"); + P_BCN_INIT(); } void writereg(uint8_t reg,uint8_t val) { - int read_val =0; cs = 0;spi.write(reg | 0x80);spi.write(val);cs = 1;read_val = readreg(reg);if(read_val != val) reset_uC(); -} + uint8_t count = 0; + for(;;count++) + { + int read_val =0; cs = 0;spi.write(reg | 0x80);spi.write(val);cs = 1; + if(reg != 0x7 && reg != 0x58 && reg != 0xF) + { + read_val = readreg(reg); + if (read_val == val) + { + break; + } + else if(count == 5) + { + reset_uC();break; + } + } + else + break; + } +} uint8_t readreg(uint8_t reg) { - int val;cs = 0;spi.write(reg & ~0x80);val = spi.write(0);cs = 1;return val; + uint8_t val;cs = 0;spi.write(reg & ~0x80);val = spi.write(0);cs = 1;return val; } void clearTxBuf() { writereg(RF22_REG_08_OPERATING_MODE2,0x01); writereg(RF22_REG_08_OPERATING_MODE2,0x00); } -int setFrequency(double centre,float afcPullInRange) +uint8_t setFrequency(double centre,float afcPullInRange) { uint8_t fbsel = 0x40; uint8_t afclimiter;