📄 stm32f10x_adc.lst
字号:
196 /* Get the ADCx SQR1 value */
197 tmpreg1 = ADCx->SQR1;
198 /* Clear L bits */
199 tmpreg1 &= SQR1_CLEAR_Mask;
200 /* Configure ADCx: regular channel sequence length */
201 /* Set L bits according to ADC_NbrOfChannel value */
202 tmpreg2 |= (ADC_InitStruct->ADC_NbrOfChannel - 1);
203 tmpreg1 |= ((u32)tmpreg2 << 20);
204 /* Write to ADCx SQR1 */
205 ADCx->SQR1 = tmpreg1;
206 }
207
208 /*******************************************************************************
209 * Function Name : ADC_StructInit
210 * Description : Fills each ADC_InitStruct member with its default value.
211 * Input : ADC_InitStruct : pointer to an ADC_InitTypeDef structure
212 * which will be initialized.
213 * Output : None
214 * Return : None
215 *******************************************************************************/
216 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
217 {
218 /* Reset ADC init structure parameters values */
219 /* Initialize the ADC_Mode member */
220 ADC_InitStruct->ADC_Mode = ADC_Mode_Independent;
221
222 /* initialize the ADC_ScanConvMode member */
223 ADC_InitStruct->ADC_ScanConvMode = DISABLE;
224
225 /* Initialize the ADC_ContinuousConvMode member */
226 ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
227
228 /* Initialize the ADC_ExternalTrigConv member */
229 ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
230
231 /* Initialize the ADC_DataAlign member */
232 ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
233
234 /* Initialize the ADC_NbrOfChannel member */
235 ADC_InitStruct->ADC_NbrOfChannel = 1;
236 }
237
238 /*******************************************************************************
239 * Function Name : ADC_Cmd
240 * Description : Enables or disables the specified ADC peripheral.
241 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
242 * - NewState: new state of the ADCx peripheral. This parameter
243 * can be: ENABLE or DISABLE.
244 * Output : None
245 * Return : None
246 *******************************************************************************/
247 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
248 {
249 /* Check the parameters */
250 assert_param(IS_FUNCTIONAL_STATE(NewState));
251
252 if (NewState != DISABLE)
253 {
254 /* Set the ADON bit to wake up the ADC from power down mode */
255 ADCx->CR2 |= CR2_ADON_Set;
256 }
257 else
258 {
259 /* Disable the selected ADC peripheral */
260 ADCx->CR2 &= CR2_ADON_Reset;
261 }
262 }
263
264 /*******************************************************************************
265 * Function Name : ADC_DMACmd
266 * Description : Enables or disables the specified ADC DMA request.
267 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
268 * - NewState: new state of the selected ADC DMA transfer.
269 * This parameter can be: ENABLE or DISABLE.
270 * Output : None
271 * Return : None
272 *******************************************************************************/
273 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
274 {
275 /* Check the parameters */
276 assert_param(IS_FUNCTIONAL_STATE(NewState));
277
278 if (NewState != DISABLE)
279 {
280 /* Enable the selected ADC DMA request */
281 ADCx->CR2 |= CR2_DMA_Set;
282 }
283 else
284 {
285 /* Disable the selected ADC DMA request */
286 ADCx->CR2 &= CR2_DMA_Reset;
287 }
288 }
289
290 /*******************************************************************************
291 * Function Name : ADC_ITConfig
292 * Description : Enables or disables the specified ADC interrupts.
293 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
294 * - ADC_IT: specifies the ADC interrupt sources to be enabled
295 * or disabled.
296 * This parameter can be any combination of the following values:
297 * - ADC_IT_EOC: End of conversion interrupt mask
298 * - ADC_IT_AWD: Analog watchdog interrupt mask
299 * - ADC_IT_JEOC: End of injected conversion interrupt mask
300 * - NewState: new state of the specified ADC interrupts.
301 * This parameter can be: ENABLE or DISABLE.
302 * Output : None
303 * Return : None
304 *******************************************************************************/
305 void ADC_ITConfig(ADC_TypeDef* ADCx, u16 ADC_IT, FunctionalState NewState)
306 {
307 u8 itmask = 0;
308
309 /* Check the parameters */
310 assert_param(IS_FUNCTIONAL_STATE(NewState));
311 assert_param(IS_ADC_IT(ADC_IT));
312
313 /* Get the ADC IT index */
314 itmask = (u8)ADC_IT;
315
316 if (NewState != DISABLE)
317 {
318 /* Enable the selected ADC interrupts */
319 ADCx->CR1 |= itmask;
320 }
321 else
322 {
323 /* Disable the selected ADC interrupts */
324 ADCx->CR1 &= (~(u32)itmask);
325 }
326 }
327
328 /*******************************************************************************
329 * Function Name : ADC_ResetCalibration
330 * Description : Resets the selected ADC calibration registers.
331 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
332 * Output : None
333 * Return : None
334 *******************************************************************************/
335 void ADC_ResetCalibration(ADC_TypeDef* ADCx)
336 {
337 /* Resets the selected ADC calibartion registers */
338 ADCx->CR2 |= CR2_RSTCAL_Set;
339 }
340
341 /*******************************************************************************
342 * Function Name : ADC_GetResetCalibrationStatus
343 * Description : Gets the selected ADC reset calibration registers status.
344 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
345 * Output : None
346 * Return : The new state of ADC reset calibration registers (SET or RESET).
347 *******************************************************************************/
348 FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx)
349 {
350 FlagStatus bitstatus = RESET;
351
352 /* Check the status of RSTCAL bit */
353 if ((ADCx->CR2 & CR2_RSTCAL_Set) != (u16)RESET)
354 {
355 /* RSTCAL bit is set */
356 bitstatus = SET;
357 }
358 else
359 {
360 /* RSTCAL bit is reset */
361 bitstatus = RESET;
362 }
363 /* Return the RSTCAL bit status */
364 return bitstatus;
365 }
366
367 /*******************************************************************************
368 * Function Name : ADC_StartCalibration
369 * Description : Starts the selected ADC calibration process.
370 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
371 * Output : None
372 * Return : None
373 *******************************************************************************/
374 void ADC_StartCalibration(ADC_TypeDef* ADCx)
375 {
376 /* Enable the selected ADC calibration process */
377 ADCx->CR2 |= CR2_CAL_Set;
378 }
379
380 /*******************************************************************************
381 * Function Name : ADC_GetCalibrationStatus
382 * Description : Gets the selected ADC calibration status.
383 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
384 * Output : None
385 * Return : The new state of ADC calibration (SET or RESET).
386 *******************************************************************************/
387 FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx)
388 {
389 FlagStatus bitstatus = RESET;
390
391 /* Check the status of CAL bit */
392 if ((ADCx->CR2 & CR2_CAL_Set) != (u16)RESET)
393 {
394 /* CAL bit is set: calibration on going */
395 bitstatus = SET;
396 }
397 else
398 {
399 /* CAL bit is reset: end of calibration */
400 bitstatus = RESET;
401 }
402 /* Return the CAL bit status */
403 return bitstatus;
404 }
405
406 /*******************************************************************************
407 * Function Name : ADC_SoftwareStartConvCmd
408 * Description : Enables or disables the selected ADC software start conversion .
409 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
410 * - NewState: new state of the selected ADC software start conversion.
411 * This parameter can be: ENABLE or DISABLE.
412 * Output : None
413 * Return : None
414 *******************************************************************************/
415 void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
416 {
417 /* Check the parameters */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -