Skip to content

Commit e5b6417

Browse files
committed
[NUCLEO_L152RE] Add analogin api
1 parent ffb7f13 commit e5b6417

File tree

1 file changed

+14
-26
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE

1 file changed

+14
-26
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/analogin_api.c

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
#include "error.h"
3636

3737
static const PinMap PinMap_ADC[] = {
38-
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
39-
{PA_1, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
40-
{PA_4, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
41-
{PB_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
42-
{PC_1, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
43-
{PC_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
38+
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN0
39+
{PA_1, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
40+
{PA_4, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN4
41+
{PB_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN8
42+
{PC_1, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN11
43+
{PC_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN10
4444
{NC, NC, 0}
4545
};
4646

@@ -72,26 +72,14 @@ void analogin_init(analogin_t *obj, PinName pin) {
7272
adc = (ADC_TypeDef *)(obj->adc);
7373

7474
// Enable ADC clock
75-
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
7675
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
7776

7877
// Configure ADC
79-
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
80-
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
81-
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
82-
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
83-
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
84-
ADC_InitStructure.ADC_NbrOfChannel = 1;
78+
ADC_StructInit(&ADC_InitStructure);
8579
ADC_Init(adc, &ADC_InitStructure);
8680

8781
// Enable ADC
8882
ADC_Cmd(adc, ENABLE);
89-
90-
// Calibrate ADC
91-
ADC_ResetCalibration(adc);
92-
while(ADC_GetResetCalibrationStatus(adc));
93-
ADC_StartCalibration(adc);
94-
while(ADC_GetCalibrationStatus(adc));
9583
}
9684
}
9785

@@ -102,28 +90,28 @@ static inline uint16_t adc_read(analogin_t *obj) {
10290
// Configure ADC channel
10391
switch (obj->pin) {
10492
case PA_0:
105-
ADC_RegularChannelConfig(adc, ADC_Channel_0, 1, ADC_SampleTime_7Cycles5);
93+
ADC_RegularChannelConfig(adc, ADC_Channel_0, 1, ADC_SampleTime_4Cycles);
10694
break;
10795
case PA_1:
108-
ADC_RegularChannelConfig(adc, ADC_Channel_1, 1, ADC_SampleTime_7Cycles5);
96+
ADC_RegularChannelConfig(adc, ADC_Channel_1, 1, ADC_SampleTime_4Cycles);
10997
break;
11098
case PA_4:
111-
ADC_RegularChannelConfig(adc, ADC_Channel_4, 1, ADC_SampleTime_7Cycles5);
99+
ADC_RegularChannelConfig(adc, ADC_Channel_4, 1, ADC_SampleTime_4Cycles);
112100
break;
113101
case PB_0:
114-
ADC_RegularChannelConfig(adc, ADC_Channel_8, 1, ADC_SampleTime_7Cycles5);
102+
ADC_RegularChannelConfig(adc, ADC_Channel_8, 1, ADC_SampleTime_4Cycles);
115103
break;
116104
case PC_1:
117-
ADC_RegularChannelConfig(adc, ADC_Channel_11, 1, ADC_SampleTime_7Cycles5);
105+
ADC_RegularChannelConfig(adc, ADC_Channel_11, 1, ADC_SampleTime_4Cycles);
118106
break;
119107
case PC_0:
120-
ADC_RegularChannelConfig(adc, ADC_Channel_10, 1, ADC_SampleTime_7Cycles5);
108+
ADC_RegularChannelConfig(adc, ADC_Channel_10, 1, ADC_SampleTime_4Cycles);
121109
break;
122110
default:
123111
return 0;
124112
}
125113

126-
ADC_SoftwareStartConvCmd(adc, ENABLE); // Start conversion
114+
ADC_SoftwareStartConv(adc); // Start conversion
127115

128116
while(ADC_GetFlagStatus(adc, ADC_FLAG_EOC) == RESET); // Wait end of conversion
129117

0 commit comments

Comments
 (0)