STM32duino+emonlib - strange behavior

I’m not sure. In that part

  #if defined(__AVR__)
  delay(2);                                        // Wait for Vref to settle
  ADCSRA |= _BV(ADSC);                             // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = READVCC_CALIBRATION_CONST / result;  //1100mV*1024 ADC steps http://openenergymonitor.org/emon/node/1186
  return result;
  #elif defined(__arm__)
  return (3300);                                  //Arduino Due
  #else
  return (3300);                                  //Guess that other un-supported architectures will be running a 3.3V!
  #endif
}

three cases: for AVR, arm and other processor types.

But this types must be defined somewhere.

AFAIK it’s part of the Arduino IDE compiler. Take a look at this Arduino forum post Identifying Due in Libraries - Arduino Due - Arduino Forum

1 Like

@mel
Is __arm__ set for you? Print it and see. In setup for your sketch, put

#ifdef(__arm__)
Serial.println("__arm__ is defined");
#endif

If it says it is, then you should be OK. If not, then the safest solution for you, unless you can find something set by your choice of board in the IDE, is what I wrote in post 18 above.

1 Like

Code that works for me

 #if defined (__arm__)
Serial.println("__arm__ is defined");
#endif

Result is positive

__arm__ is defined

Seems that processor is detected as arm, which means that library works in 12bit mode.

@Robert.Wall and @GeorgeB thank you for your support

1 Like