STM8S/A Standard Peripherals Firmware Library: main.c Source File

STM8S/A

STM8S_StdPeriph_Examples/UART1/UART1_IrDA/Receive/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file UART1_IrDA\Receive\main.c
00004   * @brief This file contains the main function for UART1 in IrDA receive mode.
00005   * @author  MCD Application Team
00006   * @version  V2.2.0
00007   * @date     30-September-2014
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */ 
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm8s.h"
00030 #include "stm8s_eval.h"
00031 
00032 /**
00033   * @addtogroup UART1_IrDA_Receive
00034   * @{
00035   */
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 uint8_t ReceivedData = 0;
00039 /* Private macro -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 /* Private function prototypes -----------------------------------------------*/
00042 static void GPIO_Config(void);
00043 static void UART1_Config(void);
00044 /* Private functions ---------------------------------------------------------*/
00045 /**
00046   * @brief  Main program.
00047   * @param  None
00048   * @retval None
00049   */
00050 void main(void)
00051 {
00052   /* GPIO configuration -----------------------------------------*/
00053   GPIO_Config();  
00054   
00055   /* UART1 configuration -----------------------------------------*/
00056   UART1_Config();  
00057     
00058     while (1)
00059     {
00060       /* Wait until a byte is received */
00061       while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
00062       {}
00063       /* Read the received byte */
00064       ReceivedData = UART1_ReceiveData8();
00065 
00066       switch (ReceivedData)
00067       {
00068         /* LED4 toggle */
00069         case JOY_UP:
00070           STM_EVAL_LEDToggle(LED4);
00071           break;
00072         /* LED3 toggle */
00073         case JOY_DOWN:
00074           STM_EVAL_LEDToggle(LED3);
00075           break;
00076         /* LED2 toggle */
00077         case JOY_LEFT:
00078           STM_EVAL_LEDToggle(LED2);
00079           break;
00080         /* LED1 toggle */
00081         case JOY_RIGHT:
00082           STM_EVAL_LEDToggle(LED1);
00083           break;
00084 
00085         case JOY_SEL:
00086           STM_EVAL_LEDToggle(LED1);
00087           STM_EVAL_LEDToggle(LED2);
00088           STM_EVAL_LEDToggle(LED3);
00089           STM_EVAL_LEDToggle(LED4);
00090           break;
00091         default:
00092           break;
00093     }
00094     }
00095 
00096 }
00097 /**
00098   * @brief  Configures the Multiplexer on the evaluation board  to select the IrDA
00099   *         and initialize GPIO for LEDs. 
00100   * @param  None
00101   * @retval None
00102   */
00103 static void GPIO_Config(void)
00104 {
00105   /* Configures the Multiplexer on the evaluation board to select the IrDA */
00106   /* Initialize I/Os in Output PP Mode */
00107   GPIO_Init(GPIOF, GPIO_PIN_6 ,GPIO_MODE_OUT_PP_LOW_FAST);
00108   GPIO_Init(GPIOF, GPIO_PIN_5 ,GPIO_MODE_OUT_PP_HIGH_FAST);
00109     
00110   /* Initialize I/Os in Output Mode for LEDs */
00111   STM_EVAL_LEDInit(LED1);
00112   STM_EVAL_LEDInit(LED2);
00113   STM_EVAL_LEDInit(LED3);
00114   STM_EVAL_LEDInit(LED4);
00115 
00116   /* Turn on LEDs */
00117   STM_EVAL_LEDOn(LED1);
00118   STM_EVAL_LEDOn(LED2);
00119   STM_EVAL_LEDOn(LED3);
00120   STM_EVAL_LEDOn(LED4);
00121 }
00122 
00123 /**
00124   * @brief  Configure UART1 for the communication with IrDA
00125   * @param  None
00126   * @retval None
00127   */
00128 static void UART1_Config(void)
00129 {
00130   UART1_DeInit();
00131   
00132   /* UART1 configured as follow:
00133           - Word Length = 8 Bits
00134           - One Stop Bit
00135           - No parity
00136           - BaudRate = 9600 baud
00137           - Tx and Rx enabled
00138           - UART1 Clock disabled
00139   */
00140   UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,
00141               UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
00142 
00143   /* Set Prescaler*/
00144   UART1_SetPrescaler(0x1);
00145 
00146   UART1_IrDAConfig(UART1_IRDAMODE_NORMAL);
00147 
00148   UART1_IrDACmd(ENABLE);
00149 }
00150 #ifdef USE_FULL_ASSERT
00151 
00152 /**
00153   * @brief  Reports the name of the source file and the source line number
00154   *   where the assert_param error has occurred.
00155   * @param file: pointer to the source file name
00156   * @param line: assert_param error line source number
00157   * @retval None
00158   */
00159 void assert_failed(uint8_t* file, uint32_t line)
00160 { 
00161   /* User can add his own implementation to report the file name and line number,
00162      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00163 
00164   /* Infinite loop */
00165   while (1)
00166   {
00167   }
00168 }
00169 #endif
00170 
00171 /**
00172   * @}
00173   */
00174 
00175 
00176 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com