![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
General testings
Fork of BEACON_CODE_NEW by
Diff: BCN.cpp
- Revision:
- 30:ca96cddf25d0
- Parent:
- 29:a864d57f10c4
- Child:
- 31:90cdfbadea91
--- a/BCN.cpp Mon Nov 02 14:09:45 2015 +0000 +++ b/BCN.cpp Mon Nov 02 14:46:12 2015 +0000 @@ -1,13 +1,15 @@ #include "BCN.h" +#include <stdio.h> +#include "pin_config.h" //Check the pin names //Takes max 4.3 sec in void FCTN_BCN_TX_MAIN() (temp.calc. + long_beacon + short_beacon) -Serial pc(USBTX, USBRX); //tx,rx -SPI spi(D11, D12, D13); // mosi, miso, sclk -DigitalOut cs(D10); //slave select or chip select -Timer t_i; -Timeout rf_sl_timeout; -Ticker loop; +Serial pc_bcn(USBTX, USBRX); //tx,rx +SPI spi(PIN16, PIN17, PIN15); // mosi, miso, sclk +DigitalOut cs(PIN6); //slave select or chip select +Timer t_i;//timer for checking the time taken by (temp.calc. + long_beacon + short_beacon) +Timeout rf_sl_timeout;//RF_silence timer +Ticker loop;//for transmitting every 10 secs //GLOBAL VARIABLES uint8_t BCN_INIT_STATUS = 0; @@ -20,21 +22,21 @@ void FCTN_BCN_INIT() { - pc.printf("FCTN_BCN_INIT\n"); + pc_bcn.printf("FCTN_BCN_INIT\n"); + Init_BEACON_HW(); BCN_INIT_STATUS = 1; - if(BCN_FEN == 0) - rf_sl_timeout.attach(&FCTN_BCN_FEN, 30); - Init_BEACON_HW(); + if(BCN_FEN == 0)//BCN_FEN is in flash + rf_sl_timeout.attach(&FCTN_BCN_FEN, RF_SILENCE_TIME); BCN_INIT_STATUS = 0; } void FCTN_BCN_FEN() { - pc.printf("FCTN_FEN\n"); + pc_bcn.printf("FCTN_FEN\n"); BCN_FEN = 1;//write this value to flash } void FCTN_BCN_TX_MAIN() { - pc.printf("FCTN_BCN_TX_MAIN\n"); + pc_bcn.printf("FCTN_BCN_TX_MAIN\n"); t_i.start(); int begin = t_i.read_us(); BCN_TX_MAIN_STATUS = 1; @@ -45,7 +47,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); + pc_bcn.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 ) { @@ -86,7 +88,7 @@ } t_i.stop(); int end = t_i.read_us(); - pc.printf("The time required for FCTN_BCN_TX_MAIN is %d useconds\r\n", end-begin); + pc_bcn.printf("The time required for FCTN_BCN_TX_MAIN is %d useconds\r\n", end-begin); } @@ -98,9 +100,9 @@ uint8_t check_Temperature() { uint8_t temperature; - writereg(RF22_REG_0F_ADC_CONFIGURATION,0x00); - writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20); - writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80); + writereg(RF22_REG_0F_ADC_CONFIGURATION,0x00);//set ADC to temp measurement + writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20);//measure in degree celsius + writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80);//start adc wait(0.1); temperature = readreg(RF22_REG_11_ADC_Value); temperature = (float)temperature*0.5 - 64; @@ -164,8 +166,9 @@ cs = 1; //Set to Tx mode - writereg(RF22_REG_07_OPERATING_MODE1,0x08); - wait(0.1); + writereg(RF22_REG_07_OPERATING_MODE1,0x08); //txon + wait(0.1);// takes time to set to tx mode hence the delay of 0.1. + //Check for fifoThresh while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break; timeout_count=10e5; @@ -173,7 +176,7 @@ //Check for packet_sent while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break; - //pc.printf("Short packet sent\r\n"); + //pc_bcn.printf("Short packet sent\r\n"); writereg(RF22_REG_07_OPERATING_MODE1,0x00); //standby mode @@ -206,7 +209,7 @@ //Set to Tx mode writereg(RF22_REG_07_OPERATING_MODE1,0x08); - wait(0.1); + wait(0.1);//necessary //Check for fifoThresh while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break; @@ -227,7 +230,7 @@ //Check for packetsent interrupt while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break; - //pc.printf("Long packet sent\r\n"); + //pc_bcn.printf("Long packet sent\r\n"); writereg(RF22_REG_07_OPERATING_MODE1,0x00); //standby mode } @@ -299,9 +302,9 @@ //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_bcn.printf("spi connection valid\r\n"); else - {pc.printf("error in spi connection\r\n"); + {pc_bcn.printf("error in spi connection\r\n"); reset_rfm(); } @@ -328,7 +331,7 @@ if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00) { - pc.printf("frequency not set properly\r\n"); + pc_bcn.printf("frequency not set properly\r\n"); reset_rfm(); } @@ -354,11 +357,11 @@ } else { - pc.printf("Packet not sent\r\n"); + pc_bcn.printf("Packet not sent\r\n"); return 0; } } -int main() +/*int main() { FCTN_BCN_INIT(); @@ -366,4 +369,4 @@ while(1); -} \ No newline at end of file +}*/ \ No newline at end of file