大学生
最后登录1970-1-1
在线时间 小时
注册时间2016-8-29
|
楼主 |
发表于 2016-9-14 14:33:34
|
显示全部楼层
这是NVIC和串口DMA的配置..
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* ÅäÖÃÖD¶ÏÔ′ */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART2_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(DEBUG_USART_DMA_CLK, ENABLE);
DMA_DeInit(DEBUG_USART_DMA_STREAM);
while (DMA_GetCmdStatus(DEBUG_USART_DMA_STREAM) != DISABLE);
/*usart2 Rx dma1,channel4,stream5*/
DMA_InitStructure.DMA_Channel = DEBUG_USART_DMA_CHANNEL;
DMA_InitStructure.DMA_PeripheralBaseAddr = DEBUG_USART_DR_BASE;
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)RecvBuff;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = BUFF_SIZE;
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_Mode_Circular; //
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
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(DEBUG_USART_DMA_STREAM, &DMA_InitStructure);
//¿aÆôDMAêy¾Y·¢Ëííê3éÖD¶Ï
DMA_ITConfig(DEBUG_USART_DMA_STREAM,DMA_IT_TC,ENABLE);
//Çå±êÖ¾
DMA_ClearITPendingBit(DEBUG_USART_DMA_STREAM,DMA_IT_TCIF5);
//¿aÆô′®¿ú½óêÕÇëÇó
USART_DMACmd(RS232_USART, USART_DMAReq_Rx, ENABLE);
//¿aÆôDMA
DMA_Cmd(DEBUG_USART_DMA_STREAM, ENABLE);
/* μè′yDMAá÷óDD§*/
while(DMA_GetCmdStatus(DEBUG_USART_DMA_STREAM) != ENABLE);
USART_Cmd(RS232_USART, ENABLE);
}
void USART2_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd( RS232_USART_RX_GPIO_CLK|RS232_USART_TX_GPIO_CLK, ENABLE);
/* ê1Äü USART2 ê±Öó */
RCC_APB1PeriphClockCmd(RS232_USART_CLK, ENABLE);
/* ᬽó PXx μ½ USARTx_Tx*/
GPIO_PinAFConfig(RS232_USART_RX_GPIO_PORT,RS232_USART_RX_SOURCE, RS232_USART_RX_AF);
/* ᬽó PXx μ½ USARTx__Rx*/
GPIO_PinAFConfig(RS232_USART_TX_GPIO_PORT,RS232_USART_TX_SOURCE,RS232_USART_TX_AF);
/* ÅäÖÃTxòy½ÅÎa¸′óÃ1|Äü */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = RS232_USART_TX_PIN ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(RS232_USART_TX_GPIO_PORT, &GPIO_InitStructure);
/* ÅäÖÃRxòy½ÅÎa¸′óÃ1|Äü */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = RS232_USART_RX_PIN;
GPIO_Init(RS232_USART_RX_GPIO_PORT, &GPIO_InitStructure);
/* ÅäÖÃ′®¿úRS232_USART Ä£ê½ */
USART_InitStructure.USART_BaudRate = RS232_USART_BAUDRATE;
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(RS232_USART, &USART_InitStructure);
//USART_ITConfig(RS232_USART, USART_IT_RXNE, ENABLE);
}
///Öض¨Ïòc¿aoˉêyprintfμ½′®¿úRS232_USART£¬Öض¨Ïòoó¿éê1óÃprintfoˉêy
int fputc(int ch, FILE *f)
{
/* ·¢Ëíò»¸ö×Ö½úêy¾Yμ½′®¿úRS232_USART */
USART_SendData(RS232_USART, (uint8_t) ch);
/* μè′y·¢Ëííê±Ï */
while (USART_GetFlagStatus(RS232_USART, USART_FLAG_TXE) == RESET);
return (ch);
}
/*********************************************END OF FILE**********************/ |
|