关于DMA内存地址的问题

2019-10-11 13:28发布

void Fc_init(u32 add)
{
        GPIO_InitTypeDef GPIO_InitStruct;
        ADC_CommonInitTypeDef ADC_CommonInitStruct;
        ADC_InitTypeDef ADC_InitStruct;
        DMA_InitTypeDef DMA_InitStruct;

        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
        RCC_AHB1PeriphClockLPModeCmd(RCC_AHB1Periph_DMA1,ENABLE);

        GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AN;
        GPIO_InitStruct.GPIO_Pin=GPIO_Pin_8;
        GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_NOPULL;
        GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStruct);

        ADC_CommonInitStruct.ADC_DMAAccessMode=ADC_DMAAccessMode_1;
        ADC_CommonInitStruct.ADC_Mode=ADC_Mode_Independent;
        ADC_CommonInitStruct.ADC_Prescaler=ADC_Prescaler_Div2;
        ADC_CommonInitStruct.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_20Cycles;
        ADC_CommonInit(&ADC_CommonInitStruct);

        ADC_InitStruct.ADC_ContinuousConvMode=ENABLE;//连续转换
        ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right;
        ADC_InitStruct.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;//禁止外部触发检测,使用软件触发
        ADC_InitStruct.ADC_NbrOfConversion=1;
        ADC_InitStruct.ADC_Resolution=ADC_Resolution_12b;
        ADC_InitStruct.ADC_ScanConvMode=DISABLE;
        ADC_Init(ADC1,&ADC_InitStruct);

        DMA_InitStruct.DMA_PeripheralBaseAddr=ADC1_BASE+0X4c;   //ADC1的数据寄存器
        DMA_InitStruct.DMA_Channel=DMA_Channel_0;   //查找映射关系
        DMA_InitStruct.DMA_Memory0BaseAddr=add;     //存储器地址
        DMA_InitStruct.DMA_DIR=DMA_DIR_PeripheralToMemory;   //传输方向从内存到外设
        DMA_InitStruct.DMA_Mode=DMA_Mode_Circular;     //循环模式
        DMA_InitStruct.DMA_BufferSize=1;
        DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_Byte;
        DMA_InitStruct.DMA_FIFOMode=DMA_FIFOMode_Disable;
        DMA_InitStruct.DMA_FIFOThreshold=DMA_FIFOThreshold_Full;
        DMA_InitStruct.DMA_MemoryBurst=DMA_PeripheralBurst_Single;
        DMA_InitStruct.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;
        DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Disable;
        DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
        DMA_InitStruct.DMA_Priority=DMA_Priority_Medium;
        DMA_InitStruct.DMA_MemoryDataSize=DMA_PeripheralDataSize_HalfWord;
        DMA_InitStruct.DMA_PeripheralDataSize =DMA_PeripheralDataSize_HalfWord;
        DMA_Init(DMA1_Stream0,&DMA_InitStruct);

        DMA_Cmd(DMA1_Stream0,ENABLE);


        ADC_Cmd(ADC1,ENABLE);
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE);//ADC1复位
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE);//ADC复位结束

        ADC_DMACmd(ADC1,ENABLE);//使能ADC转换,通过DMA
        ADC_SoftwareStartConv(ADC1);
}

#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "fc.h"

u16 convers_data;
float result_data;

int main()
{
        delay_init(168);
        uart_init(115200);
        Fc_init(&convers_data);   //这里为什么会报错???STM32F4的地址不是32位的吗

        while(1)
        {
                result_data=(float)convers_data/4096*5;
                printf("the result is %.4f V ",result_data);
                delay_ms(100);
        }

}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
7条回答
mxiaotao
1楼-- · 2019-10-11 15:18
坏坏62 发表于 2017-3-23 09:14
楼主那个错误是为什么啊?能分析一下吗

在原来地址前加上(u32),把原来的地址强制转换为32位就行了
mxiaotao
2楼-- · 2019-10-11 19:33
原子哥
正点原子
3楼-- · 2019-10-11 19:41
博爱什么错?
mxiaotao
4楼-- · 2019-10-12 00:47
 精彩回答 2  元偷偷看……
坏坏62
5楼-- · 2019-10-12 06:09
mxiaotao 发表于 2017-3-23 09:03
这个解决了,原子哥。您能解释一下下面的内容吗?看了数据手册,这个地方理解不了。谢谢!
DMA: 直接 ...

楼主那个错误是为什么啊?能分析一下吗
坏坏62
6楼-- · 2019-10-12 11:08
mxiaotao 发表于 2017-3-23 10:04
在原来地址前加上(u32),把原来的地址强制转换为32位就行了

但是你定义的变量不是存在内存中的吗?内存的地址应该也是32位的才对吧

一周热门 更多>