初中生
最后登录1970-1-1
在线时间 小时
注册时间2015-6-12
|
main程序如下,我只有注释了printf语句,程序才能正常运行,否则串口没输出,LED也不亮(关于串口使用printf需要的那段语句也添加了,源程序复制的):
​#include "led.h"
#include "usart.h"
//#include "delay.h"
extern uint8_t SendBuff[SENDBUFF_SIZE];
static void Delay(__IO u32 nCount);
int main(void)
{
LED_Init();
//delay_init();
usart_init(9600);
usart_dma_init();
//printf("\r\n usart DMA TX 测试 \r\n");
{
uint16_t i;
for(i=0;i<SENDBUFF_SIZE;i++)
{
SendBuff='A';
}
}
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
for(;;)
{
LED0=0;
LED1=1;
Delay(0xFFFFF);
LED0=1;
LED1=0;
Delay(0xFFFFF);;
}
}
static void Delay(__IO uint32_t nCount) //简单的延时函数
{
for(; nCount != 0; nCount--);
}
​
DMA初始化程序是这样的,这里有意思的地方还有一个,我第一次使用前面的注释前面的程序时,串口一直输出“|||||||||”,于是我把一段源程序复制进去,也就是注释的部分(我看过两个程序一模一样),结果串口能输出“AAAAAAA”,但我再次使用前面的程序,串口又输出“PPPPPP”,于是我又用源程序时,串口也输出“||||||”了,我不知道这到底是个什么情况,为什么同样的程序会有不同的结果,到底哪里出了问题,谁能帮个忙看看,感激不尽(实验截图在附件里):
​void usart_dma_init(void)
{
DMA_InitTypeDef DMA_InitStructure; //DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_InitStructure.DMA_PeripheralBaseAddr=USART1_DR_Base; //DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)SendBuff; //DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff;
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralDST; //DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize=SENDBUFF_SIZE; //DMA_InitStructure.DMA_BufferSize = SENDBUFF_SIZE;
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable; //DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
​ DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable; //DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Byte; //DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_Byte; //DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular; //DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority=DMA_Priority_Medium; //DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable; //DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel4, &DMA_InitStructure); //DMA_Init(DMA1_Channel4, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel4, ENABLE); //DMA_Cmd (DMA1_Channel4,ENABLE);
}
​
​
​
​
|
-
-
|