I want to use the 16bit differential ADC on the FRDM MCXN947 dev board. I cannot get the configuration correct. See the screenshots attached to see the configuration in Config Tools. My main code is added as code sample, could someone help me figure out why I cannot get a result from the ADC.
/*
* Copyright 2016-2024 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file ADC_test4.c
* @brief Application entry point.
*/
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MCXN947_cm33_core0.h"
#include "fsl_debug_console.h"
#include "fsl_lpadc.h"
#include "fsl_ctimer.h"
#include "fsl_spc.h"
/*******************************************************************************
* Variables
******************************************************************************/
volatile uint32_t adcResult = 0U;
volatile bool g_LpadcConversionCompletedFlag = false;
lpadc_conv_result_t convResult;
/*******************************************************************************
* Definitions
******************************************************************************/
/* ADC IRQ handler */
void ADC0_IRQHandler(void) {
PRINTF("ADC0 interrupt triggered\n");
#if (defined(FSL_FEATURE_LPADC_FIFO_COUNT) && (FSL_FEATURE_LPADC_FIFO_COUNT == 2U))
if (LPADC_GetConvResult(ADC0, &convResult, 0U))
#else
if (LPADC_GetConvResult(ADC0, &convResult))
#endif /* FSL_FEATURE_LPADC_FIFO_COUNT */
{
g_LpadcConversionCompletedFlag = true;
}
SDK_ISR_EXIT_BARRIER;
}
/*!
* @brief Main function
*/
int main(void) {
/* Init board hardware. */
SPC_EnableActiveModeAnalogModules(SPC0, kSPC_controlVref);
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
BOARD_InitDebugConsole();
/* Enable interrupts for ADC0 */
LPADC_EnableInterrupts(ADC0, kLPADC_Trigger0CompletionInterruptEnable | kLPADC_FIFO0WatermarkInterruptEnable);
EnableIRQ(ADC0_IRQn);
PRINTF("Please input any character to get the ADC result\r\n");
while (1) {
GETCHAR();
LPADC_DoSoftwareTrigger(ADC0, 1U);
while(!g_LpadcConversionCompletedFlag) {
}
PRINTF("ADC Result: %d\n", convResult.convValue);
g_LpadcConversionCompletedFlag = false;
}
return 0;
}
Hello @Dirk3
Please check below settings.
1> Use oscilloscope confirm there is input signal in ADC channel of your board.
2>Config ADC input pin correctly.
3>Enabled clock.
4>Using ADC demo under SDK to test firstly, whether can work without any issue?
BR
Alice