0
\$\begingroup\$

I'm trying to use the SPBTLE-1S with 2 analog inputs and read the chip temperature setting, but it seems that if I try to change the mux, it results in garbled readings (eg, temperature reads -120C or the ADC1 reads 600mV, or ADC2 reads 3000mV -- not consistent).

I've tried running at a low speed (still garbled), and I tried reading (and discarding) the first 12 readings after changing the mux (still garbled).

If I read only a single channel, it works... so I'm thinking of completely disabling/enabling (DeInit / ReInit) between channels, but I was wondering if anyone knew of a better way...

Also... is there a better StackExchange place for this (and other questions -- right now the firmware runs, but it will trigger a HardFault when I try to connect to it)?

Some code:

...

  xADC_InitType.ADC_OSR = ADC_OSR_200;//ADC_OSR_32;                                                         //32KHz
  xADC_InitType.ADC_Input = ADC_CHANS[curchan];                                     //Select the channel
  xADC_InitType.ADC_ConversionMode = ADC_ConversionMode_Single;     //Single Conversion [this chip can't scan channels]
  xADC_InitType.ADC_ReferenceVoltage = ADC_ReferenceVoltage_0V6;    //Use the recommended 0.6V reference voltage
  xADC_InitType.ADC_Attenuation = ADC_Attenuation_9dB54;                    //Voltage range is 0..3v3

  ADC_Init(&xADC_InitType); //Configure

  /* Enable auto offset correction */
  ADC_Calibration(ENABLE);
  ADC_AutoOffsetUpdate(ENABLE);

    /* Start new conversion */
  ADC_Cmd(ENABLE);

...

 while(1)
  {
        //Handle data aquisition:
        //Check / Cycle the Analog Inputs
        if( ADC_GetFlagStatus(ADC_FLAG_EOC))
        {
            ADC_Results[curchan]=ADC_GetConvertedData(xADC_InitType.ADC_Input, xADC_InitType.ADC_ReferenceVoltage);
            if(++bump>10)
            { bump=0;
            //Now reset the ADC for the next one
            if(++curchan >= 0)//ADCCHANCNT)
            {
                curchan=0;
                scancomplete++;
            }
        }
            xADC_InitType.ADC_Input = ADC_CHANS[curchan];                                       //Select the channel
            ADC_Init(&xADC_InitType); //Configure

            /* Enable auto offset correction */
            ADC_Calibration(ENABLE);
            ADC_AutoOffsetUpdate(ENABLE);

            /* Start new conversion */
            ADC_Cmd(ENABLE);
        } //Else we don't have ADC data yet...

   if(scancomplete)
{
  scancomplete=0;
  //Process the data...
} //Else we're not done cycling through the channels yet.

...
}

ADC_Chans is an array of channels to be scanned; if I change the 0 to ADCCHANCNT (array size), the data comes back seemingly quite random, even if I lower the ADC speed or discard 'bump' readings before taking one and moving to the next (tested at 2,3,5,10, and 15).

On the other hand, if 0 is there (so it doesn't change the mux), I get nice, stable readings from the ADC... but I need to be able to read the ADC0, ADC1, and Temperature channels.

\$\endgroup\$
  • \$\begingroup\$ microchip.com/forums/m287602.aspx ??maybe helps \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Mar 11 at 17:51
  • \$\begingroup\$ I have no idea why this is a question about BLE, could you clarify? \$\endgroup\$ – pipe Mar 12 at 18:57
  • \$\begingroup\$ The SPBTLE-1S is a Bluetooth Low Energy module (FCC certified) and the sensor is going to be Bluetooth Low Energy Mesh enabled (if I can get the Hardfault to go away)... but if there's a better place for this question, I'm all ears -- it seems like ST's STM32 is a weird collection of devices with many different "oddities" in each of them. \$\endgroup\$ – Thor Johnson Mar 13 at 15:35
  • \$\begingroup\$ To have an answerable question here, you need to include the critical details in the question itself, for example explain exactly what you are attempting to do with the ADC and include the code in your question itself. \$\endgroup\$ – Chris Stratton Mar 13 at 16:12
  • \$\begingroup\$ Code and explanations of testing so far added... If anyone has an example of multi-channel ADC sampling with this module, I'd love to see it and learn the right way to do it! \$\endgroup\$ – Thor Johnson Mar 18 at 23:57
1
\$\begingroup\$

This Errata applies to this device. So you need to change the #define for the micro from 32MHz down to 16MHz. Note that this doesn't actually change the operating speed, it just fakes the CPU out, so all timed things will happen twice as fast (eg baud rates will be double what you set).

But the ADC will then work with multiple channels. And the ADC on this chip is nice and clean. I'm still working on "it blows up if you connect to it," because that seems to be specific to my code...

--- Blows up if you connect to it was a memory address error. But when I change the speed, it doesn't show up on the radio...

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.