Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2013
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.94 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * @file OptimizedI2Cexamples/src/main.c
  4.   * @author  MCD Application Team
  5.   * @version  V4.0.0
  6.   * @date     06/18/2010
  7.   * @brief  Main program body
  8.   ******************************************************************************
  9.   * @copy
  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 2010 STMicroelectronics</center></h2>
  19.   */
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f10x.h"
  23. #include "I2CRoutines.h"
  24.  
  25.  
  26. /** @addtogroup Optimized I2C examples
  27.   * @{
  28.   */
  29.  
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* Private define ------------------------------------------------------------*/
  32. /* Private macro -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. ErrorStatus HSEStartUpStatus;
  35. /* Buffer of data to be received by I2C1 */
  36. uint8_t Buffer_Rx1[255];
  37. /* Buffer of data to be transmitted by I2C1 */
  38. uint8_t Buffer_Tx1[255] = {0x5, 0x6,0x8,0xA};
  39. /* Buffer of data to be received by I2C2 */
  40. uint8_t Buffer_Rx2[255];
  41. /* Buffer of data to be transmitted by I2C2 */
  42. uint8_t Buffer_Tx2[255] = {0xF, 0xB, 0xC,0xD};
  43. extern __IO uint8_t Tx_Idx1 , Rx_Idx1;
  44. extern __IO uint8_t Tx_Idx2 , Rx_Idx2;
  45.  
  46. /* Private function prototypes -----------------------------------------------*/
  47. void GPIO_Configuration(void);
  48. void NVIC_Configuration(void);
  49. /* Private functions ---------------------------------------------------------*/
  50.  
  51.  
  52. /**
  53.   * @brief  Main program
  54.   * @param  None
  55.   * @retval : None
  56.   */
  57. int main(void)
  58.  
  59. {
  60.    
  61.      
  62.     NVIC_Configuration();
  63.     I2C_LowLevel_Init(I2C2);
  64.     I2C_LowLevel_Init(I2C1);
  65.  
  66. /* Use I2C1 as Master which is communicating with I2C1 of another STM32F10x device */
  67. while(1)
  68.  {
  69.      I2C_Master_BufferWrite(I2C1, Buffer_Tx1,120,Interrupt, 0x28);
  70.      I2C_Master_BufferRead(I2C1,Buffer_Rx1,120,Polling, 0x28);
  71.  }
  72.    
  73. /* Use I2C1 as Slave */
  74. /*! When using Slave with DMA, uncomment //#define SLAVE_DMA_USE in the stm32f10x_it.c file.*/
  75.  /*I2C_Slave_BufferReadWrite(I2C1, DMA);
  76.  
  77.  while(1); */
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /**
  87.   * @brief  Configures NVIC and Vector Table base location.
  88.   * @param  None
  89.   * @retval : None
  90.   */
  91. void NVIC_Configuration(void)
  92. {
  93.  
  94.     /* 1 bit for pre-emption priority, 3 bits for subpriority */
  95.     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
  96.  
  97.     NVIC_SetPriority(I2C1_EV_IRQn, 0x00);
  98.     NVIC_EnableIRQ(I2C1_EV_IRQn);
  99.  
  100.     NVIC_SetPriority(I2C1_ER_IRQn, 0x01);
  101.     NVIC_EnableIRQ(I2C1_ER_IRQn);
  102.    
  103.    
  104.     NVIC_SetPriority(I2C2_EV_IRQn, 0x00);
  105.     NVIC_EnableIRQ(I2C2_EV_IRQn);
  106.  
  107.     NVIC_SetPriority(I2C2_ER_IRQn, 0x01);
  108.     NVIC_EnableIRQ(I2C2_ER_IRQn);
  109.  
  110. }
  111.  
  112. #ifdef  USE_FULL_ASSERT
  113.  
  114.  
  115. /**
  116.   * @brief  Reports the name of the source file and the source line number
  117.   *   where the assert_param error has occurred.
  118.   * @param file: pointer to the source file name
  119.   * @param line: assert_param error line source number
  120.   * @retval : None
  121.   */
  122. void assert_failed(uint8_t* file, uint32_t line)
  123. {
  124.     /* User can add his own implementation to report the file name and line number,
  125.        ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  126.  
  127.     /* Infinite loop */
  128.     while (1)
  129.     {
  130.     }
  131. }
  132. #endif
  133. /**
  134.   * @}
  135.   */
  136.  
  137.  
  138. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement