原子哥搭救搭救~~我使用的是串口1的接收,通过串口助手发送数据,希望保存在数组里,本来设置发送16个,但是发送6个,DMA就已经传输结束了。。数组也没数据
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "dma.h"
#include "usart.h"
#include "lcd.h"
#include "delay.h"
#include "led.h"
#define buffsize 16
u8 rbuff[buffsize];
int main(void)
{
u8 i,j;
delay_init();
uart_init(115200);
LCD_Init();
Led_Init();
DMA_Config(DMA1_Channel5,(u32)&USART1->DR,(u32)rbuff,buffsize);
POINT_COLOR = BLUE;
LCD_ShowString(60,50,"DMA&USART test");
LCD_ShowString(60,70,"2015.02.15");
Led2 = 0;
USART_DMACmd(USART1,USART_DMAReq_Rx,ENABLE);
Open_DAM(DMA1_Channel5,(u32)buffsize);
while(1)
{
while(1)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC5)!=RESET)
{
DMA_ClearFlag(DMA1_FLAG_TC5);
Led2 = 1;
break;
}
i=DMA_GetCurrDataCounter(DMA1_Channel5);
LCD_ShowNum(60,170,i,3,16);
}
for(j=0;j<buffsize;j++)
{
printf("
%d",rbuff[j]);
LCD_ShowNum(60+j,190,rbuff[j],3,16);
}
}
}
[/mw_shl_code]
[mw_shl_code=c,true]#include "dma.h"
DMA_InitTypeDef DMA_Initialize;
u16 DMA_MEM_LEN;
//配置DMA1串口1接收
void DMA_Config(DMA_Channel_TypeDef* DMA_CHx,u32 dpba,u32 dmba,u32 buffsize )
{
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_DMA1 ,ENABLE);
DMA_DeInit(DMA_CHx);
DMA_MEM_LEN = buffsize;
DMA_Initialize.DMA_PeripheralBaseAddr = dpba; //外设地址
DMA_Initialize.DMA_MemoryBaseAddr = dmba; //内存地址
DMA_Initialize.DMA_DIR = DMA_DIR_PeripheralSRC;//外设作为数据的来源
DMA_Initialize.DMA_BufferSize = buffsize; //一次传输的数据量
DMA_Initialize.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址不增加
DMA_Initialize.DMA_MemoryInc = DMA_PeripheralInc_Enable;//内存地址增加
DMA_Initialize.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_Initialize.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_Initialize.DMA_Mode = DMA_Mode_Normal;
DMA_Initialize.DMA_Priority = DMA_Priority_VeryHigh;
DMA_Initialize.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA_CHx,&DMA_Initialize);
//DMA_Cmd(DMA_CHx,ENABLE); //使能DMAx通道x,启动传输
}
void Open_DAM(DMA_Channel_TypeDef* DMA_CHx,u32 buffsize)
{
DMA_Cmd(DMA_CHx,DISABLE);
DMA_SetCurrDataCounter(DMA1_Channel5,DMA_MEM_LEN);
DMA_Cmd(DMA_CHx,ENABLE);
}
[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
我参考过了,始终不行啊,一直不知道为什么,当我把内存地址设置为不增加的时候,就可以完整发送完16个数据,但是最后数组里的数据时重叠的,只有第一个有数据,而且是不对的,原子哥帮帮忙啊!
---------------------------------
弄出来了么,我这里有各个串口的dma
---------------------------------
没有,后来我请教了师兄,他让我用串口中断,你有的是发送还是接收
---------------------------------
都有
一周热门 更多>