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.

58 lines
2.1 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
  1. #include "uart0.h"
  2. void uart0_init(void) {
  3. /**
  4. * @brief 0115200
  5. * Fpclk
  6. *
  7. */
  8. GPIO_InitSettingType InitSet;
  9. InitSet.Dir = GPIO_Direction_Output;
  10. InitSet.DS = GPIO_DS_Output_Strong;
  11. InitSet.Func = GPIO_Reuse_Func2;
  12. InitSet.ODE = GPIO_ODE_Output_Disable;
  13. InitSet.PDE = GPIO_PDE_Input_Disable;
  14. InitSet.PUE = GPIO_PUE_Input_Enable;
  15. InitSet.Signal = GPIO_Pin_Signal_Digital;
  16. GPIO_Init(UART0_TXD0_PIN, &InitSet);
  17. InitSet.Dir = GPIO_Direction_Input;
  18. InitSet.DS = GPIO_DS_Output_Strong;
  19. InitSet.Func = GPIO_Reuse_Func2;
  20. InitSet.ODE = GPIO_ODE_Output_Disable;
  21. InitSet.PDE = GPIO_PDE_Input_Disable;
  22. InitSet.PUE = GPIO_PUE_Input_Disable;
  23. InitSet.Signal = GPIO_Pin_Signal_Digital;
  24. GPIO_Init(UART0_RXD0_PIN, &InitSet);
  25. UART_InitStruType UART_InitStruct;
  26. UART_InitStruct.UART_BaudRate = 115200; //波特率
  27. UART_InitStruct.UART_ClockSet = UART_Clock_1; //时钟选择不分频
  28. UART_InitStruct.UART_RxMode = UART_DataMode_8; // 8数据位无奇偶校验位
  29. //标准极性端口数据和传输数据相同
  30. UART_InitStruct.UART_RxPolar = UART_Polar_Normal;
  31. UART_InitStruct.UART_StopBits = UART_StopBits_1; //一个停止位
  32. UART_InitStruct.UART_TxMode = UART_DataMode_8; // 8数据位无奇偶校验位
  33. UART_InitStruct.UART_TxPolar = UART_Polar_Normal; //标准usart极性
  34. UART_Init(UART0, &UART_InitStruct);
  35. UART_ITConfig(UART0, UART_IT_RB, Enable); /* UART0接收中断使能 */
  36. /* UART0发送缓冲区空中断模式: 全空中断 */
  37. UART_TBIMConfig(UART0, UART_TBIM_Byte);
  38. UART_ClearITPendingBit(UART0, UART_FLAG_TB);
  39. UART_ClearITPendingBit(UART0, UART_FLAG_RB);
  40. UART_ClearITPendingBit(UART0, UART_FLAG_FE);
  41. NVIC_Init(NVIC_UART0_IRQn, NVIC_Priority_1, Enable); //使能串口0中断
  42. UART0_TxEnable();
  43. UART0_RxEnable();
  44. }
  45. void fun(void) {}
  46. void Uart0SendBuff(uint8_t *buff) {
  47. while (*buff != '\0') {
  48. // UART_SendByte(UART0, *buff);
  49. while (UART_GetFlagStatus(UART0, UART_FLAG_TC) == RESET)
  50. ;
  51. UART_ClearITPendingBit(UART0, UART_FLAG_TC);
  52. buff++;
  53. }
  54. }