
hello world
Dependencies: lib_gps lib_mpl3115a2 lmic_MOTE_L152RC mbed
Fork of lmic_NAmote_GPS by
Revision 3:d81e4a63fb2e, committed 2015-07-17
- Comitter:
- dudmuck
- Date:
- Fri Jul 17 21:11:02 2015 +0000
- Parent:
- 2:a8f00db60fdb
- Child:
- 4:f9aaf0f82c00
- Commit message:
- enable HSI for ADC from deep sleep, add TX limit for low battery
Changed in this revision
--- a/config.h Thu Jul 02 01:03:13 2015 +0000 +++ b/config.h Fri Jul 17 21:11:02 2015 +0000 @@ -1,3 +1,5 @@ #define CFG_us915 -#define CFG_sx1272_radio \ No newline at end of file +#define CFG_sx1272_radio + +//#define CHNL_HYBRID \ No newline at end of file
--- a/lmic_MOTE_L152RC.lib Thu Jul 02 01:03:13 2015 +0000 +++ b/lmic_MOTE_L152RC.lib Fri Jul 17 21:11:02 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Semtech/code/lmic_MOTE_L152RC/#d87012f45bf6 +https://developer.mbed.org/teams/Semtech/code/lmic_MOTE_L152RC/#e4ba433f0ac1
--- a/main.cpp Thu Jul 02 01:03:13 2015 +0000 +++ b/main.cpp Fri Jul 17 21:11:02 2015 +0000 @@ -61,7 +61,8 @@ I2C i2c(I2C_SDA, I2C_SCL); DigitalIn i2c_int_pin(PB_4); MPL3115A2 mpl3115a2(i2c, i2c_int_pin); -AnalogIn bat(PA_0); +AnalogIn *bat; +#define LOW_BAT_THRESHOLD 3.45 ////////////////////////////////////////////////// // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW) @@ -136,11 +137,13 @@ first = pc_1; pc_7 = 0; if (first && !pc_1) { - //printf("v2-mote\r\n"); mote_version = MOTE_V2; + printf("v2\r\n"); + bat = new AnalogIn(PA_0); } else { - //printf("v3-mote\r\n"); mote_version = MOTE_V3; + printf("v3\r\n"); + bat = new AnalogIn(PA_1); } } @@ -204,12 +207,31 @@ led1 = 1; } +static void +restore_hsi() +{ + RCC_OscInitTypeDef osc_init; + /* if HSI was shut off in deep sleep (needed for AnalogIn) */ + HAL_RCC_GetOscConfig(&osc_init); + if (osc_init.HSIState != RCC_HSI_ON) { + // Enable the HSI (to clock the ADC) + osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSI; + osc_init.HSIState = RCC_HSI_ON; + osc_init.PLL.PLLState = RCC_PLL_NONE; + HAL_RCC_OscConfig(&osc_init); + } +} + static bool AppLedStateOn = false; +#define AIN_VREF 3.3 // stm32 internal refernce +#define AIN_VBAT_DIV 2 // resistor divider static void PrepareDataFrame( void ) { uint16_t altitudeGps; - //int i; + float volts; + + restore_hsi(); gps.service(); printf("lat:%f long:%f\r\n", gps.Latitude, gps.Longitude); @@ -221,7 +243,8 @@ //LMIC.frame[0] = LMIC.rxq.snr; LMIC.frame[0] = AppLedStateOn; // (bit 0 == 1) => LED on LMIC.frame[1] = (int)mpl3115a2.Temperature; // Signed degrees Celcius in half degree units. So, +/-63 C - LMIC.frame[2] = (bat.read_u16() >> 8) + (bat.read_u16() >> 9) ; // per LoRaMAC spec; 0=Charging; 1...254 = level, 255 = N/A + LMIC.frame[2] = (bat->read_u16() >> 8) + (bat->read_u16() >> 9) ; // per LoRaMAC spec; 0=Charging; 1...254 = level, 255 = N/A + LMIC.frame[3] = ( gps.LatitudeBinary >> 16 ) & 0xFF; LMIC.frame[4] = ( gps.LatitudeBinary >> 8 ) & 0xFF; LMIC.frame[5] = gps.LatitudeBinary & 0xFF; @@ -230,9 +253,21 @@ LMIC.frame[8] = gps.LongitudeBinary & 0xFF; altitudeGps = atoi(gps.NmeaGpsData.NmeaAltitude); - printf("alt:%d\r\n", altitudeGps); + //printf("alt:%d\r\n", altitudeGps); LMIC.frame[9] = ( altitudeGps >> 8 ) & 0xFF; LMIC.frame[10] = altitudeGps & 0xFF; + + volts = bat->read()*AIN_VREF*AIN_VBAT_DIV; + printf("bat:%.2f\r\n", volts); +#ifdef CHNL_HYBRID + LMIC.txpow_limit = 20; +#else + if (volts < LOW_BAT_THRESHOLD) + LMIC.txpow_limit = 20; + else + LMIC.txpow_limit = 30; +#endif /* !CHNL_HYBRID */ + } static void onSendFrame (osjob_t* j) {