嵌入式技术
/****************************************
* IIC初始值 function
***************************************/
void i2c_init(void)
{
// unsigned char slave_address; //CTP Slave address set
//IICADD
//slave_address=0x38; //Device slave address
//GPE set 55555515
*(volatile unsigned int *)GPECON=0xF5555515;//set GPE15->IICSDA GPE14->IICSCL
*(volatile unsigned int *)GPECON=0xA5555515;//set GPE15->IICSDA GPE14->IICSCL
*(volatile unsigned int *)GPEUP=0xC00f ; //GPE3=CTP Interrupt
//IIC Initial
*(volatile unsigned int *)0x54000008 = 0x38; // S3C2410A to IIC Save address
*(volatile unsigned int *)0x54000000 = 0xAF; // ACK &IIC中斷,IICCLK=MCLK/16 ,ACK=fPCLK/16//(15+1)
*(volatile unsigned int *)0x54000004 = 0x10; // Enable Tx/i2c_master_RX
}
/*************************************************
* I2C Master TX function
************************************************/
void i2c_master_TX(unsigned char slave_add,unsigned char add1)
{
unsigned char i=0;
*(volatile unsigned int *)0x54000004 = 0xD0; // Master Tx mode
*(volatile unsigned int *)0x5400000C = slave_add; // Master to Slave address
*(volatile unsigned int *)0x54000004= 0xF0;//IICSTAT (M/R START) bit5 IIC Start single產生
while((*(volatile unsigned char *)(0x54000000)&0x10 )!=0x10){;;} //Tx/i2c_master_RX Interrupt Enable
*(volatile unsigned char *) 0x5400000C=add1 ;//Writer A DATA
*(volatile unsigned int *)0x54000000=0xAF; //Interrupt pending =0
while((*(volatile unsigned char *)(0x54000000)&0x10 )!=0x10){;;} //Tx/i2c_master_RX Interrupt Enable
*(volatile unsigned int *)0x54000004=0xD0;//STOP
*(volatile unsigned int *)0x54000000=0xAF;//ACK
Delay1us(10);
}
/*************************************************
* I2C Master Receiver function read 26 byte
************************************************/
void i2c_master_RX(unsigned char slave_add) //
{
unsigned int i=0;
unsigned int temp1;
unsigned char check_sum;
*(volatile unsigned int *)0x54000004 = 0x90; // Master i2c_master_RX mode
*(volatile unsigned int *)0x5400000C = slave_add; // Master to Slave address
*(volatile unsigned int *)0x54000004=0xB0;//IICSTAT (M/R START)bit5 IIC Start single產生
while((*(volatile unsigned char *)(0x54000000) &0x10 )!=0x10){;;} //Tx/i2c_master_RX Interrupt Enable
*(volatile unsigned int *)0x54000000=0xAF; //Interrupt pending =0
for(i=0;i<25;i++)
{
while((*(volatile unsigned char *)(0x54000000) &0x10 )!=0x10){;;} //Tx/i2c_master_RX Interrupt Enable
data1[i]=*(volatile unsigned char *) 0x5400000C ;//READ A DATA
*(volatile unsigned int *)0x54000000=0xAF; //Interrupt pending =0 }
while((*(volatile unsigned char *)(0x54000000) &0x10 )!=0x10){;;} //Tx/i2c_master_RX Interrupt Enable
data1[25]=*(volatile unsigned char *)0x5400000C ;//READ 最後一筆資料 DATA
*(volatile unsigned int *)0x54000004=0x90;//STOP
*(volatile unsigned int *)0x54000000=0x2F;//NACK
Delay1us(10);
}
全部0条评论
快来发表一下你的评论吧 !