串口数据配置
void macUART4_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(macUART4_RX_GPIO_CLK|macUART4_TX_GPIO_CLK,ENABLE);
RCC_APB1PeriphClockCmd(macUART4_CLK, ENABLE);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = macUART4_TX_PIN ;
GPIO_Init(macUART4_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = macUART4_RX_PIN;
GPIO_Init(macUART4_RX_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(macUART4_RX_GPIO_PORT,macUART4_RX_SOURCE,macUART4_RX_AF);
GPIO_PinAFConfig(macUART4_TX_GPIO_PORT,macUART4_TX_SOURCE,macUART4_TX_AF);
USART_InitStructure.USART_BaudRate = macUART4_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(macUART4, &USART_InitStructure);
USART_Cmd(macUART4, ENABLE);
}
DMA配置函数,请和DMA串口接收数据配置函数对比
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure; //
RCC_AHB1PeriphClockCmd(macUART4_DMA_CLK, ENABLE); //
DMA_DeInit(macUART4_TX_DMA_STREAM); //
while (DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != DISABLE){
}
DMA_InitStructure.DMA_Channel = macUART4_TX_DMA_CHANNEL; //
DMA_InitStructure.DMA_PeripheralBaseAddr = macUART4_DR_BASE; //
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)SendBuff; //
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; //
DMA_InitStructure.DMA_BufferSize = macUART4_SEND_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_Circular; //
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //
DMA_Init(macUART4_TX_DMA_STREAM, &DMA_InitStructure); //
DMA_Cmd(macUART4_TX_DMA_STREAM, ENABLE);
while(DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != ENABLE)
{
}
}
主函数,调试串口和UART4同时发送数据,相互并不影响
int main(void)
{
int i;
SysTick_Init();
NVIC_Configuration();
Debug_USART_Config();
macUART4_Config();
DMA_Config();
printf("Hello World!nn");
for(i=0;i
{
SendBuff
= 'A';
}
USART_DMACmd(macUART4, USART_DMAReq_Tx, ENABLE);
while(1)
{
printf("Hello World!n");
}
}
该程序中没有涉及中断程序,DMA的使用本应该尽量避免使用中断。
串口数据配置
void macUART4_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(macUART4_RX_GPIO_CLK|macUART4_TX_GPIO_CLK,ENABLE);
RCC_APB1PeriphClockCmd(macUART4_CLK, ENABLE);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = macUART4_TX_PIN ;
GPIO_Init(macUART4_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = macUART4_RX_PIN;
GPIO_Init(macUART4_RX_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(macUART4_RX_GPIO_PORT,macUART4_RX_SOURCE,macUART4_RX_AF);
GPIO_PinAFConfig(macUART4_TX_GPIO_PORT,macUART4_TX_SOURCE,macUART4_TX_AF);
USART_InitStructure.USART_BaudRate = macUART4_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(macUART4, &USART_InitStructure);
USART_Cmd(macUART4, ENABLE);
}
DMA配置函数,请和DMA串口接收数据配置函数对比
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure; //
RCC_AHB1PeriphClockCmd(macUART4_DMA_CLK, ENABLE); //
DMA_DeInit(macUART4_TX_DMA_STREAM); //
while (DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != DISABLE){
}
DMA_InitStructure.DMA_Channel = macUART4_TX_DMA_CHANNEL; //
DMA_InitStructure.DMA_PeripheralBaseAddr = macUART4_DR_BASE; //
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)SendBuff; //
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; //
DMA_InitStructure.DMA_BufferSize = macUART4_SEND_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_Circular; //
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //
DMA_Init(macUART4_TX_DMA_STREAM, &DMA_InitStructure); //
DMA_Cmd(macUART4_TX_DMA_STREAM, ENABLE);
while(DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != ENABLE)
{
}
}
主函数,调试串口和UART4同时发送数据,相互并不影响
int main(void)
{
int i;
SysTick_Init();
NVIC_Configuration();
Debug_USART_Config();
macUART4_Config();
DMA_Config();
printf("Hello World!nn");
for(i=0;i
{
SendBuff = 'A';
}
USART_DMACmd(macUART4, USART_DMAReq_Tx, ENABLE);
while(1)
{
printf("Hello World!n");
}
}
该程序中没有涉及中断程序,DMA的使用本应该尽量避免使用中断。
举报