main.c

来自「st7单片机关于I2C总线设计的源程序,使用ST7单片机的很有用」· C语言 代码 · 共 45 行

C
45
字号
/******************************************************************************
COPYRIGHT 2002 STMicroelectronics
Source File Name :  main.c  
Group            :  IPSW,CMG-IPDF
Author           : MCD Application Team
Date First Issued:  04/03/2002
********************************Documentation**********************************
General Purpose - It is application file which calls the functions in i2c.c. 
This example carries out the single byte transmission and continuous 
transmission in pollling mode or in interrupt driven without buffer mode as per 
the selection made in the ST7lib_Config.h. Also it carries out the reception of
a single byte and a buffer of data in polling mode or in interrupt driven 
without buffer mode.The transmission and reception are carried out at a speed
of 200 KHz.
 
Also for transmission and reception in interrupt driven case, interrupt is 
enabled for generating the interrupt.  	
********************************Revision History*******************************
_______________________________________________________________________________
Date :04/03/2002                  Release:1.0
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/

#include "ST7lib_config.h" /* List of all ST7 devices and communication mode */
#include "main.h"        
       /* Declaration of prototypes of user defined functions used in main.c */ 
       
void main(void)              
{ 		
     unsigned char Rx_Data;
     unsigned char Buff_Test[size_buff];
     unsigned char Buff[size_buff] = {0, 1, 2, 5, 50, 10, 100, 200, 225, 255};      
     I2C_TxErrCode_t Temp1 ;
     I2C_RxErrCode_t Temp2 ;
     Temp1 = Temp2 = 0x00 ;
     I2C_Init ((unsigned char)I2C_ENABLE_ACK | (unsigned char)I2C_IT_ENABLE); 
                                        /* Enable acknowledge and interrupts */

     EnableInterrupts;     /* Interrupt mask is reset for enabling interrupt */
     I2C_MultiMaster_Config ();   /* Configure I2C as multimaster I2C device */ 
     I2C_Select_Speed (I2C_FASTSPEED, (unsigned int)200);
                                 /* Selects fast speed mode, Speed is 200KHz */
     I2C_Generate_Start ();
     while(!(I2C_IsTransmitCompleted()== I2C_START_OK));     
               /*================================================
                        Transmission through 慞olling

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?