STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/CEC/CEC_MultiAddress/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    CEC/CEC_MultiAddress/main.c 
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    24-July-2014
00007   * @brief   Main program body
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 "main.h"
00030 
00031 /** @addtogroup STM32F0xx_StdPeriph_Examples
00032   * @{
00033   */
00034 
00035 /** @addtogroup CEC_MultiAddress
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 
00044 uint8_t MyLogicalAddress1 = 0x0, MyLogicalAddress2 = 0x0;
00045 uint8_t MyFollowerAddress1 = 0x0, MyFollowerAddress2 = 0x0;
00046 __IO uint8_t TransferStatus = 0;
00047 extern uint8_t ReceiverAddress;
00048 extern __IO uint8_t CECReceivedFrame;
00049 
00050 /* Private function prototypes -----------------------------------------------*/
00051 static void CEC_Config(void);
00052 
00053 /* Private functions ---------------------------------------------------------*/
00054 
00055 /**
00056   * @brief  Main program.
00057   * @param  None
00058   * @retval None
00059   */
00060 int main(void)
00061 {
00062   /*!< At this stage the microcontroller clock setting is already configured, 
00063   this is done through SystemInit() function which is called from startup
00064   file (startup_stm32f0xx.s) before to branch to application main.
00065   To reconfigure the default setting of SystemInit() function, refer to
00066   system_stm32f0xx.c file
00067   */
00068 #ifdef LCD_DISPLAY
00069   /* Initialize the LCD */
00070 #ifdef USE_STM320518_EVAL
00071     STM320518_LCD_Init();
00072 #else
00073     STM32072B_LCD_Init();
00074 #endif /* USE_STM320518_EVAL */
00075 #endif /* LCD_DISPLAY */
00076 
00077   /* Initialize LEDs available on STM320518-EVAL board */
00078   /* Configure LED1, LED2, LED3 and LED4 */
00079   STM_EVAL_LEDInit(LED1);
00080   STM_EVAL_LEDInit(LED2);
00081   STM_EVAL_LEDInit(LED3);
00082   STM_EVAL_LEDInit(LED4);
00083 
00084 #if defined (DEVICE_1)
00085   /* Configure the Joystick button and its associated EXTI Line */
00086   STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI);
00087   STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_EXTI);
00088 
00089   MyLogicalAddress1 = DEVICE_ADDRESS_1;
00090   MyFollowerAddress1 = DEVICE_ADDRESS_2;
00091   MyFollowerAddress2 = DEVICE_ADDRESS_3;
00092 #elif defined (DEVICE_2)
00093   MyLogicalAddress1 = DEVICE_ADDRESS_2;
00094   MyLogicalAddress2 = DEVICE_ADDRESS_3;
00095   MyFollowerAddress1 = DEVICE_ADDRESS_1;
00096 #endif /* DEVICE_1 */
00097 
00098   /* CEC configuration */
00099   CEC_Config();
00100 
00101 #ifdef LCD_DISPLAY
00102   /* Clear the LCD */
00103   LCD_Clear(LCD_COLOR_WHITE);
00104   LCD_SetBackColor(LCD_COLOR_BLACK);
00105   LCD_SetTextColor(LCD_COLOR_WHITE);
00106 #if defined (DEVICE_1)
00107   LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)"CEC Initiator device");
00108   LCD_SetBackColor(LCD_COLOR_WHITE);
00109   LCD_SetTextColor(LCD_COLOR_BLUE);
00110   LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)"Choose CEC Follower ");
00111   LCD_DisplayStringLine(LCD_LINE_3, (uint8_t *)"Address :           ");
00112   LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"RIGHT=> Tuner       ");
00113   LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"LEFT => Audio System");
00114 #elif defined (DEVICE_2) 
00115   LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)"CEC Follower device ");
00116 #endif /* DEVICE_1 */
00117 #endif /* LCD_DISPLAY */
00118 
00119   while(1)
00120   {
00121     /* If a frame has been received */
00122     while(CECReceivedFrame == 0)
00123     {}
00124 
00125     if (CECReceivedFrame == 1)
00126     {
00127       if ((ReceiverAddress&0xF) == 0x03) /* Test on the Receiver value */
00128       {
00129         /* Turn on LED1 */
00130         STM_EVAL_LEDOn(LED1);
00131         /* Turn off LED4 */
00132         STM_EVAL_LEDOff(LED4);
00133         /* Turn off LED3 */
00134         STM_EVAL_LEDOff(LED3);
00135 #ifdef LCD_DISPLAY
00136         LCD_SetBackColor(LCD_COLOR_GREEN);
00137         LCD_SetTextColor(LCD_COLOR_WHITE);
00138         LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Receive : Succeeded ");
00139         LCD_DisplayStringLine(LCD_LINE_8, (uint8_t *)"Receiver Address is ");
00140         LCD_DisplayStringLine(LCD_LINE_9, (uint8_t *)"       Tuner        ");
00141 #endif /* LCD_DISPLAY */
00142       }
00143       else if ((ReceiverAddress &0xF) ==0x05) /* Test on the Receiver value */
00144       {
00145         /* Turn on LED4 */
00146         STM_EVAL_LEDOn(LED4);
00147         /* Turn off LED1 */
00148         STM_EVAL_LEDOff(LED1);
00149          /* Turn off LED3 */
00150         STM_EVAL_LEDOff(LED3);
00151 #ifdef LCD_DISPLAY
00152         LCD_SetBackColor(LCD_COLOR_BLUE2);
00153         LCD_SetTextColor(LCD_COLOR_WHITE);
00154         LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Receive : Succeeded ");
00155         LCD_DisplayStringLine(LCD_LINE_8, (uint8_t *)"Receiver Address is ");
00156         LCD_DisplayStringLine(LCD_LINE_9, (uint8_t *)"   Audio System     ");
00157 #endif /* LCD_DISPLAY */
00158       }
00159     }
00160     else
00161     {
00162       /* KO */
00163       /* Turn on LED3 */
00164       STM_EVAL_LEDOn(LED3);
00165 #ifdef LCD_DISPLAY
00166       LCD_SetTextColor(LCD_COLOR_WHITE);
00167       LCD_SetBackColor(LCD_COLOR_RED);
00168       LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Receive : Failed    ");
00169 #endif /* LCD_DISPLAY */
00170     }
00171 
00172     CECReceivedFrame = 0;
00173   }
00174 }
00175 /**
00176   * @brief  Configures the CEC peripheral.
00177   * @param  None
00178   * @retval None
00179   */
00180 static void CEC_Config(void)
00181 {
00182   CEC_InitTypeDef CEC_InitStructure;
00183   NVIC_InitTypeDef NVIC_InitStructure;
00184   GPIO_InitTypeDef GPIO_InitStructure;
00185 
00186   /* Enable CEC clocks */
00187   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC , ENABLE);
00188 
00189   /* Enable CEC_LINE_GPIO clocks */
00190   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
00191 
00192   /* Configure CEC_LINE_GPIO as Output open drain */
00193 #ifdef USE_STM320518_EVAL
00194   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
00195 #else
00196   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
00197 #endif /* USE_STM320518_EVAL */  
00198   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
00199   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00200   GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
00201   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
00202   GPIO_Init(GPIOB, &GPIO_InitStructure);
00203 
00204   /* Enable the CEC global Interrupt (with higher priority) */
00205 #ifdef USE_STM320518_EVAL
00206   NVIC_InitStructure.NVIC_IRQChannel = CEC_IRQn;
00207 #else
00208   NVIC_InitStructure.NVIC_IRQChannel = CEC_CAN_IRQn;
00209 #endif /* USE_STM320518_EVAL */
00210   NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
00211   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00212   NVIC_Init(&NVIC_InitStructure);
00213 
00214   /* Configure CEC */
00215   CEC_InitStructure.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard;
00216   CEC_InitStructure.CEC_RxTolerance = CEC_RxTolerance_Standard;
00217   CEC_InitStructure.CEC_StopReception = CEC_StopReception_Off;
00218   CEC_InitStructure.CEC_BitRisingError = CEC_BitRisingError_Off;
00219   CEC_InitStructure.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off;
00220   CEC_InitStructure.CEC_BRDNoGen = CEC_BRDNoGen_Off;
00221   CEC_InitStructure.CEC_SFTOption = CEC_SFTOption_Off;
00222   CEC_Init(&CEC_InitStructure);
00223 
00224   /* Set the CEC initiator address */
00225   CEC_OwnAddressConfig(MyLogicalAddress1);
00226 
00227 #if defined (DEVICE_2)
00228   /* Set the CEC initiator address 2 */
00229   CEC_OwnAddressConfig(MyLogicalAddress2);
00230 #endif /* DEVICE_2 */
00231 
00232 #if defined (DEVICE_1)
00233   /* Activate CEC interrupts associated to the set of TX flags */
00234   CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE);
00235 
00236   /* Activate CEC interrupts associated to the set of TX error */
00237   CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_TXUDR|CEC_IT_ARBLST,ENABLE);
00238 
00239 #elif defined (DEVICE_2)
00240   /* Activate CEC interrupts associated to the set of RX flags */
00241   CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE);
00242 
00243   /* Activate CEC interrupts associated to the set of RX error */
00244   CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE|CEC_IT_RXOVR,ENABLE);
00245 #endif /* DEVICE_1 */
00246   /* Enable CEC */
00247   CEC_Cmd(ENABLE);
00248 }
00249 
00250 
00251 #ifdef  USE_FULL_ASSERT
00252 
00253 /**
00254   * @brief  Reports the name of the source file and the source line number
00255   *         where the assert_param error has occurred.
00256   * @param  file: pointer to the source file name
00257   * @param  line: assert_param error line source number
00258   * @retval None
00259   */
00260 void assert_failed(uint8_t* file, uint32_t line)
00261 { 
00262   /* User can add his own implementation to report the file name and line number,
00263      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00264 
00265   /* Infinite loop */
00266   while (1)
00267   {
00268   }
00269 }
00270 #endif
00271 
00272 /**
00273   * @}
00274   */
00275 
00276 /**
00277   * @}
00278   */
00279 
00280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32