新手上路
- 积分
- 49
- 金钱
- 49
- 注册时间
- 2014-4-3
- 在线时间
- 0 小时
|
5金钱
下面是我串口1的配置:
#define USART_TDR_Address (USART1_BASE + 0x28)
#define USART_RDR_Address (USART1_BASE + 0x24)
void BSP_UART1_Init(uint32_t bps)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
DMA_Channel_TypeDef *PosTmp = DMA1_Channel3;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
//Connect pin to Periph //á??óI/O?úμ?×ü??
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
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_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_DeInit(USART1);
USART_InitStructure.USART_BaudRate = bps;
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);
#if 1
/*DMA配置*/
DMA_DeInit(DMA1_Channel2); //USART3_TX ~ CHANNEL2
DMA_InitStructure.DMA_PeripheralBaseAddr =USART_TDR_Address; //USART3->TDR
DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)USART_TX_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //usart3 tx_dr :source of data
DMA_InitStructure.DMA_BufferSize=10; //one byte sizeof(USART3_RX_Buffer) this is DMA1_Channel2->CNDTR;
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; //warning: this is important ,attention please !!!!
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
//===========================================================================================//
DMA_DeInit(DMA1_Channel3); //USART3_RX ~ CHANNEL3
DMA_InitStructure.DMA_PeripheralBaseAddr =USART_RDR_Address;//USART3->RDR
DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)USART_RX_Buffer; // (u32)USART3_TX_Buffer
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //usart3 rx_dr:destination of data
DMA_InitStructure.DMA_BufferSize=10; //one byte (u32)USART3_TX_Buffer this is DMA1_Channel3->CNDTR;
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; //warning: this is important ,attention please !!!!
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
DMA_ClearFlag(DMA1_FLAG_GL2);
DMA_ClearFlag(DMA1_FLAG_GL3);
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA1_Channel2, DISABLE);
DMA_Cmd(DMA1_Channel3, ENABLE);
#endif
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
//USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
USART_Cmd(USART1, ENABLE);
}
在main函数里始终没有进入if判断条件内部
while(1)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC3) != RESET) //检测DMA1TC1标志
{
DMA_ClearFlag(DMA1_FLAG_TC3);//清除DMA TC3标志
memcpy(USART_TX_Buffer,USART_RX_Buffer,10);
uart_printf("1111 CNDTR is %x CRR is %x CMAR is %x CPAR is %x\r\n",PosTmp->CNDTR,PosTmp->CCR,PosTmp->CMAR,PosTmp->CPAR);
}
}
请教各位大神怎么回事?
|
最佳答案
查看完整内容[请看2#楼]
回复【3楼】正点原子:
---------------------------------
多谢,已经搞通了。
|