Skip to content

Commit 0343ad2

Browse files
committed
KSDK2 - set ADC mux before taking measurement
Set the channel mux before taking a reading rather than on initialization. This allows ADC pins on both mux A and B to be used in the same application.
1 parent 967b45a commit 0343ad2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/api/analogin_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ void analogin_init(analogin_t *obj, PinName pin) {
5454
ADC16_Init(adc_addrs[instance], &adc16_config);
5555
ADC16_EnableHardwareTrigger(adc_addrs[instance], false);
5656
ADC16_SetHardwareAverage(adc_addrs[instance], kADC16_HardwareAverageCount4);
57-
ADC16_SetChannelMuxMode(adc_addrs[instance],
58-
obj->adc & (1 << ADC_B_CHANNEL_SHIFT) ? kADC16_ChannelMuxB : kADC16_ChannelMuxA);
59-
6057
pinmap_pinout(pin, PinMap_ADC);
6158
}
6259

@@ -71,6 +68,9 @@ uint16_t analogin_read_u16(analogin_t *obj) {
7168
adc16_channel_config.enableDifferentialConversion = false;
7269
#endif
7370

71+
ADC16_SetChannelMuxMode(adc_addrs[instance],
72+
obj->adc & (1 << ADC_B_CHANNEL_SHIFT) ? kADC16_ChannelMuxB : kADC16_ChannelMuxA);
73+
7474
/*
7575
* When in software trigger mode, each conversion would be launched once calling the "ADC16_ChannelConfigure()"
7676
* function, which works like writing a conversion command and executing it.

0 commit comments

Comments
 (0)