博士
最后登录1970-1-1
在线时间 小时
注册时间2014-4-3
|
以下代码,代码后是问题
----------------------------------------------
void USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10, GPIO_AF_USART1);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
DMA_DeInit(DMA2_Stream7);
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
DMA_InitStructure.DMA_PeripheralBaseAddr = ((uint32_t)USART1_BASE + 0x04); //外设基址
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)UsartValue; //数据缓存基址
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; //数据传输方向
DMA_InitStructure.DMA_BufferSize = 4; //数据循环限值
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; //先进选出模式
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream7, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream7, ENABLE);
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
}
//用于重复发送
void DMA_Test(void)
{
DMA_Cmd(DMA2_Stream7, DISABLE);
DMA_SetCurrDataCounter(DMA2_Stream7,4);
DMA_Cmd(DMA2_Stream7, ENABLE);
}
------------------------------------------------------------------
这样的配置只能发送一次数据,调用DMA_Test也不能再次重发.求解
|
|