Nucleo's AnalogIn::read_u16 function returns 0..4095.

04 Aug 2014

Nucleo's AnalogIn::read_u16 function returns values between 0 and 4095. However, the document on read_u16 function says the function returns "16-bit unsigned short representing the current input voltage, normalised to a 16-bit value." So it should return values between 0 and 0xfff0(65520). For better compatibility with other mbed microcontrollers, I want the bug to be fixed.

Please refer: https://mbed.org/questions/4239/AnalogInread_u16-function-returns-04095-/

04 Aug 2014

Hello,

this is not just nucleo , It looks to me that other targets do the same.

Are you familiar with git/github? Please visit [http://mbed.org/handbook/mbed-tools]] You can fix it and send a pull request.

Regards,
0xc0170

04 Aug 2014

Which others would that be? I quickly checked most NXP targets, and they all do it correctly. The Freescale ones all are set for 16-bit mode, so also work correctly. Only the Nordic also seems to do it wrong.

20 Aug 2014

For LPC1768, read_u16() reads 12bit from hw and convert/normalize to 16bit, for Nucleos it does not, so i do it manually in my program:

value=anin.read_u16();
#if defined TARGET_STM // NXP rets 16bit, STM rets 12bit
value = (value << 4 | (value >> 8) & 0xF); // noralize 12bit > 16bit, NXP does in libs
#endif
20 Aug 2014

That works yes, but it shouldn't be required. The reason to make a standard library is exactly to prevent being forced to use ifdefs for each target.