PageRenderTime 27ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/DOC/mcu/stsw-stm32054/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/IrDA/Receive/main.c

https://gitlab.com/avr_master/Doggy_SFP
C | 224 lines | 99 code | 29 blank | 96 comment | 3 complexity | 2fc2a1f870c59c3e49e91ec11afad28e MD5 | raw file
  1. /**
  2. ******************************************************************************
  3. * @file USART/IrDA/Receive/main.c
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 08-April-2011
  7. * @brief Main program body
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  19. ******************************************************************************
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f10x.h"
  23. #include "platform_config.h"
  24. /** @addtogroup STM32F10x_StdPeriph_Examples
  25. * @{
  26. */
  27. /** @addtogroup USART_IrDA_Receive
  28. * @{
  29. */
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* Private define ------------------------------------------------------------*/
  32. /* Private macro -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. USART_InitTypeDef USART_InitStructure;
  35. JOYState_TypeDef ReceivedData = JOY_NONE;
  36. /* Private function prototypes -----------------------------------------------*/
  37. void RCC_Configuration(void);
  38. void GPIO_Configuration(void);
  39. /* Private functions ---------------------------------------------------------*/
  40. /**
  41. * @brief Main program
  42. * @param None
  43. * @retval None
  44. */
  45. int main(void)
  46. {
  47. /*!< At this stage the microcontroller clock setting is already configured,
  48. this is done through SystemInit() function which is called from startup
  49. file (startup_stm32f10x_xx.s) before to branch to application main.
  50. To reconfigure the default setting of SystemInit() function, refer to
  51. system_stm32f10x.c file
  52. */
  53. /* System Clocks Configuration */
  54. RCC_Configuration();
  55. /* Configure the GPIO ports */
  56. GPIO_Configuration();
  57. /* Initialize Leds mounted on STM3210X-EVAL board */
  58. STM_EVAL_LEDInit(LED1);
  59. STM_EVAL_LEDInit(LED2);
  60. STM_EVAL_LEDInit(LED3);
  61. STM_EVAL_LEDInit(LED4);
  62. /* USARTy configuration ------------------------------------------------------*/
  63. /* USARTy configured as follow:
  64. - BaudRate = 115200 baud
  65. - Word Length = 8 Bits
  66. - One Stop Bit
  67. - No parity
  68. - Hardware flow control disabled (RTS and CTS signals)
  69. - Receive and transmit enabled
  70. */
  71. USART_InitStructure.USART_BaudRate = 115200;
  72. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  73. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  74. USART_InitStructure.USART_Parity = USART_Parity_No ;
  75. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  76. USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  77. /* Configure the USARTy */
  78. USART_Init(USARTy, &USART_InitStructure);
  79. /* Enable the USARTy */
  80. USART_Cmd(USARTy, ENABLE);
  81. /* Set the USARTy prescaler */
  82. USART_SetPrescaler(USARTy, 0x1);
  83. /* Configure the USARTy IrDA mode */
  84. USART_IrDAConfig(USARTy, USART_IrDAMode_Normal);
  85. /* Enable the USARTy IrDA mode */
  86. USART_IrDACmd(USARTy, ENABLE);
  87. while (1)
  88. {
  89. /* Wait until a byte is received */
  90. while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
  91. {
  92. }
  93. /* Read the received byte */
  94. ReceivedData = (JOYState_TypeDef)USART_ReceiveData(USARTy);
  95. switch(ReceivedData)
  96. {
  97. case JOY_UP:
  98. STM_EVAL_LEDOn(LED1);
  99. STM_EVAL_LEDOff(LED2);
  100. STM_EVAL_LEDOff(LED3);
  101. STM_EVAL_LEDOff(LED4);
  102. break;
  103. case JOY_DOWN:
  104. STM_EVAL_LEDOn(LED2);
  105. STM_EVAL_LEDOff(LED1);
  106. STM_EVAL_LEDOff(LED3);
  107. STM_EVAL_LEDOff(LED4);
  108. break;
  109. case JOY_LEFT:
  110. STM_EVAL_LEDOn(LED3);
  111. STM_EVAL_LEDOff(LED1);
  112. STM_EVAL_LEDOff(LED2);
  113. STM_EVAL_LEDOff(LED4);
  114. break;
  115. case JOY_RIGHT:
  116. STM_EVAL_LEDOn(LED4);
  117. STM_EVAL_LEDOff(LED1);
  118. STM_EVAL_LEDOff(LED2);
  119. STM_EVAL_LEDOff(LED3);
  120. break;
  121. case JOY_SEL:
  122. STM_EVAL_LEDOn(LED1);
  123. STM_EVAL_LEDOn(LED2);
  124. STM_EVAL_LEDOn(LED3);
  125. STM_EVAL_LEDOn(LED4);
  126. break;
  127. case JOY_NONE:
  128. break;
  129. default:
  130. break;
  131. }
  132. }
  133. }
  134. /**
  135. * @brief Configures the different system clocks.
  136. * @param None
  137. * @retval None
  138. */
  139. void RCC_Configuration(void)
  140. {
  141. /* Enable GPIO clock */
  142. RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
  143. /* Enable USARTy clocks */
  144. RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);
  145. }
  146. /**
  147. * @brief Configures the different GPIO ports.
  148. * @param None
  149. * @retval None
  150. */
  151. void GPIO_Configuration(void)
  152. {
  153. GPIO_InitTypeDef GPIO_InitStructure;
  154. #ifndef USE_STM3210C_EVAL
  155. /* Enable the USART3 Pins Partial Software Remapping */
  156. GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
  157. #else
  158. /* Enable the USART2 Pins Software Remapping */
  159. GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
  160. #endif
  161. /* Configure USARTy Tx as alternate function push-pull */
  162. GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
  163. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  164. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  165. GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
  166. /* Configure USARTy Rx as input floating */
  167. GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
  168. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  169. GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
  170. }
  171. #ifdef USE_FULL_ASSERT
  172. /**
  173. * @brief Reports the name of the source file and the source line number
  174. * where the assert_param error has occurred.
  175. * @param file: pointer to the source file name
  176. * @param line: assert_param error line source number
  177. * @retval None
  178. */
  179. void assert_failed(uint8_t* file, uint32_t line)
  180. {
  181. /* User can add his own implementation to report the file name and line number,
  182. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  183. /* Infinite loop */
  184. while (1)
  185. {
  186. }
  187. }
  188. #endif
  189. /**
  190. * @}
  191. */
  192. /**
  193. * @}
  194. */
  195. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/