lisn1234 发表于 2013-6-9 11:00
还有就是,改成stream0也不行……
这个是DMA配置:
DMA_InitTypeDef DMA_InitStructure; //DMA配置初始化结构体
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); //开启DMA2时钟
/* 配置DMA1的Channel3 stream0, 用于接收ADC的SPI传输数据 */
DMA_DeInit(DMA2_Stream0); //复位DMA2的Stream0的寄存器到复位默认状态
/* 在使能DMA Stream前检查其是否被禁用,这一步非常重要当Stream用于其它复用时:启用、禁用、再
启用禁用,这种情况下DMA的Stream禁用将会影响到正在传输的数据,而且在再次使能前不能正确配置
被硬件清除的位,如果Streanm只被使用一次,这个步骤可以省略跳过 */
while (DMA_GetCmdStatus(DMA2_Stream0) != DISABLE);
DMA_InitStructure.DMA_Channel = DMA_Channel_3; //选择通道3
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32)(&(SPI1->DR)); //SPI1_BASE+0x0c寄存器地址,(uint32_t)(SPI1_BASE+0x0c)
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32)ADC_RX_BUFFER; //SPI接收ADC的数据地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; //外设到内存
DMA_InitStructure.DMA_BufferSize = (uint32)(ADC_RX_BUFFER_SIZE * 3); //DMA的接收缓冲区大小
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址不增加
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址增加
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //外设按照字节传输
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //内存按照字节传输
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //正常模式,非循环读取
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //优先级高
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //关闭FIFO模式
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure); //配置DMA及Stream0并初始化
/* 配置DMA2、通道3、stream0传输完成产生中断
** DMA_IT_TC 传输完成产生DMA中断
** DMA_IT_HT 传输一半产生DMA中断
** DMA_IT_TE 传输错误产生DMA中断
** DMA_IT_DME
** DMA_IT_FE FIFO传输错误*/
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
DMA_Cmd(DMA2_Stream0, DISABLE); //先关闭DMA2_Stream0
/* 配置DMA2、channel3、stream0中断向量表 */
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* 配置DMA2 channe3 stream3 SPI的数据发送 */
DMA_DeInit(DMA2_Stream3); //复位DMA2的Stream0的寄存器到复位默认状态
while ( DMA_GetCmdStatus(DMA2_Stream3) != DISABLE);
DMA_InitStructure.DMA_Channel = DMA_Channel_3;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32)(&(SPI1->DR)); //SPI->DR寄存器地址
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32)ADC_TX_BUFFER; //ADC发送数据起始地址
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; //内存到外设
DMA_InitStructure.DMA_BufferSize = (uint32)ADC_TX_BUFFER_SIZE; //DMA发送缓冲区大小
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址不增加
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址增加
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //外设字节传输
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //内存字节传输
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode =DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream3, &DMA_InitStructure); //配置DMA的Stream3并初始化
DMA_ITConfig(DMA2_Stream3, DMA_IT_TC, ENABLE); //配置DMA传输完成产生中断
DMA_Cmd(DMA2_Stream3, DISABLE); //先关闭DMA的Stream3
/* 配置DMA2 channe3 stream3的中断向量 */
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
|