|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我的I2C驱动程序,很简单的一个字符设备驱动,但是不知道为什么SCL和SDA老师保持为高电平,请大虾们帮我看一下我的写函数有什么问题啊?
#define IICCON __REG2(0x54000000,4)
#define IICSTAT __REG2(0x54000004,4)
#define IICADD __REG2(0x54000008,4)
#define IICDS __REG2(0x5400000c,4)
static char iic_Data[IICBUFSIZE];
static volatile int iic_DataCount;
static unsigned int old_gpecon,old_gpeup; //use to save GPECON GPEUP
//端口初始化
static void s3c2410_io_port_init(void)
{
old_gpecon = GPECON;
old_gpeup = GPEUP;
GPEUP |= 0xc000; //Pull-up disable
GPECON |= 0xa00000; //GPE15:IICSDA , GPE14:IICSCL
INTMSK &= ~(BIT_IIC);
//Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx clock=IICCLK/16
// If PCLK 50.7MHz, IICCLK = 3.17MHz, Tx Clock = 0.198MHz
IICCON = (1<<7) | (0<<6) | (1<<5) | (0xf);
IICADD = 0x10; //2410 slave address = [7:1]
IICSTAT = 0x10; //IIC bus data output enable(Rx/Tx)
}
static int s3c2410_write(struct file * file,const char * buffer, size_t count, loff_t *ppos)
{
int i;
iic_DataCount=count;
printk("WRITE\n");
copy_from_user(iic_Data,buffer,count);
IICDS = slave_addr; //0xa0
IICSTAT = 0xf0; //MasTx,Start
if(IICSTAT&0x1) {};
for(i=0;i<iic_DataCount;i++)
{
IICDS = iic_Data;
IICSTAT = 0xf0; //MasTx,Start
IICCON = 0xaf; //Resumes II operation.
if(IICSTAT&0x1) {};
}
IICSTAT = 0xd0; //Stop MasTx condition
IICCON = 0xaf; //Resumes IIC operation.
udelay(1); //Wait until stop condtion is in effect.
return 0;
}
|
|