stm32H750的ADC采集使用DMA得不到数据的处理方式

在STM32H750芯片上,使用DMA进行ADC采集时遇到问题,数据无法正常存入预定义的uint32_tADC1_2Data[ADC_SIZE]数组中。解决方法是通过ALIGN_32BYTES确保数组ADC1Data在RAM中的起始位置32字节对齐,避免DCACHE指令错误。重新定义后的数组静态存储于指定内存段,解决了数据丢失的问题。

芯片为stm32H750,ADC采集使用DMA方式,定义ADC采集后的数据存放数组如下:

uint32_t ADC1_2Data[ADC_SIZE];

DMA传送完成后,数组ADC1_2Data中数据为空,如果不用DMA方式,ADC采集数据是对的,解决方式,重新定义数组ADC1_2Data占用的RAM起始位置,如下:


///ALIGN_32BYTES 把地址进行32字节对齐,避免使用dcache指令出错
ALIGN_32BYTES (static uint16_t   ADC1Data[ADC_SIZE]) __attribute__((section(".ARM.__at_0x24000000")));

问题解决。

### STM32H750 HAL ADC DMA Example Code and Documentation For the STM32H750 series microcontrollers using the Hardware Abstraction Layer (HAL) library to perform Analog-to-Digital Converter (ADC) conversions with Direct Memory Access (DMA), several key points must be considered including initialization of peripherals, starting a conversion through DMA, handling completion callbacks, and ensuring data is correctly placed in memory not restricted by DMA such as DTCM. Initialization involves setting up both the DMA controller and the ADC peripheral: ```c /* Initialize all configured peripherals */ MX_DMA_Init(); MX_ADC1_Init(); ``` Starting an ADC conversion via DMA can be done using `HAL_ADC_Start_DMA` function which requires passing a pointer to where converted values should be stored along with how many samples are expected. An error handler ensures any issues during this process do get addressed immediately[^3]. ```c if(HAL_ADC_Start_DMA(&hadc1,(uint32_t *)ADC_DATA, adc_value_len)!=HAL_OK){ Error_Handler(); } ``` To handle when conversions complete without needing polling within main loop or interrupt service routines directly tied to hardware events, callback functions provided by HAL framework come into play allowing cleaner asynchronous programming style while still maintaining efficiency[^2]: ```c void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle) { /* Process completed conversion results here if necessary before next set begins */ } ``` Finally, iterating over collected data from inside application's primary execution context might look like so assuming proper synchronization mechanisms exist between ISR/callbacks writing versus reading operations on shared resources: ```c for(uint16_t i=0; i<adc_value_len; ++i){ printf("ADC_DATA[%d]: %u\n", i, ADC_DATA[i]); } ``` It’s important that buffers intended for use alongside DMA transfers reside outside regions protected against direct access due to potential conflicts leading to undefined behavior—such as Data Tightly Coupled Memory (DTCM)[^4]. This means placing variables used for storing ADC readings into SRAM sections instead unless specifically designed otherwise according to project requirements. --related questions-- 1. What considerations need to be taken regarding buffer placement when working with DMA? 2. How does one properly synchronize access to shared resources modified asynchronously by interrupts or callbacks? 3. Can you explain more about configuring dual ADC mode on STM32H750 devices? 4. In what scenarios would it make sense to employ circular buffering techniques with ADC/DMA setups? 5. Are there specific timing constraints developers ought to keep track of concerning ADC sampling rates?
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值