LL库_STM32F407_ADC_DMA

相关文件

stm32f4xx_ll_adc.h
stm32f4xx_ll_adc.c
stm32f4xx_it.c
stm32f4xx_ll_dma.h
stm32f4xx_ll_dma.c

相关函数

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

轮询示例

1、cubemx配置
在这里插入图片描述
2、代码
adc.c

  /* USER CODE BEGIN ADC1_Init 2 */
  LL_ADC_Enable(ADC1);
  /* USER CODE END ADC1_Init 2 */

main.c

	uint16_t i;
	double value;

	LL_ADC_REG_StartConversionSWStart(ADC1);
	LL_ADC_REG_SetFlagEndOfConversion(ADC1,LL_ADC_REG_FLAG_EOC_SEQUENCE_CONV);
	if(LL_ADC_IsActiveFlag_EOCS(ADC1)){
		i=LL_ADC_REG_ReadConversionData12(ADC1);
		value=((double)i/4096)*3.3;
		LL_ADC_ClearFlag_EOCS(ADC1);
	}

DMA普通模式ADC示例

1、cubemx配置
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2、部分代码
adc.c

uint16_t adc_value[10];

 /* USER CODE BEGIN ADC1_Init 2 */

  /* Set ADC group regular conversion data transfer */
  LL_ADC_REG_SetDMATransfer(ADC1, LL_ADC_REG_DMA_TRANSFER_UNLIMITED);

  /*dma配置*/
  LL_DMA_ConfigAddresses(DMA2, LL_DMA_STREAM_0, LL_ADC_DMA_GetRegAddr(ADC1,LL_ADC_DMA_REG_REGULAR_DATA),
		  (uint32_t)adc_value,LL_DMA_GetDataTransferDirection(DMA2, LL_DMA_STREAM_0));
  LL_DMA_SetDataLength(DMA2, LL_DMA_STREAM_0, sizeof(adc_value));
  //使能DMA传输完成中断
  LL_DMA_EnableIT_TC(DMA2, LL_DMA_STREAM_0);

  //使能接收的DMA2 STREAM_0
  LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_0);

  //开始转换
  LL_ADC_Enable(ADC1);
  LL_ADC_REG_StartConversionSWStart(ADC1);

  /* USER CODE END ADC1_Init 2 */

it.c

#include "adc.h"
#include <string.h>
/**
  * @brief This function handles DMA2 stream0 global interrupt.
  */
void DMA2_Stream0_IRQHandler(void)
{
  /* USER CODE BEGIN DMA2_Stream0_IRQn 0 */
	if(LL_DMA_IsActiveFlag_TC0(DMA2))
	  {
		/* Clear flag DMA transfer complete */
		LL_DMA_ClearFlag_TC0(DMA2);
		memset(adc_value,0x0000,sizeof(adc_value));

		LL_DMA_DisableStream(DMA2, LL_DMA_STREAM_0);
		LL_DMA_SetDataLength(DMA2, LL_DMA_STREAM_0, sizeof(adc_value));
		LL_ADC_ClearFlag_OVR(ADC1);
		LL_ADC_REG_StartConversionSWStart(ADC1);
		LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_0);

	  }
  /* USER CODE END DMA2_Stream0_IRQn 0 */

  /* USER CODE BEGIN DMA2_Stream0_IRQn 1 */

  /* USER CODE END DMA2_Stream0_IRQn 1 */
}

3、仿真数据
在这里插入图片描述
要注意这个

/* Set ADC group regular conversion data transfer */
  LL_ADC_REG_SetDMATransfer(ADC1, LL_ADC_REG_DMA_TRANSFER_UNLIMITED);
  /**
  * @brief  Set ADC group regular conversion data transfer: no transfer or
  *         transfer by DMA, and DMA requests mode.
  * @note   If transfer by DMA selected, specifies the DMA requests
  *         mode:
  *         - Limited mode (One shot mode): DMA transfer requests are stopped
  *           when number of DMA data transfers (number of
  *           ADC conversions) is reached.
  *           This ADC mode is intended to be used with DMA mode non-circular.
  *         - Unlimited mode: DMA transfer requests are unlimited,
  *           whatever number of DMA data transfers (number of
  *           ADC conversions).
  *           This ADC mode is intended to be used with DMA mode circular.
  * @note   If ADC DMA requests mode is set to unlimited and DMA is set to
  *         mode non-circular:
  *         when DMA transfers size will be reached, DMA will stop transfers of
  *         ADC conversions data ADC will raise an overrun error
  *        (overrun flag and interruption if enabled).
  * @note   For devices with several ADC instances: ADC multimode DMA
  *         settings are available using function @ref LL_ADC_SetMultiDMATransfer().
  * @note   To configure DMA source address (peripheral address),
  *         use function @ref LL_ADC_DMA_GetRegAddr().
  * @rmtoll CR2      DMA            LL_ADC_REG_SetDMATransfer\n
  *         CR2      DDS            LL_ADC_REG_SetDMATransfer
  * @param  ADCx ADC instance
  * @param  DMATransfer This parameter can be one of the following values:
  *         @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  *         @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  *         @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  * @retval None
  */
__STATIC_INLINE void LL_ADC_REG_SetDMATransfer(ADC_TypeDef *ADCx, uint32_t DMATransfer)
{
  MODIFY_REG(ADCx->CR2, ADC_CR2_DMA | ADC_CR2_DDS, DMATransfer);
}

/** @defgroup ADC_LL_EC_REG_DMA_TRANSFER  ADC group regular - DMA transfer of ADC conversion data
  * @{
  */
#define LL_ADC_REG_DMA_TRANSFER_NONE       0x00000000UL              /*!< ADC conversions are not transferred by DMA */
#define LL_ADC_REG_DMA_TRANSFER_LIMITED    (              ADC_CR2_DMA)          /*!< ADC conversion data are transferred by DMA, in limited mode (one shot mode): DMA transfer requests are stopped when number of DMA data transfers (number of ADC conversions) is reached. This ADC mode is intended to be used with DMA mode non-circular. */
#define LL_ADC_REG_DMA_TRANSFER_UNLIMITED  (ADC_CR2_DDS | ADC_CR2_DMA)          /*!< ADC conversion data are transferred by DMA, in unlimited mode: DMA transfer requests are unlimited, whatever number of DMA data transferred (number of ADC conversions). This ADC mode is intended to be used with DMA mode circular. */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亦哟啊哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值