/**
  @page I2C_TwoBoards  I2C Communication Boards Data Exchange using CPAL Library
  
  @verbatim
  ******************** (C) COPYRIGHT 2012 STMicroelectronics *******************
  * @file    I2C/I2C_TwoBoards/readme.txt 
  * @author  MCD Application Team
  * @version V1.0.0
  * @date    18-May-2012
  * @brief   Description of the CPAL Two Boards communication example.
  ******************************************************************************
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
   @endverbatim

@par Example Description 

This example shows how to use the CPAL library to control I2C devices and 
communicate between two different boards.

To use this example, you need to load the same software into two STM32 boards
(let's call them  Board A and Board B) then connect these two boards through I2C
lines and Gnd.

*------------------------------------------------------------------------------*
|                BOARD A                                BOARD B                |
|         ____________________                   ____________________          |
|        |                    |                 |                    |         |
|        |                    |                 |                    |         | 
|        |     __________     |                 |     __________     |         |
|        |    |I2C Device|____|_______SCL_______|____|I2C Device|    |         |
|        |    |__________|____|_______SDA_______|____|__________|    |         |
|        |                    |                 |                    |         |
|        |                    |                 |                    |         |
|        |  Tamper      Key   |                 |  Tamper      Key   |         |
|        |   _           _    |                 |   _           _    |         |
|        |  |_|         |_|   |                 |  |_|         |_|   |         |
|        |                    |                 |                    |         |
|        |             GND O--|-----------------|--O GND             |         |
|        |____________________|                 |____________________|         |
|                                                                              |
|                                                                              |
*------------------------------------------------------------------------------*

The example software perform the following actions:
 - At startup, Boards A & B are both in slave receiver mode and wait for messages 
   to be received.
 - When a push button is pressed, for example on Board A, the master transmitter 
   mode is activated and a message is sent to Board B containing identification 
   of the action relative to the push button.
 - Once a message is correctly sent, Board A activates the master transmitter mode 
   permanently and disables the slave receiver mode.
 - Once a message is received and correctly recognized, Board B activate the
   receiver mode and disable the transmitter mode. (push buttons interrupts are
   still active but message sending is disabled).
 - According to the push button pressed, a value is affected to a Timer which 
   generates periodic high priority interrupts. At each interrupt, a status message
   is sent to Board B. The period of Timer interrupts is variable depending on
   the push button pressed.    
 - When Key is pressed Board A send specific message (tSignal1) to Board B and set 
   the period of Timer to 1.5 seconds. When Tamper is pressed specific message (tSignal2)
   is sent and the period of Timer is set to 0.375 seconds.

For each event (message received, message transmitted, error occur ...) a 
relative information is displayed on the LCD screen. When the same event is 
repeated, the line color is switched to highlight the event occurrence.

the Mode of Board (transmitter or receiver) is monitored by LEDs:
      - LED2 is toggling when transmitter mode is activated.
      - LED3 is toggling when receiver mode is activated. 

LED1 and LED4 are toggling by an interrupt generated by TIM6 each 50ms.

The programming model of I2C communication can be selected (DMA or Interrupt) in 
stm32f0xx_i2c_cpal_conf.h file by commenting or uncommenting these defines in
Section 2 (Transfer Options Configuration):
              #define CPAL_I2C_DMA_PROGMODEL
              #define CPAL_I2C_IT_PROGMODEL
Note : Only one define must selected. If these two defines are uncommented DMA Programming 
model is selected and the code size of this example will increase.

 
** UserCallbacks :

   - CPAL_TIMEOUT_UserCallback : This Callback is called to manage timeout error.
      In this Callback I2C device is reinitialized.
      
   - CPAL_I2C_ERR_UserCallback : This Callback is called to manage Device error .  
      In this Callback I2C device is reinitialized.
      Note: 
      If you want to generate an I2C error, you can disconnect I2C_SCL/I2C_SDA connector.
      In this case the I2C communication will be corrupted and the CPAL I2C error callbacks
      will be entered. If you fit back the jumper or connector, the communication should be 
      recovered immediately thanks to CPAL error management. 
      
   - CPAL_I2C_TXTC_UserCallback : This Callback is called when Write operation 
      is completed. In this Callback only information relative to communication 
      are displayed on LCD screen.
      
   - CPAL_I2C_RXTC_UserCallback : This Callback is called when Read operation 
      is completed. In this Callback received data are compared and transfer 
      status is displayed on LCD screen.
 

@par Directory contents 

  - I2C/I2C_TwoBoards/stm32f0xx_conf.h                   Library Configuration file
  - I2C/I2C_TwoBoards/stm32f0xx_it.c                     Interrupt handlers
  - I2C/I2C_TwoBoards/stm32f0xx_it.h                     Interrupt handlers header file
  - I2C/I2C_TwoBoards/main.c                             Main program
  - I2C/I2C_TwoBoards/main.h                             Main program header file   
  - I2C/I2C_TwoBoards/system_stm32f0xx.c                 STM32F0xx system source file
  - I2C/I2C_TwoBoards/stm32f0xx_i2c_cpal_conf.h          CPAL Library Configuration file
  - I2C/I2C_TwoBoards/stm32f0xx_i2c_cpal_usercallback.c  CPAL Usercallbacks definition
  
  
@note The "system_stm32f0xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to meet user application requirements. 
      To select different clock setup, use the "STM32F0xx_Clock_Configuration_VX.Y.Z.xls" 
      provided with the AN4055 package available on <a href="http://www.st.com/internet/mcu/class/1734.jsp">  ST Microcontrollers </a>

         
@par Hardware and Software environment

  - This example runs on STM32F0xx Devices.
  
  - This example has been tested with STMicroelectronics STM320518-EVAL (STM32F0xx)
    evaluation board and can be easily tailored to any other supported device 
    and development board. 

 - The same example should be loaded in two evaluation boards.
    
 - STM320518-EVAL Set-up
    - Use two boards should be connected as follows:
       - Connect I2C1 SCL pin (PB6) to I2C1 SCL pin (PB6)
       - Connect I2C1 SDA pin (PB7) to I2C SDA pin (PB7)
       - Connect Gnd pins of two boards.

    
@par How to use it ? 

In order to make the program work, you must do the following :
 - Copy all source files from this example folder to the template folder under
   Project\STM32F0xx_StdPeriph_Templates
 - Open your preferred toolchain
 - Add the following files the project source list
     - Libraries/STM32F0xx_CPAL_Driver/stm32f0xx_i2c_cpal.c
     - Libraries/STM32F0xx_CPAL_Driver/stm32f0xx_i2c_cpal_hal.c
     - stm32f0xx_i2c_cpal_usercallback.c
 - Rebuild all files and load your image into target memory
 - Run the example

 * <h3><center>&copy; COPYRIGHT STMicroelectronics</center></h3>
 */
