UART_DMA.C 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "UART_DMA.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. void NVIC_ConfigurationUSART1 ( void )
  48. {
  49. NVIC_InitTypeDef NVIC_InitStructure;
  50. /* Configure the NVIC Preemption Priority Bits */
  51. NVIC_PriorityGroupConfig ( Wifi_NVIC_Group );
  52. /* Enable the USARTy Interrupt */
  53. NVIC_InitStructure.NVIC_IRQChannel = Wifi_NVIC_Interrupt;
  54. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = Wifi_NVIC_Pre;
  55. NVIC_InitStructure.NVIC_IRQChannelSubPriority = Wifi_NVIC_Sub;
  56. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  57. NVIC_Init ( &NVIC_InitStructure );
  58. }
  59. void UartSend ( char *buffer, int nBytes )
  60. {
  61. // Wait for previous xmt to complete
  62. while ( TxCounterUart < UartSendCount );
  63. // Setup next XMT
  64. memcpy ( TxBufferUart, buffer, nBytes );
  65. TxCounterUart = 0;
  66. UartSendCount = nBytes;
  67. USART_ITConfig ( USART1, USART_IT_TXE, ENABLE );
  68. }