11 years, 6 months ago.

query regarding function definition

can I get the definition of the function "analogin_read_u16(&_adc)"?

2 Answers

11 years, 6 months ago.

Hello prasanna hegde,

for what platform do you need a definition? Here's a code from KLxx platforms (KL25Z for example):

uint16_t analogin_read_u16(analogin_t *obj) {
    // start conversion
    ADC0->SC1[0] = ADC_SC1_ADCH(obj->adc & ~(1 << CHANNELS_A_SHIFT));

    // Wait Conversion Complete
    while ((ADC0->SC1[0] & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK);

    // Return value
    return (uint16_t)ADC0->R[0];
}

Thsi code is available in the online compiler (mbed-src) or on github https://github.com/mbedmicro/mbed.

Regards,
0xc0170

Accepted Answer

ADC in lpc1768 is of 12 bits, but the function returns 16 bit number. Is it right if we use the 16 bit number? Do we need to AND the return value with 0x0FFFh to get 12 bit number?

posted by prasanna hegde 26 Mar 2014
11 years, 6 months ago.

It returns an unsigned 16 bit value for the analog input specified, exactly how it does that will depend on the platform you are using. The whole point of the mbed API is that you shouldn't need to worry about what's going on after that point, if you need more control than the API gives you then you may need to fall back to accessing the platform specific CPU registers.