以下代码是使用GPIO模拟IIC通讯的代码,时序由MCU产生,在CC2541上运行通过。
-
/*
-
* file iic.h
-
*
-
*/
-
#include "hal_types.h"
-
-
#ifndef __IIC_H__
-
#define __IIC_H__
-
-
-
#if 1 /* exchange SDA SCL */
-
-
#define SCL_SET() (I2CIO |= (1<<1))
-
#define SDA_SET() (I2CIO |= (1<<0))
-
#define SCL_CLR() (I2CIO &= ~(1<<1))
-
#define SDA_CLR() (I2CIO &= ~(1<<0))
-
-
#define SET_SDA_IN() (I2CWC &= ~(1<<0))
-
#define SET_SDA_OUT() (I2CWC |= 1)
-
#define GET_SDA() (I2CIO & 0x1)
-
-
#else
-
-
#define SCL_SET() (I2CIO |= (1<<0))
-
#define SDA_SET() (I2CIO |= (1<<1))
-
#define SCL_CLR() (I2CIO &= ~(1<<0))
-
#define SDA_CLR() (I2CIO &= ~(1<<1))
-
-
#define SET_SDA_IN() (I2CWC &= ~(1<<1))
-
#define SET_SDA_OUT() (I2CWC |= 1<<1)
-
#define GET_SDA() ((I2CIO>>1) & 0x1)
-
-
#endif
-
-
-
#define DEEP_OPTIMIZATION (0)
-
-
extern void iic_init(void);
-
extern void iic_release(void);
-
extern void iic_start(void);
-
extern void iic_stop(void);
-
extern uint8 iic_send_byte(uint8 data);
-
extern uint8 iic_recv_byte_with_ack(void);
-
extern uint8 iic_recv_byte_with_nak(void);
-
-
#endif
阅读(1763) | 评论(0) | 转发(0) |