资源描述:
《stm32iic硬件中断方式通用子函数》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//h文件#ifndef__iic_h__#define__iic_h__/*Includes------------------------------------------------------------------*/#include"stm32f10x.h"/*Exportedtypes------------------------------------------------------------*/typedefenumi2c_result{NO_ERR=0,TIMEOUT=1,BUS_BUSY=2,SEND_START_ERR=3,ADDR_MATCH_E
2、RR=4,ADDR_HEADER_MATCH_ERR=5,DATA_TIMEOUT=6,WAIT_COMM=7,STOP_TIMEOUT=8}I2C_Result;typedefenumi2c_state{COMM_DONE=0,//donesuccessfullyCOMM_PRE=1,COMM_IN_PROCESS=2,CHECK_IN_PROCESS=3,COMM_EXIT=4//exitsincefailure}I2C_STATE;externI2C_STATEi2c_comm_state;externvu8MasterReceptionComplete;externvu8M
3、asterTransitionComplete;externvu8WriteComplete;externvu8SlaveReceptionComplete;externvu8SlaveTransitionComplete;voidI2C_Comm_Init(I2C_TypeDef*I2Cx,u32I2C_Speed,u16I2C_Addr);voidI2C_Comm_MasterWrite(I2C_TypeDef*I2Cx,u16slave_addr,u32offset,u8*pBuffer,u32length);voidI2C_Comm_SlaveRead(I2C_TypeDe
4、f*I2Cx,u8*pBuffer,u32length);voidI2C_Comm_MasterRead(I2C_TypeDef*I2Cx,u16slave_addr,u32offset,u8*pBuffer,u32length);voidI2C_Comm_SlaveWrite(I2C_TypeDef*I2Cx,u8*pBuffer,u32length);voidi2c1_evt_isr(void);voidi2c1_err_isr(void);voidi2c2_evt_isr(void);voidi2c2_err_isr(void);//c文件#endif//__iic_h__#
5、include"iic.h"/*******specifiedbyuser************///#defineI2C_REMAP//#defineSLAVE_10BIT_ADDRESS/*******specifybyuser************/#defineTransmitter0x00#defineReceiver0x01#defineFALSE0#defineTRUE1staticvu8Direction=Transmitter;staticu16SlaveADDR;staticu32TxLength,RxLength;staticu32DeviceOffset
6、=0xffffffff;staticu8*pTxBuffer1;staticu8*pTxBuffer2;staticu8*pRxBuffer1;staticu8*pRxBuffer2;staticu8check_begin=FALSE;vu8MasterReceptionComplete=0;vu8MasterTransitionComplete=0;//toindicatmaster'ssendprocessvu8SlaveReceptionComplete=0;vu8SlaveTransitionComplete=0;vu8WriteComplete=0;//toindicat
7、target'sinternalwriteprocess/*P-VoperationonI2C1orI2C2*/staticvu8PV_flag_1;staticvu8PV_flag_2;I2C_STATEi2c_comm_state;voidI2C_Comm_Init(I2C_TypeDef*I2Cx,u32I2C_Speed,u16I2C_Addr){/*******GPIOconfigurationandclockenable*********/GPIO_Ini