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:

04 Aug 2014


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

Are you familiar with git/github? Please visit []] You can fix it and send a pull request.


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:

#if defined TARGET_STM // NXP rets 16bit, STM rets 12bit
value = (value << 4 | (value >> 8) & 0xF); // noralize 12bit > 16bit, NXP does in libs
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.

Please log in to post a reply.