AnsweredAssumed Answered

KL17 ADC always returns 0xff

Question asked by John Demayor on Sep 19, 2016
Latest reply on Sep 28, 2016 by Robin_Shen

Hi there,


I've been trying to get a really barebone example running of the ADC functionality on the KL17. I can't seem to get the microcontroller to return anything else than 0xff. At first, I thought I did something wrong with wires on the board, but then I changed the code to sample the internal temperature sensor of the KL17 - which also returned 0xff. I must be doing wrong something really basic; please take a look at my code:


#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_device_registers.h"

int main(void) {
     uint16_t data = 0;

     /* Init board hardware. */

     // Enable clock to ADC peripheral
     SIM->SCGC6           |= (1<<27);                    // ADC0 clock enable

     // Registers
     ADC0->CFG1          = 0b00000001;                // ClockDiv=1, 8 bit mode, Bus clock / 2
     ADC0->CFG2          = 0b00001000;               // Fastest sample time (for low impedance sources)
     ADC0->SC3            = 0b00000000;               // No continuous conversion, no hardware average
     ADC0->SC2            = 0b00000000;               // Default register setup
     ADC0->SC1[0]      = 0b00011111;               // Channel all '1' means disable
    // ADC test code
         ADC0->SC1[0]     = 0b00011010;               // Temperature sensor, auto starts conversion

          while(ADC0->SC2 & (1<<7));                    // Conversion active or hardware averaging in progress
          while(!(ADC0->SC1[0] & (1<<7)));          // Wait for conversion to complete
          data = ADC0->R[0];                              // Return result


Please help me on this - thanks a lot in advance!