Hope RFM95/98 power usage in sleep mode?


(Lorawanhere) #41

@bluejedi i will try to replace all the mdelay() / delay() statements with Serial.flush() and report back later…right now i don’t have much time…besides i need to experiment a bit with stm32 timers/isr http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/latest/timers.html using the stm32duino core


(Lorawanhere) #42

i’ve somehow managed to send data to TTN. it is shown in ttn applications>data section with proper variables with ABP. OTAA still doesn’t work…callback works properly now in ABP i can see TX_COMPLETE event. this is with the “official” stm32core which supports stm32 hal…https://github.com/stm32duino/Arduino_Core_STM32

In the current form the sketch looks like this: https://github.com/iotlearner0level/TTN-OLED-SENSORNODE-STM32/blob/master/v3oled.ino
lora modem (sx1278 based aithinker ra02) is connected to SPI1 an OLED ssd1306 is connected to i2c1 (pa6/7) bmp180 is connected to pa10/11 it takes power from gpio pins (low power device, so it should be ok) i’ve redefined bmp180.h and bmp180.c to used twowire on those two pins for the bmp. rest of the sketch is based on tomtor’s solar example but i’ve removed all the sleep statements. apparently, sleep in the official core works a bit different.

The keypoint was that we have to disable in the libraries nointerrupts and disablehal and it seems to work ok.

now i want two additional features:

  • I am testing various batteries (nimhx4, nicdx4, 1-18650 connected to Vin pin, 2x18650 lipo connected to Vin) so i also need to send Vcc voltage. How to get Vcc in stm32. method prescribed in original sketch doesn’t seem to work…
  • SLEEP Mode, which seem to work differently in the official core

thanks


(Tom Vijlbrief) #43

I am using this code to read the voltage without an external voltage divider:

int readVInt()
{
  adc_enable(ADC1);

  adc_reg_map *regs = ADC1->regs;
  regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and temp sensor
  regs->SMPR1 = (ADC_SMPR1_SMP17); // sample rate for VREFINT ADC channel

  int vref = 1210 * 4096 / adc_read(ADC1, 17); // ADC sample to millivolts
  regs->CR2 &= ~ADC_CR2_TSVREFE; // disable VREFINT and temp sensor
  return vref;
}

(Lorawanhere) #44

This gives compiler error for the hal enabled core at https://github.com/stm32duino/Arduino_Core_STM32 :
C:\Users\XYZ\Documents\Arduino\stm32\sketch_apr23a\sketch_apr23a.ino: In function ‘int readVInt()’:

sketch_apr23a:12: error: 'adc_enable' was not declared in this scope

   adc_enable(ADC1);

                  ^

sketch_apr23a:14: error: 'adc_reg_map' was not declared in this scope

   adc_reg_map *regs = ADC1->regs;

   ^~~~~~~~~~~

sketch_apr23a:14: error: 'regs' was not declared in this scope

   adc_reg_map *regs = ADC1->regs;

                ^~~~

sketch_apr23a:14: error: 'struct ADC_TypeDef' has no member named 'regs'

   adc_reg_map *regs = ADC1->regs;

                             ^~~~

sketch_apr23a:18: error: 'adc_read' was not declared in this scope

   int vref = 1210 * 4096 / adc_read(ADC1, 17); // ADC sample to millivolts

                                             ^

exit status 1
'adc_enable' was not declared in this scope

after some google search, hal adc for bluepill stm32f103 boards are defined here:

I can’t make much ot of it right now. maybe i’ve to spend lots of time to figure out how that works.


(Lorawanhere) #45

Just in case anyone is interested in the “official” stm32 core https://github.com/stm32duino/Arduino_Core_STM32

Based on fpiSTM’s suggestion from the stm32duino forums, we can read chip voltage & temperature using the following:

uint16_t adc_read(uint32_t channel)
{
  ADC_HandleTypeDef AdcHandle = {};
  ADC_ChannelConfTypeDef  AdcChannelConf = {};
  __IO uint16_t uhADCxConvertedValue = 0;

  AdcHandle.Instance = ADC1;
  AdcHandle.State = HAL_ADC_STATE_RESET;
  AdcHandle.Init.DataAlign             = ADC_DATAALIGN_RIGHT;           /* Right-alignment for converted data */
  AdcHandle.Init.ScanConvMode          = DISABLE;                       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
  AdcHandle.Init.ContinuousConvMode    = DISABLE;                       /* Continuous mode disabled to have only 1 conversion at each conversion trig */
  AdcHandle.Init.DiscontinuousConvMode = DISABLE;                       /* Parameter discarded because sequencer is disabled */
  AdcHandle.Init.ExternalTrigConv      = ADC_SOFTWARE_START;            /* Software start to trig the 1st conversion manually, without external event */
  AdcHandle.Init.NbrOfConversion       = 1;                             /* Specifies the number of ranks that will be converted within the regular group sequencer. */
  AdcHandle.Init.NbrOfDiscConversion   = 0;                             /* Parameter discarded because sequencer is disabled */

  if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {
    return 0;
  }

  AdcChannelConf.Channel      = channel;             /* Specifies the channel to configure into ADC */
  AdcChannelConf.Rank         = ADC_REGULAR_RANK_1;               /* Specifies the rank in the regular group sequencer */
  AdcChannelConf.SamplingTime = ADC_SAMPLETIME_13CYCLES_5;                     /* Sampling time value to be set for the selected channel */

  /*##-2- Configure ADC regular channel ######################################*/
  if (HAL_ADC_ConfigChannel(&AdcHandle, &AdcChannelConf) != HAL_OK)
  {
    /* Channel Configuration Error */
    return 0;
  }
  /*##-2.1- Calibrate ADC then Start the conversion process ####################*/
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) !=  HAL_OK) {
    /* ADC Calibration Error */
    return 0;
  }
  /*##-3- Start the conversion process ####################*/
  if (HAL_ADC_Start(&AdcHandle) != HAL_OK) {
    /* Start Conversation Error */
    return 0;
  }
  /*##-4- Wait for the end of conversion #####################################*/
  /*  For simplicity reasons, this example is just waiting till the end of the
      conversion, but application may perform other tasks while conversion
      operation is ongoing. */
  if (HAL_ADC_PollForConversion(&AdcHandle, 10) != HAL_OK) {
    /* End Of Conversion flag not set on time */
    return 0;
  }
  /* Check if the continous conversion of regular channel is finished */
  if ((HAL_ADC_GetState(&AdcHandle) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC) {
    /*##-5- Get the converted value of regular channel  ########################*/
    uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);
  }

  if (HAL_ADC_Stop(&AdcHandle) != HAL_OK) {
    /* Stop Conversation Error */
    return 0;
  }
  if(HAL_ADC_DeInit(&AdcHandle) != HAL_OK) {
    return 0;
  }
  return uhADCxConvertedValue;
}

void setup() {
  Serial.begin(115000);
  analogRead(A0); // Workaround to init g_current_pin used in HAL_ADC_MspInit
}

void loop() {
  float Vdd = readVdd();
  Serial.print("Vdd=  ");
  Serial.print(Vdd);
  Serial.print(" V Temp= ");
  Serial.print(readTempSensor(Vdd));
  Serial.println(" °C");
  delay(500);
}

static float readVdd()
{
  return (1.20 * 4096.0 / adc_read(ADC_CHANNEL_VREFINT)); // ADC sample to V
  //return (1200 * 4096 / adc_read(ADC_CHANNEL_VREFINT)); // ADC sample to mV
}

static float readTempSensor(float Vdd)
{
  return ((1.43 - (Vdd / 4096.0 * adc_read(ADC_CHANNEL_TEMPSENSOR))) / 0.0043 + 25.0);
}

I’ve also updated my sketch which now sends bmp180 Pressure,temperature, altitude, chip temperature and Vdd. Vdd is especially helpful in battery operated scenarios.

sketch is here:

https://github.com/iotlearner0level/TTN-OLED-SENSORNODE-STM32/blob/master/v4oled.ino

In addition, fpiSTM has indicated that sleep/low power API will be available soon, so it may be a matter of a few weeks or a month and we can use arduino library calls for low power without even using register stuff.

Just of reference, i’ve created a link to reading Vdd/chip temperature in official core just in case it is useful:


(Lorawanhere) #46

Just in case anyone interested, bluepill boards seem to work upto 2.0V@72Mhz. I’ve connected 4xNiMh to Vin (5V input) Fully charged it starts from 5.4V then keeps on dropping…I get around 10hours with everything running (around 80mA, approx 50mA for the bluepill+lora and another 30mA for an electrical parameter tester)

From the voltage levels reported by chip, it seems it works ok upto 2.0V along with the lora radio (aithinker ra02/sx1278) without any special low frequency mode. bmp180 (connected to GPIO pins for Vcc/GND) also seem to work. last correct reading shows voltage of 2.67V (for the stm32). but the oled did not work that low…

here is o/p from the TTN storage integration console:

  {
    "altitude": 173,
    "chipTemp": 45.51,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCPcRxw==",
    "temperature": 32.7,
    "time": "2018-04-26T15:08:31.886672246Z",
    "voltage": 2.295
  },
  {
    "altitude": 173,
    "chipTemp": 49.07,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCJwTKw==",
    "temperature": 32.7,
    "time": "2018-04-26T15:09:43.815344082Z",
    "voltage": 2.204
  },
  {
    "altitude": 173,
    "chipTemp": 48.57,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCK8S+Q==",
    "temperature": 32.7,
    "time": "2018-04-26T15:09:48.870310385Z",
    "voltage": 2.223
  },
  {
    "altitude": 173,
    "chipTemp": 47.48,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCKwSjA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:09:59.018495216Z",
    "voltage": 2.22
  },
  {
    "altitude": 173,
    "chipTemp": 48.14,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCKASzg==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:09.111891725Z",
    "voltage": 2.208
  },
  {
    "altitude": 172,
    "chipTemp": 47.36,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsCL0SgA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:14.443139847Z",
    "voltage": 2.237
  },
  {
    "altitude": 172,
    "chipTemp": 48.53,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsCJYS9Q==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:21.023027081Z",
    "voltage": 2.198
  },
  {
    "altitude": 173,
    "chipTemp": 48.65,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCI0TAQ==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:27.35627427Z",
    "voltage": 2.189
  },
  {
    "altitude": 172,
    "chipTemp": 49.24,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsCIYTPA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:33.76306509Z",
    "voltage": 2.182
  },
  {
    "altitude": 173,
    "chipTemp": 48.93,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCIETHQ==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:39.810258704Z",
    "voltage": 2.177
  },
  {
    "altitude": 173,
    "chipTemp": 49.44,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtCHcTUA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:10:45.594316777Z",
    "voltage": 2.167
  },
  {
    "altitude": 112,
    "chipTemp": 50.59,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCGoTww==",
    "temperature": 12.8,
    "time": "2018-04-26T15:10:54.261388134Z",
    "voltage": 2.154
  },
  {
    "altitude": 112,
    "chipTemp": 50.82,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCFkT2g==",
    "temperature": 12.8,
    "time": "2018-04-26T15:11:02.42113182Z",
    "voltage": 2.137
  },
  {
    "altitude": 112,
    "chipTemp": 50.96,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCE0T6A==",
    "temperature": 12.8,
    "time": "2018-04-26T15:11:10.264988356Z",
    "voltage": 2.125
  },
  {
    "altitude": 112,
    "chipTemp": 51.08,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCEQT9A==",
    "temperature": 12.8,
    "time": "2018-04-26T15:11:17.896079546Z",
    "voltage": 2.116
  },
  {
    "altitude": 112,
    "chipTemp": 51.41,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCD0UFQ==",
    "temperature": 12.8,
    "time": "2018-04-26T15:11:25.272545344Z",
    "voltage": 2.109
  },
  {
    "altitude": 112,
    "chipTemp": 50.77,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCDgT1Q==",
    "temperature": 12.8,
    "time": "2018-04-26T15:11:32.674394192Z",
    "voltage": 2.104
  },
  {
    "altitude": 112,
    "chipTemp": 52,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 999,
    "raw": "BQAD5wBwCCIUUA==",
    "temperature": 12.8,
    "time": "2018-04-26T15:11:41.797026116Z",
    "voltage": 2.082
  },
  {
    "altitude": 172,
    "chipTemp": 52.94,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsCA8Urg==",
    "temperature": 32.7,
    "time": "2018-04-26T15:11:47.370536356Z",
    "voltage": 2.063
  },
  {
    "altitude": 172,
    "chipTemp": 52.39,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsCAwUdw==",
    "temperature": 32.7,
    "time": "2018-04-26T15:11:52.945451005Z",
    "voltage": 2.06
  },
  {
    "altitude": 172,
    "chipTemp": 52.48,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsCAUUgA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:11:58.259530726Z",
    "voltage": 2.053
  },
  {
    "altitude": 173,
    "chipTemp": 52.8,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACtB/8UoA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:03.329723118Z",
    "voltage": 2.047
  },
  {
    "altitude": 172,
    "chipTemp": 52.65,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB/gUkQ==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:08.406844851Z",
    "voltage": 2.04
  },
  {
    "altitude": 172,
    "chipTemp": 53.55,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB/AU6w==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:13.211109286Z",
    "voltage": 2.032
  },
  {
    "altitude": 172,
    "chipTemp": 53.27,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB+sUzw==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:17.761658036Z",
    "voltage": 2.027
  },
  {
    "altitude": 172,
    "chipTemp": 54.03,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB+UVGw==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:22.332773405Z",
    "voltage": 2.021
  },
  {
    "altitude": 172,
    "chipTemp": 54.47,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB94VRw==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:26.623906536Z",
    "voltage": 2.014
  },
  {
    "altitude": 172,
    "chipTemp": 53.86,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB9cVCg==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:30.66988373Z",
    "voltage": 2.007
  },
  {
    "altitude": 172,
    "chipTemp": 54.36,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DMYD4ACsB9QVPA==",
    "temperature": 32.7,
    "time": "2018-04-26T15:12:34.728438098Z",
    "voltage": 2.004
  },
  {
    "altitude": 172,
    "chipTemp": 55.15,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DLsD4ACsB8oViw==",
    "temperature": 32.59,
    "time": "2018-04-26T15:12:43.351249396Z",
    "voltage": 1.994
  },
  {
    "altitude": 169,
    "chipTemp": 42.37,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 993,
    "raw": "DIkD4QCpDM4QjQ==",
    "temperature": 32.09,
    "time": "2018-04-26T15:48:49.328256588Z",
    "voltage": 3.278
  },
  {
    "altitude": 170,
    "chipTemp": 46.4,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 993,
    "raw": "DIkD4QCqDMESIA==",
    "temperature": 32.09,
    "time": "2018-04-26T15:50:02.785980618Z",
    "voltage": 3.265
  },
  {
    "altitude": 169,
    "chipTemp": 45.49,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 993,
    "raw": "DIkD4QCpDNMRxQ==",
    "temperature": 32.09,
    "time": "2018-04-26T15:51:17.9793614Z",
    "voltage": 3.283
  },
  {
    "altitude": 169,
    "chipTemp": 44.37,
    "device_id": "lora-gateway-node-ra01",
    "pressure": 992,
    "raw": "DJQD4ACpDNMRVQ==",
    "temperature": 32.2,
    "time": "2018-04-26T15:52:33.173748387Z",
    "voltage": 3.283
  },