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

STM8S/A

STM8S_StdPeriph_Examples/UART1/UART1_MultiProcessor/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file UART1_MultiProcessor\main.c
00004   * @brief This file contains the main function for:use the UART1 in multi-processor mode example.
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_MultiProcessor
00034   * @{
00035   */
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 /* Private macro -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 /* Private function prototypes -----------------------------------------------*/
00041 static void GPIO_Config(void);
00042 static void UART_Config(void);
00043 void Delay(uint32_t nCount);
00044 /* Private functions ---------------------------------------------------------*/
00045 
00046 /**
00047   * @brief  Main program.
00048   * @param  None
00049   * @retval None
00050   */
00051 void main(void)
00052 {
00053   /* GPIO configuration -----------------------------------------*/
00054   GPIO_Config();
00055 
00056   /* UART configuration -----------------------------------------*/
00057   UART_Config();  
00058     
00059   while (1)
00060   {
00061       /* Send one byte from UART1 to UART3 */
00062       UART1_SendData9(0x33);
00063       
00064       /* Wait while UART1 TXE = 0 */
00065       while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
00066       {
00067       }
00068       if (UART3_GetFlagStatus(UART3_FLAG_RXNE) != RESET)
00069       {
00070           if (UART3_ReceiveData9() == 0x33)
00071           {
00072             STM_EVAL_LEDToggle(LED1);
00073             STM_EVAL_LEDToggle(LED2);
00074             STM_EVAL_LEDToggle(LED3);
00075             STM_EVAL_LEDToggle(LED4);
00076             Delay(0x5FF);
00077           }
00078       }
00079   }
00080 }
00081 
00082 /**
00083   * @brief  Configure GPIO for Leds and buttons available on the evaluation board  
00084   * @param  None
00085   * @retval None
00086   */
00087 static void GPIO_Config(void)
00088 {
00089   /* Initialize I/Os in Output Mode for LEDs */
00090   STM_EVAL_LEDInit(LED1);
00091   STM_EVAL_LEDInit(LED2);
00092   STM_EVAL_LEDInit(LED3);
00093   STM_EVAL_LEDInit(LED4);
00094   
00095   /* Put all Leds On*/
00096   STM_EVAL_LEDOn(LED1);
00097   STM_EVAL_LEDOn(LED2);
00098   STM_EVAL_LEDOn(LED3);
00099   STM_EVAL_LEDOn(LED4);
00100   
00101   /* Initialize I/O for Key button*/
00102   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
00103   
00104   /* Initialize I/O for Joystick Up*/
00105   STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI);  
00106   
00107   enableInterrupts();  
00108 }
00109 
00110 /**
00111   * @brief  UART1 and UART3 Configuration for multi processor communication
00112   * @param  None
00113   * @retval None
00114   */
00115 static void UART_Config(void)
00116 {
00117   UART1_DeInit();
00118   /* UART1 configured as follow:
00119         - BaudRate = 9600 baud  
00120         - Word Length = 9 Bits
00121         - One Stop Bit
00122         - No parity
00123         - Receive and Transmit enabled
00124         - UART1 Clock disabled
00125   */
00126   UART1_Init((uint32_t)9600, UART1_WORDLENGTH_9D, UART1_STOPBITS_1, UART1_PARITY_NO,
00127               UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
00128 
00129   /* Set the UART1 Address */
00130   UART1_SetAddress(0x1);
00131   
00132   UART3_DeInit();
00133   /* UART3 configured as follow:
00134         - BaudRate = 9600 baud  
00135         - Word Length = 9 Bits
00136         - One Stop Bit
00137         - No parity
00138         - Receive and transmit enabled
00139   */
00140   UART3_Init((uint32_t)9600, UART3_WORDLENGTH_9D, UART3_STOPBITS_1, UART3_PARITY_NO,
00141               UART3_MODE_TXRX_ENABLE);
00142 
00143   /* Set the UART3 Address */
00144   UART3_SetAddress(0x2);
00145 
00146   /* Select the UART3 WakeUp Method */
00147   UART3_WakeUpConfig(UART3_WAKEUP_ADDRESSMARK);
00148 }
00149 
00150 /**
00151   * @brief  Delay.
00152   * @param  nCount
00153   * @retval None
00154   */
00155 void Delay(uint32_t nCount)
00156 {
00157   /* Decrement nCount value */
00158   while (nCount != 0)
00159   {
00160     nCount--;
00161   }
00162 }
00163 
00164 #ifdef USE_FULL_ASSERT
00165 
00166 /**
00167   * @brief  Reports the name of the source file and the source line number
00168   *   where the assert_param error has occurred.
00169   * @param file: pointer to the source file name
00170   * @param line: assert_param error line source number
00171   * @retval None
00172   */
00173 void assert_failed(uint8_t* file, uint32_t line)
00174 { 
00175   /* User can add his own implementation to report the file name and line number,
00176      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00177 
00178   /* Infinite loop */
00179   while (1)
00180   {
00181   }
00182 }
00183 #endif
00184 
00185 /**
00186   * @}
00187   */
00188 
00189 
00190 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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