![]() |
MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides a peripheral driver for the 12-bit 5MSPS Analog-to-Digital Converter (HSADC) module of MCUXpresso SDK devices.
Modules | |
HSADC Peripheral driver | |
Data Structures | |
struct | hsadc_config_t |
Defines the structure for configuring the HSADC's common setting. More... | |
struct | hsadc_converter_config_t |
Defines the structure for configuring each converter. More... | |
struct | hsadc_sample_config_t |
Defines the structure for configuring the sample slot. More... | |
Macros | |
#define | FSL_HSADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
HSADC driver version. More... | |
#define | HSADC_SAMPLE_MASK(index) (1U << (index)) |
Converter index to mask for sample slot. More... | |
#define | HSADC_CALIBRATION_VALUE_A_SINGLE_ENDED_MASK HSADC_CALVAL_A_CALVSING_MASK |
Bit mask of calibration value for converter A in single ended mode. More... | |
#define | HSADC_CALIBRATION_VALUE_A_SINGLE_ENDED_SHIFT HSADC_CALVAL_A_CALVSING_SHIFT |
Bit shift of calibration value for converter A in single ended mode. More... | |
#define | HSADC_CALIBRATION_VALUE_A_DIFFERENTIAL_MASK HSADC_CALVAL_A_CALVDIF_MASK |
Bit mask of calibration value for converter A in differential mode. More... | |
#define | HSADC_CALIBRATION_VALUE_A_DIFFERENTIAL_SHIFT HSADC_CALVAL_A_CALVDIF_SHIFT |
Bit shift of calibration value for converter A in differential mode. More... | |
#define | HSADC_CALIBRATION_VALUE_B_SINGLE_ENDED_MASK (HSADC_CALVAL_B_CALVSING_MASK << 16U) |
Bit mask of calibration value for converter B in single ended mode. More... | |
#define | HSADC_CALIBRATION_VALUE_B_SINGLE_ENDED_SHIFT (HSADC_CALVAL_B_CALVSING_SHIFT + 16U) |
Bit shift of calibration value for converter B in single ended mode. More... | |
#define | HSADC_CALIBRATION_VALUE_B_DIFFERENTIAL_MASK (HSADC_CALVAL_B_CALVDIF_MASK << 16U) |
Bit mask of calibration value for converter B in differential mode. More... | |
#define | HSADC_CALIBRATION_VALUE_B_DIFFERENTIAL_SHIFT (HSADC_CALVAL_B_CALVDIF_SHIFT + 16U) |
Bit shift of calibration value for converter B in differential mode. More... | |
HSADC Initialization and deinitialization. | |
void | HSADC_Init (HSADC_Type *base, const hsadc_config_t *config) |
Initializes the HSADC module. More... | |
void | HSADC_GetDefaultConfig (hsadc_config_t *config) |
Gets an available pre-defined settings for module's configuration. More... | |
void | HSADC_Deinit (HSADC_Type *base) |
De-initializes the HSADC module. More... | |
Converter. | |
void | HSADC_SetConverterConfig (HSADC_Type *base, uint16_t converterMask, const hsadc_converter_config_t *config) |
Configures the converter. More... | |
void | HSADC_GetDefaultConverterConfig (hsadc_converter_config_t *config) |
Gets an available pre-defined settings for each converter's configuration. More... | |
void | HSADC_EnableConverter (HSADC_Type *base, uint16_t converterMask, bool enable) |
Enables the converter's conversion. More... | |
void | HSADC_EnableConverterSyncInput (HSADC_Type *base, uint16_t converterMask, bool enable) |
Enables the input of an external sync signal. More... | |
void | HSADC_EnableConverterPower (HSADC_Type *base, uint16_t converterMask, bool enable) |
Enables power for the converter. More... | |
void | HSADC_DoSoftwareTriggerConverter (HSADC_Type *base, uint16_t converterMask) |
Triggers the converter by using the software trigger. More... | |
void | HSADC_EnableConverterDMA (HSADC_Type *base, uint16_t converterMask, bool enable) |
Enables the DMA feature. More... | |
void | HSADC_EnableInterrupts (HSADC_Type *base, uint16_t mask) |
Enables the interrupts. More... | |
void | HSADC_DisableInterrupts (HSADC_Type *base, uint16_t mask) |
Disables the interrupts. More... | |
uint16_t | HSADC_GetStatusFlags (HSADC_Type *base) |
Gets the status flags. More... | |
void | HSADC_ClearStatusFlags (HSADC_Type *base, uint16_t mask) |
Clears the status flags. More... | |
Sample. | |
void | HSADC_SetSampleConfig (HSADC_Type *base, uint16_t sampleIndex, const hsadc_sample_config_t *config) |
Configures the sample slot. More... | |
void | HSADC_GetDefaultSampleConfig (hsadc_sample_config_t *config) |
Gets the default sample configuration. More... | |
static void | HSADC_EnableSample (HSADC_Type *base, uint16_t sampleMask, bool enable) |
Enables the sample slot. More... | |
static void | HSADC_EnableSampleResultReadyInterrupts (HSADC_Type *base, uint16_t sampleMask, bool enable) |
Enables the interrupt for each sample slot when its result is ready. More... | |
static uint16_t | HSADC_GetSampleReadyStatusFlags (HSADC_Type *base) |
Returns the sample ready flags of sample slots. More... | |
static uint16_t | HSADC_GetSampleLowLimitStatusFlags (HSADC_Type *base) |
Gets the low-limit flags of sample slots. More... | |
static void | HSADC_ClearSampleLowLimitStatusFlags (HSADC_Type *base, uint16_t sampleMask) |
Clears low-limit flags of sample slots. More... | |
static uint16_t | HSADC_GetSampleHighLimitStatusFlags (HSADC_Type *base) |
Gets the high-limit flags of sample slots. More... | |
static void | HSADC_ClearSampleHighLimitStatusFlags (HSADC_Type *base, uint16_t sampleMask) |
Clears high-limit flags of sample slots. More... | |
static uint16_t | HSADC_GetSampleZeroCrossingStatusFlags (HSADC_Type *base) |
Gets the zero crossing flags of sample slots. More... | |
static void | HSADC_ClearSampleZeroCrossingStatusFlags (HSADC_Type *base, uint16_t sampleMask) |
Clears zero crossing flags of sample slots. More... | |
static uint16_t | HSADC_GetSampleResultValue (HSADC_Type *base, uint16_t sampleIndex) |
Gets the sample result value. More... | |
Calibration. | |
void | HSADC_DoAutoCalibration (HSADC_Type *base, uint16_t converterMask, uint16_t calibrationModeMask) |
Starts the hardware calibration. More... | |
uint32_t | HSADC_GetCalibrationResultValue (HSADC_Type *base) |
Gets the calibration result value. More... | |
void | HSADC_EnableCalibrationResultValue (HSADC_Type *base, uint16_t converterMask, bool enable) |
Enables or disables the calibration result value. More... | |
struct hsadc_config_t |
Data Fields | |
hsadc_dual_converter_scan_mode_t | dualConverterScanMode |
Dual converter's scan mode. More... | |
bool | enableSimultaneousMode |
Using Simultaneous mode. More... | |
hsadc_resolution_t | resolution |
Resolution mode. More... | |
hsadc_dma_trigger_source_t | DMATriggerSoruce |
DMA trigger source. More... | |
hsadc_idle_work_mode_t | idleWorkMode |
Converter's work mode when idle. More... | |
uint16_t | powerUpDelayCount |
Delay count united as 32 clocks to wait for the clock to be stable. More... | |
hsadc_dual_converter_scan_mode_t hsadc_config_t::dualConverterScanMode |
bool hsadc_config_t::enableSimultaneousMode |
hsadc_resolution_t hsadc_config_t::resolution |
hsadc_dma_trigger_source_t hsadc_config_t::DMATriggerSoruce |
hsadc_idle_work_mode_t hsadc_config_t::idleWorkMode |
uint16_t hsadc_config_t::powerUpDelayCount |
Available range is 0-63.
struct hsadc_converter_config_t |
Data Fields | |
uint16_t | clockDivisor |
Converter's clock divisor for the clock source. More... | |
uint16_t | samplingTimeCount |
Sampling time count. More... | |
uint16_t | powerUpCalibrationModeMask |
Calibration mode mask in the power up period. More... | |
uint16_t hsadc_converter_config_t::clockDivisor |
Available range is 2-64.
uint16_t hsadc_converter_config_t::samplingTimeCount |
The resultant sampling time is (1.5 + samplingTimeCount) x clock period. Available range is 0-255.
uint16_t hsadc_converter_config_t::powerUpCalibrationModeMask |
See the "_hsadc_calibration_mode". If this field isn't zero, call the function HSADC_GetStatusFlags() to check whether the End of Calibration flag is set to wait for sthe calibration process to complete. If this is zero, it indicates no calibration is executed in power up period.
struct hsadc_sample_config_t |
channelNumber, channel67MuxNumber, and enableDifferentialPair have following relationship: channelNumber equals 0~7 represents channel 0~7 of converter A. channelNumber equals 8~15 represents channel 0~7 of converter B. 1) When channelNumber = 6 and enableDifferentialPair = false, channel67MuxNumber represents converter A's channel 6's sub multiplex channel number. 2) When channelNumber = 6 and enableDifferentialPair = true, channel67MuxNumber represents converter A's channel 6 and channel 7's sub multiplex channel number. 3) When channelNumber = 7 and enableDifferentialPair = false, channel67MuxNumber represents converter A's channel 7's sub multiplex channel number. 4) When channelNumber = 7 and enableDifferentialPair = true, channel67MuxNumber represents converter A's channel 6 and channel 7's sub multiplex channel number. 5) When channelNumber = 14 and enableDifferentialPair = false, channel67MuxNumber represents converter B's channel 6's sub multiplex channel number. 6) When channelNumber = 14 and enableDifferentialPair = true, channel67MuxNumber represents converter B's channel 6 and channel 7's sub multiplex channel number. 7) When channelNumber = 15 and enableDifferentialPair = false, channel67MuxNumber represents converter B's channel 7's sub multiplex channel number. 8) When channelNumber = 15 and enableDifferentialPair = true, channel67MuxNumber represents converter B's channel 6 and channel 7's sub multiplex channel number. 9) In other cases, channel67MuxNumber won't be functional.
Data Fields | |
uint16_t | channelNumber |
Channel number. More... | |
uint16_t | channel67MuxNumber |
Channel 6/7's sub multiplex channel number. More... | |
bool | enableDifferentialPair |
Use differential sample input or not. More... | |
hsadc_zero_crossing_mode_t | zeroCrossingMode |
Zero crossing mode. More... | |
uint16_t | highLimitValue |
High-limit value. More... | |
uint16_t | lowLimitValue |
Low-limit value. More... | |
uint16_t | offsetValue |
Offset value. More... | |
bool | enableWaitSync |
Wait for sync input to launch this sample's conversion or not. More... | |
uint16_t hsadc_sample_config_t::channelNumber |
Available range is 0-15.
uint16_t hsadc_sample_config_t::channel67MuxNumber |
When channelNumber = 6 or 14, its available range is 0~6. When channelNumber = 7 or 15, its available range is 0~5.
bool hsadc_sample_config_t::enableDifferentialPair |
In differential mode, the sub multiplex channel number of channel 6 and channel 7 must be configured to be same.
hsadc_zero_crossing_mode_t hsadc_sample_config_t::zeroCrossingMode |
uint16_t hsadc_sample_config_t::highLimitValue |
Original value format as hardware register, with 3-bits left shifted.
uint16_t hsadc_sample_config_t::lowLimitValue |
Original value format as hardware register, with 3-bits left shifted.
uint16_t hsadc_sample_config_t::offsetValue |
Original value format as hardware register, with 3-bits left shifted.
bool hsadc_sample_config_t::enableWaitSync |
#define FSL_HSADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
#define HSADC_SAMPLE_MASK | ( | index | ) | (1U << (index)) |
#define HSADC_CALIBRATION_VALUE_A_SINGLE_ENDED_MASK HSADC_CALVAL_A_CALVSING_MASK |
#define HSADC_CALIBRATION_VALUE_A_SINGLE_ENDED_SHIFT HSADC_CALVAL_A_CALVSING_SHIFT |
#define HSADC_CALIBRATION_VALUE_A_DIFFERENTIAL_MASK HSADC_CALVAL_A_CALVDIF_MASK |
#define HSADC_CALIBRATION_VALUE_A_DIFFERENTIAL_SHIFT HSADC_CALVAL_A_CALVDIF_SHIFT |
#define HSADC_CALIBRATION_VALUE_B_SINGLE_ENDED_MASK (HSADC_CALVAL_B_CALVSING_MASK << 16U) |
#define HSADC_CALIBRATION_VALUE_B_SINGLE_ENDED_SHIFT (HSADC_CALVAL_B_CALVSING_SHIFT + 16U) |
#define HSADC_CALIBRATION_VALUE_B_DIFFERENTIAL_MASK (HSADC_CALVAL_B_CALVDIF_MASK << 16U) |
#define HSADC_CALIBRATION_VALUE_B_DIFFERENTIAL_SHIFT (HSADC_CALVAL_B_CALVDIF_SHIFT + 16U) |
enum _hsadc_status_flags |
enum _hsadc_converter_id |
enum hsadc_resolution_t |
void HSADC_Init | ( | HSADC_Type * | base, |
const hsadc_config_t * | config | ||
) |
This function initializes the HSADC module. The operations are:
base | HSADC peripheral base address. |
config | Pointer to configuration structure. See the "hsadc_config_t". |
void HSADC_GetDefaultConfig | ( | hsadc_config_t * | config | ) |
This function initializes the module's configuration structure with an available settings. The default value are:
config | Pointer to configuration structure. See the "hsadc_config_t" |
void HSADC_Deinit | ( | HSADC_Type * | base | ) |
This function de-initializes the HSADC module. The operations are:
base | HSADC peripheral base address. |
void HSADC_SetConverterConfig | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
const hsadc_converter_config_t * | config | ||
) |
base | HSADC peripheral base address. |
converterMask | Mask for converters to be configured. See the "_hsadc_converter_id". |
config | Pointer to configuration structure. See the "hsadc_converter_config_t". |
void HSADC_GetDefaultConverterConfig | ( | hsadc_converter_config_t * | config | ) |
This function initializes each converter's configuration structure with available settings. The default value are:
config | Pointer to configuration structure. See the "hsadc_converter_config_t" |
void HSADC_EnableConverter | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
bool | enable | ||
) |
This function enables the converter's conversion by making the converter exit stop mode. The conversion should only be launched after the converter is enabled. When this feature is asserted to be "false", the current scan is stopped and no further scans can start. All the software and hardware triggers are ignored.
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
enable | Enable or disable the feature. |
void HSADC_EnableConverterSyncInput | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
bool | enable | ||
) |
This function enables the input of the external sync signal. The external sync signal could be used to trigger the conversion if the hardware trigger-related setting is used. Note: When in "Once" scan mode, this gate is off automatically after an available sync is received. Enable the input again manually if another sync signal is needed.
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
enable | Enable or disable the feature. |
void HSADC_EnableConverterPower | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
bool | enable | ||
) |
This function enables the power for the converter. The converter should be powered on before conversion. Once this API is called, the converter is powered on after a few moments (so-called power up delay) to make the power stable.
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
enable | Enable or disable the feature. |
void HSADC_DoSoftwareTriggerConverter | ( | HSADC_Type * | base, |
uint16_t | converterMask | ||
) |
This function triggers the converter using a software trigger. The software trigger can be used to start a conversion sequence.
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
void HSADC_EnableConverterDMA | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
bool | enable | ||
) |
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
enable | Enable or disable the feature. |
void HSADC_EnableInterrupts | ( | HSADC_Type * | base, |
uint16_t | mask | ||
) |
base | HSADC peripheral base address. |
mask | Mask value for interrupt events. See the "_hsadc_interrupt_enable". |
void HSADC_DisableInterrupts | ( | HSADC_Type * | base, |
uint16_t | mask | ||
) |
base | HSADC peripheral base address. |
mask | Mask value for interrupt events. See the "_hsadc_interrupt_enable". |
uint16_t HSADC_GetStatusFlags | ( | HSADC_Type * | base | ) |
base | HSADC peripheral base address. |
void HSADC_ClearStatusFlags | ( | HSADC_Type * | base, |
uint16_t | mask | ||
) |
base | HSADC peripheral base address. |
flags | Mask value for the event flags to be cleared. See the "_hsadc_status_flags". |
void HSADC_SetSampleConfig | ( | HSADC_Type * | base, |
uint16_t | sampleIndex, | ||
const hsadc_sample_config_t * | config | ||
) |
A sample list in this module works like a conversion sequence. Each sample slot can be used to designate to sample which channel is in converter A and converter B. The detail mapping relationship between sample slot and converter's channel can be found in the SoC reference manual.
base | HSADC peripheral base address. |
sampleIndex | Index of sample slot in conversion sequence. Available range is 0-15. |
config | Pointer to configuration structure. See the "hsadc_sample_config_t". |
void HSADC_GetDefaultSampleConfig | ( | hsadc_sample_config_t * | config | ) |
This function initializes each sample's configuration structure with an available settings. The default values are:
config | Pointer to configuration structure. See the "hsadc_sample_config_t". |
|
inlinestatic |
This function enables the sample slot. Only the enabled sample slot can join the conversion sequence.
base | HSADC peripheral base address. |
sampleMask | Mask value of sample slots in conversion sequence. Each bit corresponds to a sample slot. |
enable | Enable or disable the feature. |
|
inlinestatic |
base | HSADC peripheral base address. |
sampleMask | Mask value of sample slots in conversion sequence. Each bit is corresponding to a sample slot. |
enable | Enable or disable the feature. |
|
inlinestatic |
base | HSADC peripheral base address. |
|
inlinestatic |
base | HSADC peripheral base address. |
|
inlinestatic |
base | HSADC peripheral base address. |
sampleMask | Mask value for the sample slots' flags to be cleared. |
|
inlinestatic |
base | HSADC peripheral base address. |
|
inlinestatic |
base | HSADC peripheral base address. |
sampleMask | Mask value for the sample slots to be cleared flags. |
|
inlinestatic |
base | HSADC peripheral base address. |
|
inlinestatic |
base | HSADC peripheral base address. |
sampleMask | Mask value for the sample slots to be cleared flags. |
|
inlinestatic |
This function gets the sample result value. This returned value keeps its original formation just like in the hardware result register. It includes the sign bit as the MSB and 3-bit left shifted value.
base | HSADC peripheral base address. |
sampleIndex | Index of sample slot. |
void HSADC_DoAutoCalibration | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
uint16_t | calibrationModeMask | ||
) |
This function starts the single ended calibration and differential calibration for converter A and converter B at the same time. Note that this is a non blocking function. End of Scan flag and End of Calibration flag are both be set after the calibration process. As a result, the user should check these two flags by using the function HSADC_GetStatusFlags() to wait for the calibration process to complete.
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
calibrationModeMask | Mask for calibration mode to be operated. See the "_hsadc_calibration_mode". Shouldn't be zero. |
uint32_t HSADC_GetCalibrationResultValue | ( | HSADC_Type * | base | ) |
This function returns the single ended calibration value and differential calibration value for converter A and converter B. The calibration value of each calibration mode for each converter can be received from this function's return value by using the mask and shift definition from HSADC_CALIBRATION_VALUE_A_SINGLE_ENDED_MASK to HSADC_CALIBRATION_VALUE_B_DIFFERENTIAL_SHIFT.
base | HSADC peripheral base address. |
void HSADC_EnableCalibrationResultValue | ( | HSADC_Type * | base, |
uint16_t | converterMask, | ||
bool | enable | ||
) |
This function enables or disables converter A and converter B to use the calibration values to obtain the final conversion result by calibration sum operation.
base | HSADC peripheral base address. |
converterMask | Mask for converters to be operated. See the "_hsadc_converter_id". |
enable | Enable or disable the feature. |