- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开展一个项目,其中涉及 STM32H743 核板和 16 个 ADC 输入的使用。
显然,这些模拟输入一次使用一次;通过轮询机制读取值并配置下一个输入...配置 ADC channel ,启动 ADC,通过轮询读取值并配置下一个输入...每 1 ms 16 次,作为实时行为。
我发现的问题是我无法启动 3 个 ADC 中的任何一个,它卡在这条线上stm32h7xx_hal_adc.h(我认为我错误地配置了时钟或其他类型的东西):
while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == 0UL)
该行位于函数中:
HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc)
正在调用:
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc)
提前感谢您的帮助,下面提供了源代码。
源代码文件是:
MAIN.C
#include "main.h"
#include "hwdrvlib.h"
#include "test.h"
volatile unsigned int systick_count = 0;
static volatile int systick_active = 1;
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
#ifdef CPU_CACHE
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
#endif
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config(); //Located on hwdrvlid.h y hwdrvlib.c
/* SysTick is 0 at start */
tick = (uint8_t)0;
/* Initialize */
ADC_Init(); /* Initialize ADC peripherals and GPIO ADC inputs as analog */
//Located on hwdrvlid.h y hwdrvlib.c
/* Sample Time: 0.001 */
while (...) { /* Some comparison deleted for readability */
RT_Task(); //Located on Function file
} //End of while
}
hwdrvlib.c(包含配置函数的文件)
ADC_HandleTypeDef hadc1 __attribute__((section(".ramd2")));
ADC_HandleTypeDef hadc2 __attribute__((section(".ramd2")));
ADC_HandleTypeDef hadc3 __attribute__((section(".ramd2")));
void ADC_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* ADC Clock Enable */
__HAL_RCC_ADC12_CLK_ENABLE();
__HAL_RCC_ADC3_CLK_ENABLE();
/* ADC Periph interface clock configuration */
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_CLKP);//or PLL2
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/* ADCs GPIO as analog input */
/* System ADC Input number 1 PF9 */
/*##-2- Configure peripheral GPIO ##########################################*/
/* ADC Channel GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
/* Initialization of 16 analog inputs, hidden for readability */
/* System ADC Input number 16 PA3 */
/*##-2- Configure peripheral GPIO ##########################################*/
/* ADC Channel GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* ADC1 Config */
hadc1.Instance = ADC1;
if (HAL_ADC_DeInit(&hadc1) != HAL_OK) {
/* ADC1 de-initialization Error */
Error_Handler();
}
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_16B;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1; /* Vector Support */
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.NbrOfDiscConversion = 1;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK) {
Error_Handler();
}
/* The same for ADC2 and ADC3 using hadc2 and hadc3 */
}
void ADC_Input_Select(ADC_HandleTypeDef *hadc,uint32_t Channel)
{
static ADC_ChannelConfTypeDef sConfig = { 0 };
/* Configure Regular Channel */
sConfig.Channel = Channel;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(hadc, &sConfig) != HAL_OK) {
Error_Handler();
}
}
/**
* @brief System Clock Configuration
* @retval None
*
*
*
* Configure 480 MHz CPU Clock, 240 MHz APB1 and APB2 Clock
* flash latency 4
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
}
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
}
__HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSI);//HSE
/* a 480 MHz config */
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
}
/** Initializes the CPU, AHB and APB busses clocks
*/
#ifdef USB_VCP_SETUP
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 |
RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 60;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
#else
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 60;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
#endif
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/* End of old 480 MHz config */
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
Error_Handler();
}
/* USB CLK Initialization if needed */
#ifdef USB_VCP_SETUP
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;//PLL
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
Error_Handler();
}
/** Enable USB Voltage detector
*/
HAL_PWREx_EnableUSBVoltageDetector();
#endif
}
函数文件(该函数包含要执行的函数,以便读取模拟输入数据)
void RT_Task(void)
{
/* ADC3-IN2 PF9 */
ADC_Input_Select(&hadc3,ADC_CHANNEL_2);
HAL_ADC_Start(&hadc3); /* Execution stucks here :( */
if (HAL_ADC_PollForConversion(&hadc3,1000) != HAL_OK ) {
/* ADC conversion fails */
//Escribir aqui la salida de error
} else {
test2_B.VectorConcatenate[1] = HAL_ADC_GetValue(&hadc3) + 0;
}
/* More ADC reading hidden for readability */
}
最佳答案
此问题的解决方案,请记住您可以使用任何微 Controller 来面对此问题:
我发现了失败,这是我以前从未想象过的。
初始化函数需要更多时间,SysTick IRQ需要触发第一个IRQ(从SysTick IRQ调用实时任务),并且由于ADC外设未初始化...其功能无法执行适本地。
我添加了一个 uint8 变量来检测初始化函数是否在 RT Task 调用开始代码处结束。我还需要启用 ADC_ConfigureBoostMode(&hadc1);对于每个使用的 ADC。
int main(void)
{
Init_finished = (uint8_t)0;
#ifdef CPU_CACHE
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
#endif
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* SysTick is 0 at start */
tick = (uint8_t)0;
/* Initialize model */
test_initialize(1);
Init_finished = (uint8_t)255;
并使用这些
ADC_ConfigureBoostMode(&hadc1); /* and for hadc2 and hadc3 */
关于c - STM32H743 nucleo 板,在轮询模式下同时使用 3 个 ADC(一次 1 个 ADC);不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59828644/
我将 ADC 与 DMA(STM32F4,ide STM32CubeIDE)一起使用,我认为我了解它是如何工作的,但仍然有一个难题。根据我的理解,MCU 仅在 DMA 传输完成时调用,基本上 MCU
我正在开展一个项目,其中涉及 STM32H743 核板和 16 个 ADC 输入的使用。 显然,这些模拟输入一次使用一次;通过轮询机制读取值并配置下一个输入...配置 ADC channel ,启动
1 指令语法 adc <Xd>, <Xn>, <Xm> 2 指令语义 adc就是带「进位」加法,指令中的c就是英文carry。 整个指令等价于: (Xd
ATtiny88初体验(五):ADC ADC模块介绍 ATtiny88单片机包含一个10bit分辨率的ADC模块,拥有8个通道,最大采样率15kSPS,转换时间14us。ATtiny88的
我正在尝试在 STM32L476 Nucleo 板上调出一个 ADC。我想我已经配置好了,但我一定是漏掉了一步。我知道这可以使用 HAL API 和 CubeMX 来完成,但我更喜欢在启动新板时进行寄
mov eax, ptr_to_num1 ; little endian mov ebx, ptr_to_num2 ; little endian xor ecx, ecx xor edx, edx
.MODEL SMALL .STACK 1000 .DATA MSGA DB 13,10,"Input first number: ","$" MSGB DB 13,10,"Input second
我目前正在对 PIC 微 Controller 进行编程。 当按照我的方式创建结构时,每次我尝试访问该结构的变量的地址是否都会更改? 还是像静态变量一样,意味着地址在编译时确定,并且在整个程序中不会更
大家好,我正在开发一个项目,我必须计算 ADC 读数的移动平均值。从 ADC 输出的数据代表正弦波。 这是我用来获取给定信号的移动平均值的代码。 longNew = (8 bit data from
我希望在每次转换结束后调用 ADC 中断服务程序。但是它没有被调用。 这是我的代码: #define RCC_APB2ENR (*((volatile unsigned long*) 0x4002
有人可以看看我的代码吗?当我旋转电位器时,我试图让 8 个 LED 旋转,但四个 LED 一直保持亮着,根本不旋转。 #include /******************************
目的是将最新的 10 个 ADC 读数存储在一个数组中,然后计算它们的平均值以供其他地方使用。每次更新时删除最旧的。 关于 LED 时序,如果 ADC 读数在下面写的边界内,它必须将时序从 1s 切换
我正在尝试将音频ADC(wm8782 / pcm1803a)与Beagle Black连接。我已经对文件 davinci-evm , wm8782.c 和BB-BONE-AUDI-01设备树覆盖文件进
我正在尝试在简单的连续转换模式下通过 STM32F411RE 配置 ADC。我使用 CubeMX 生成基于 HAL 驱动程序的代码,这是生成的代码中初始化 ADC 的部分内容: /* ADC1 ini
我只是对我用 C 编写的反汇编 32 位程序进行一些分析。以下是反汇编程序输出的一部分: 41153c 02 00 add al, [eax] 41153e 00 00 add [eax]
我一直在运行Blarggs CPU tests通过我的 Gameboy 模拟器,op r,r 测试表明我的 ADC 指令工作不正常,但 ADD 是。我的理解是两者之间的唯一区别是在添加之前将现有的进位
我正在使用Renesas RX62N ;我的屏幕使用 ADC 单元 1,我的代码使用单元 0。 难道两个ADC单元不能一起工作吗?当我分别运行“ADC”和“显示代码”时,它工作正常,但一旦我尝试将它们
描述很长,抱歉。我用粗体突出显示了问题。 我目前正在尝试建立一个 driverlib 机制来执行以下操作: 大约每 20 个 RTC 预分频器 1 事件,检查是否应进行 ADC 测量。 如果需要,请设
我正在努力让 ADC 与我的设备配合使用。我正在使用 dsPIC33FJ128GP802,并尝试通过手动采样和转换缓慢启动。 我的代码发布在下面,我已经设置了 ADC 的每个寄存器,然后尝试仅采样一次
我的板上有一个 adc 模块。我在信号发生器上创建了一个正弦波。我将这个发生器的输出提供给一个 adc 引脚。最后我定期读取这个引脚的值。我尝试在我的软件上创建一个正弦波。 x = t, y = As
我是一名优秀的程序员,十分优秀!