新聞中心

S3C2440-IIC

作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
void __irq IIC_ISR(void){
rSRCPND |= 0x1<<27;
rINTPND |= 0x1<<27;
flag = 0;
}
void wrat24c02(unsigned char add,unsigned char word, U32 length){
int i;
flag = 1;
rIICDS = 0xa0; //dev add
rIICCON &= "(0x1<<4); //清中斷
rIICSTAT = 0xf0; //主發(fā)送模式,寫開(kāi)始信號(hào)輸出,IIC Rx/Tx使能
//等待ACK,接收器在接受到8位數(shù)據(jù)后,在第9個(gè)時(shí)鐘周期,拉低SDA電平,然后會(huì)產(chǎn)生中斷
while(flag == 1)
delay(100);
flag = 1;
rIICDS = word; //word add 發(fā)送要寫入的數(shù)據(jù)的內(nèi)存其實(shí)地址
rIICCON &= "(0x1<<4);
while(flag)
delay(100); //注意要有delay
for(i = 0; i < length; i++){
flag = 1;
rIICDS = iic_buffer[ i];
rIICCON &= "(0x1<<4);
while(flag)
delay(100);
}
rIICCON = 0xe0; //IIC應(yīng)答有效,IICCLK=fpclk/512,IIC接受發(fā)送中斷使能位
rIICSTAT = 0xd0; //主發(fā)送模式,rIICCON和rIICSTAT配置好,方便下次使用
}
void rdat24c02(unsigned char add, unsigned char word, U32 length){
int i;
char temp;
flag = 1;
rIICDS = add; //dev add
rIICCON &= "(0x1<<4);
rIICSTAT = 0xf0;
while(flag)
delay(100);
flag = 1;
rIICDS = word; //word add
rIICCON &= "(0x1<<4);
while(flag)
delay(100);
flag = 1;
//這里的IIC的隨機(jī)讀操作,根據(jù)IIC的隨機(jī)讀時(shí)序,先發(fā)啟動(dòng),要讀取的設(shè)備地址和寫的內(nèi)存地址,方向是寫,即0,重啟IIC,
//發(fā)要讀取的設(shè)備地址,這次方向是讀,然后接到ACK,從機(jī)向主機(jī)發(fā)data,主機(jī)相應(yīng)ACK,直到最后一個(gè)data,主機(jī)不相應(yīng)ACK,
//發(fā)送停止信號(hào)
rIICDS = add; //dev add
rIICSTAT = 0xb0; //改變方向?yàn)橹鹘邮?div> rIICCON &= "(0x1<<4);
while(flag)
delay(100);
flag = 1;
temp = rIICDS;
rIICCON &= "(0x1<<4);
while(flag)
delay(100);
for(i = 0; i < length; i++){
flag = 1;
if(i == (length - 1)){
rIICCON &= "(0x1<<7);
}
iic_buffer[ i] = rIICDS;
rIICCON &= "(0x1<<4);
while(flag)
delay(100);
}
rIICCON = 0xd0;
rIICSTAT = 0x90;
delay(200);
}
int Main(){
int i;
count= 0;
length = 0;
cmd = 0;
command = 0;
rGPECON = 0xa0000000; //GPE15~14 IICSDA,IICSCL
rGPEUP = 0xc000;
rIICCON = 0xe0; //IIC應(yīng)答有效,IICCLK=fpclk/512,IIC接受發(fā)送中斷使能位
rIICSTAT = 0x10; //IIC總線有效Rx/Tx
rULCON0 = 0x3;
rUCON0 = (1<<11)|(1<<2)|(1<<0);
rUBRDIV0 = 26;
rSRCPND = (0x1<<28)|(0x1<<27);
rINTPND = (0x1<<28)|(0x1<<27);
rSUBSRCPND = 0x1<<0;
rINTMSK &= "((0x1<<28)|(0x1<<27));
rINTSUBMSK &= "(0x1<<0);
pISR_UART0 = (U32)UART0_ISR;
pISR_IIC = (U32)IIC_ISR;
for(i = 0; i < 8; i++){
iic_buffer[ i] = 0xee;
}
while(1){
switch(cmd){
case 0x01:
cmd = 0;
wrat24c02(add, word, length);
break;
case 0x02:
cmd = 0;
rdat24c02(add, word, length);
for(i = 0; i < 8; i++){
while(!(rUTRSTAT0&0x4));
rUTXH0 = iic_buffer[ i];
}
break;
}
}
return 0;
}
上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: S3C2440IIC串行總

評(píng)論


技術(shù)專區(qū)

關(guān)閉