⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc_i2c.h

📁 给大家提供一个在inram/exram中调试的示例,在周公的lpc2200上调试过.
💻 H
字号:
#ifndef __LPC_I2C_H
#define __LPC_I2C_H

/***********************************************************************
 *         BU MMS China, Philips Semiconductor Software Support
 *         Embest info&Tech Co. Software Support
 *---------------------------------------------------------------------------
 * The software is delivered "AS IS" without warranty or condition of any
 * kind, either express, implied or statutory.  Everybody can use it as 
 * it is opened and without copyright. We will not take any law responsibility
 * for any problem produced by using this software.
 *---------------------------------------------------------------------------
 *    File name: 	LPC_I2C.h                                                          
 *    Description: 	Define I2C structure and relative micro
 *
 *    History:
 *    1. Date: 		Nov 20, 2004
 *       Author: 	Shawn Zhang
 *       Description: Create
 *
 *	$Revision: 1.0 $
 **********************************************************************/

#include "LPC_Base.h"
#include "LPC_Type.h"
#include "LPC_Lib.h"

#include "LPC_Syscontrol.h"
#include "LPC_Vic.h"

#define I2C_MAXSPEED        400000		// I2C max speed: 400k/s

/* Status Errors */
#define I2C_OK                      0 // transfer ended No Errors
#define I2C_IDLE                    1 // bus idle
#define I2C_BUSY                    2 // transfer busy
#define I2C_ERROR                   3 // err: general error
#define I2C_NO_DATA                 4 // err: No data in block
#define I2C_NACK_ON_DATA            5 // err: No ack on data
#define I2C_NACK_ON_ADDRESS         6 // err: No ack on address
#define I2C_DEVICE_NOT_PRESENT      7 // err: Device not present
#define I2C_ARBITRATION_LOST        8 // err: Arbitration lost
#define I2C_TIME_OUT                9 // err: Time out occurred
#define I2C_SLAVE_ERROR             10 // err: Slave mode error
#define I2C_INIT_ERROR              11 // err: Initialization (not done)
#define I2C_RETRIES                 12 // err: Initialization (not done)

/* I2C Message Flag Type*/
#define I2C_MSG_AA		0x4
#define I2C_MSG_SI		0x8
#define I2C_MSG_STOP	0x10
#define I2C_MSG_START	0x20

typedef enum {
	I2C_MASTER = 1,
	I2C_SLAVE = 2
} LPC_I2C_Mode_t;

typedef enum {
	WRITE=0,	//transmit
	READ=1, 	//receive
	WRITETHENREAD = 2
} LPC_I2C_TransMode_t;

typedef struct {
	LPC_BYTE address;	// slave address to sent/receive message
	LPC_BYTE nrBytes;	// number of bytes in message buffer
	LPC_BYTE *buf;		// pointer to application message buffer	
	LPC_I2C_TransMode_t transMode;	// write or read flag
	LPC_BYTE nrWriteBytes ;	// write byte number, only used in "WriteThenRead" mode

	int dataCount ;	// count the Tx/Rx number
} LPC_I2C_Msg_t;

// Declare the API functions
int I2C_InitMaster (lpc_uint32 BusSpeed);
int I2C_MasterWrite (lpc_uint8 addr, lpc_uint8 *pMsg , lpc_uint32 numMsg);
int I2C_MasterRead (lpc_uint8 addr, lpc_uint8 *pMsg , lpc_uint32 numMsg);

int I2C_InitSlave (lpc_uint32 BusSpeed, lpc_uint32 SlaveAddr);
int I2C_SlaveWrite (lpc_uint8 *pMsg , lpc_uint32 numMsg);
int I2C_SlaveRead (lpc_uint8 *pMsg , lpc_uint32 numMsg);

int I2C_Transfer (lpc_uint8 addr, lpc_uint8 *pMsg , lpc_uint32 numMsg, 
	LPC_I2C_TransMode_t transMode, lpc_uint32 numWrite);

void I2C_HandleMasterState(void);
void I2C_HandleSlaveState(void);

__irq void I2C_ISR(void);

extern I2C_VectISR (void);

#endif //__LPC_I2C_H

⌨️ 快捷键说明

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