Uart1.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "uart1.h"
  2. uint8_t TxBufferUart[256] = { 0 };
  3. uint8_t RxBufferUart[256] = { 0 };
  4. __IO uint8_t TxCounterUart = 0x00;
  5. __IO uint8_t RxCounterUart = 0x00;
  6. uint8_t UartSendCount = 0;
  7. /*******************************************************************************
  8. * Function Name : USART_Configuration
  9. * Description : Configure USART1
  10. * Input : None
  11. * Output : None
  12. * Return : None
  13. * Attention : None
  14. *******************************************************************************/
  15. void ConfigurationUsart1 ( void )
  16. {
  17. #if UART1_SD_def
  18. GPIO_InitTypeDef GPIO_InitStructure;
  19. USART_InitTypeDef USART_InitStructure;
  20. //使能USART1/GPIO 时钟可配置
  21. Wifi_RCC_GPIO_CONFIG();
  22. Wifi_RCC_UART_CONFIG();
  23. /*
  24. * USART1_TX -> PA9 , USART1_RX -> PA10
  25. */
  26. GPIO_InitStructure.GPIO_Pin = Wifi_Tx;
  27. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  28. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  29. GPIO_Init ( Wifi_GPIO, &GPIO_InitStructure );
  30. GPIO_InitStructure.GPIO_Pin = Wifi_Rx;
  31. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  32. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  33. GPIO_Init ( Wifi_GPIO, &GPIO_InitStructure );
  34. USART_InitStructure.USART_BaudRate = Wifi_UART_BAUD;
  35. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  36. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  37. USART_InitStructure.USART_Parity = USART_Parity_No;
  38. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  39. USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  40. USART_Init ( Wifi_UART, &USART_InitStructure );
  41. //USART_ITConfig ( Wifi_UART, USART_IT_RXNE, ENABLE );
  42. //USART_ITConfig ( Wifi_UART, USART_IT_TXE, DISABLE );
  43. USART_Cmd ( Wifi_UART, ENABLE );
  44. #endif
  45. }
  46. //系统中断管理
  47. #if 0
  48. void NVIC_ConfigurationUSART1 ( void )
  49. {
  50. NVIC_InitTypeDef NVIC_InitStructure;
  51. /* Configure the NVIC Preemption Priority Bits */
  52. NVIC_PriorityGroupConfig ( Wifi_NVIC_Group );
  53. /* Enable the USARTy Interrupt */
  54. NVIC_InitStructure.NVIC_IRQChannel = Wifi_NVIC_Interrupt;
  55. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = Wifi_NVIC_Pre;
  56. NVIC_InitStructure.NVIC_IRQChannelSubPriority = Wifi_NVIC_Sub;
  57. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  58. NVIC_Init ( &NVIC_InitStructure );
  59. }
  60. #endif
  61. void UartSend ( char *buffer, int nBytes )
  62. {
  63. // Wait for previous xmt to complete
  64. while ( TxCounterUart < UartSendCount );
  65. // Setup next XMT
  66. memcpy ( TxBufferUart, buffer, nBytes );
  67. TxCounterUart = 0;
  68. UartSendCount = nBytes;
  69. USART_ITConfig ( USART1, USART_IT_TXE, ENABLE );
  70. }