ports.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /********************************* (C) РОТЕК ***********************************
  2. * @module buttons_api
  3. * @file buttons_api.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief buttons_api
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "ports.h"
  14. #include "FreeRTOS.h"
  15. #include "task.h"
  16. char recvBufRS232[RS232_MAX_REC_LEN]; // Входной буфер для RS232
  17. uint16_t indexRS232;
  18. /**
  19. * @brief
  20. */
  21. void RS232_Init(void)
  22. {
  23. GPIO_InitTypeDef GPIO_InitStructure;
  24. USART_InitTypeDef USART_InitStructure;
  25. NVIC_InitTypeDef NVIC_InitStructure;
  26. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  27. RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  28. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
  29. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  30. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  31. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  32. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  33. GPIO_Init(GPIOD, &GPIO_InitStructure);
  34. GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
  35. GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
  36. NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  37. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  38. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  39. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  40. NVIC_Init(&NVIC_InitStructure);
  41. NVIC_SetPriority (USART3_IRQn, 5);
  42. USART_InitStructure.USART_BaudRate = 115200;
  43. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  44. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  45. USART_InitStructure.USART_Parity = USART_Parity_No;
  46. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  47. USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  48. USART_Init(RS232_PORT, &USART_InitStructure);
  49. USART_Cmd(RS232_PORT, ENABLE);
  50. USART_ITConfig(RS232_PORT, USART_IT_RXNE, ENABLE);
  51. USART_ITConfig(RS232_PORT, USART_IT_TXE, DISABLE);
  52. }
  53. /**
  54. * @brief RS232
  55. */
  56. /*void USART3_IRQHandler(void)
  57. {
  58. char byte;
  59. if(USART_GetITStatus(RS232_PORT, USART_IT_RXNE) != RESET)
  60. {
  61. byte = (uint8_t)(RS232_PORT->DR & (uint16_t)0x01FF);
  62. recvBufRS232[indexRS232++] = byte;
  63. // Защита от выхода за границу отведенного буфера
  64. if (indexRS232 == (RS232_MAX_REC_LEN - 1))
  65. indexRS232 = 0;
  66. }
  67. }*/
  68. void RS232_SendByte(char byte)
  69. {
  70. while(USART_GetFlagStatus(RS232_PORT, USART_FLAG_TXE) == RESET) {}
  71. RS232_PORT->DR = (byte & (uint16_t)0x01FF);
  72. }
  73. /********************************* (C) РОТЕК **********************************/