/*******************************************************************************
* Function Name : USART_DMARece
* Description : USART接收函数
* Input : -pBuffer: 接收数据指针
: -NumByteToRece: 接收的字节数
* Output : None
* Return : None
*******************************************************************************/
void USART_DMARece(u8 *pBuffer, u8 NumByteToRece)
{
DMA_USART_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //从存储器读(接收)
DMA_USART_InitStructure.DMA_MemoryBaseAddr = (u32)pBuffer; //存储器地址
DMA_USART_InitStructure.DMA_BufferSize = NumByteToRece; //接收数量
DMA_Init(DMA_Channel5, &DMA_USART_InitStructure);
//禁止读数据寄存器非空
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
/* Enable USART1 DMA RX request */
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
//开启DMA通道5
DMA_Cmd(DMA_Channel5, ENABLE);
if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
//DMA接收完中断
while(!DMA_GetFlagStatus(DMA_FLAG_TC5));
//清中断
DMA_ClearFlag(DMA_FLAG_TC5);
//关闭DMA通道
DMA_Cmd(DMA_Channel5, DISABLE);
/* DISABLE USART1 DMA RX request */
USART_DMACmd(USART1, USART_DMAReq_Rx, DISABLE);
} |