You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.1 KiB
59 lines
2.1 KiB
#include "uart0.h"
|
|
void uart0_init(void) {
|
|
/**
|
|
* @brief 配置串口0的波特率为115200
|
|
* 时钟为系统时钟 Fpclk 为系统时钟频率
|
|
*
|
|
*/
|
|
GPIO_InitSettingType InitSet;
|
|
InitSet.Dir = GPIO_Direction_Output;
|
|
InitSet.DS = GPIO_DS_Output_Strong;
|
|
InitSet.Func = GPIO_Reuse_Func2;
|
|
InitSet.ODE = GPIO_ODE_Output_Disable;
|
|
InitSet.PDE = GPIO_PDE_Input_Disable;
|
|
InitSet.PUE = GPIO_PUE_Input_Enable;
|
|
InitSet.Signal = GPIO_Pin_Signal_Digital;
|
|
GPIO_Init(UART0_TXD0_PIN, &InitSet);
|
|
|
|
InitSet.Dir = GPIO_Direction_Input;
|
|
InitSet.DS = GPIO_DS_Output_Strong;
|
|
InitSet.Func = GPIO_Reuse_Func2;
|
|
InitSet.ODE = GPIO_ODE_Output_Disable;
|
|
InitSet.PDE = GPIO_PDE_Input_Disable;
|
|
InitSet.PUE = GPIO_PUE_Input_Disable;
|
|
InitSet.Signal = GPIO_Pin_Signal_Digital;
|
|
GPIO_Init(UART0_RXD0_PIN, &InitSet);
|
|
|
|
UART_InitStruType UART_InitStruct;
|
|
|
|
UART_InitStruct.UART_BaudRate = 115200; //波特率
|
|
UART_InitStruct.UART_ClockSet = UART_Clock_1; //时钟选择不分频
|
|
UART_InitStruct.UART_RxMode = UART_DataMode_8; // 8数据位无奇偶校验位
|
|
//标准极性端口数据和传输数据相同
|
|
UART_InitStruct.UART_RxPolar = UART_Polar_Normal;
|
|
UART_InitStruct.UART_StopBits = UART_StopBits_1; //一个停止位
|
|
UART_InitStruct.UART_TxMode = UART_DataMode_8; // 8数据位无奇偶校验位
|
|
UART_InitStruct.UART_TxPolar = UART_Polar_Normal; //标准usart极性
|
|
UART_Init(UART0, &UART_InitStruct);
|
|
UART_ITConfig(UART0, UART_IT_RB, Enable); /* UART0接收中断使能 */
|
|
/* UART0发送缓冲区空中断模式: 全空中断 */
|
|
UART_TBIMConfig(UART0, UART_TBIM_Byte);
|
|
UART_ClearITPendingBit(UART0, UART_FLAG_TB);
|
|
UART_ClearITPendingBit(UART0, UART_FLAG_RB);
|
|
UART_ClearITPendingBit(UART0, UART_FLAG_FE);
|
|
NVIC_Init(NVIC_UART0_IRQn, NVIC_Priority_1, Enable); //使能串口0中断
|
|
UART0_TxEnable();
|
|
UART0_RxEnable();
|
|
}
|
|
|
|
void fun(void) {}
|
|
|
|
void Uart0SendBuff(uint8_t *buff) {
|
|
while (*buff != '\0') {
|
|
// UART_SendByte(UART0, *buff);
|
|
while (UART_GetFlagStatus(UART0, UART_FLAG_TC) == RESET)
|
|
;
|
|
UART_ClearITPendingBit(UART0, UART_FLAG_TC);
|
|
buff++;
|
|
}
|
|
}
|