請益2440 IIC

我們生活周遭存在太多太多的 embedded system ,過去 embedded system 有專屬的 OS,現在 linux 也可以應用在嵌入式環境,不過本版將廣泛討論所有嵌入式系統不只 linux 喔,歡迎有這方面經驗或有興趣的朋友一同進來討論。

版主: chester

請益2440 IIC

文章13F » 週二 7月 14, 2009 9:42 pm

各位前輩好
弟用S3C2440,在寫I2C要讀取外部IC(slave addr=0x30)的4筆
資料.
start,slave addr + read ,ack,data1,ack,data2,ack,data3,
ack,data4,nack,stop. repeat.

參考網路上的2440 iic test程式(Polling方式)
目前slave addr 寫入與讀值出來都對.但是用邏輯分析儀自動比對
iic
start ok
slave addr值是錯的....
read ok
後面得到nack. 沒辦法進行讀取資料的動作..
之前是採用i/o模擬iic沒問題.但是有時IC改變.常要改delay time,
且不穩.

1.請問不用中斷方式,是否還需要注意INTMSK? (iic_bit )
或其他得設定? 目前SCL=8KHz.






參考網路上2440 iic範例
//************************[ _Rd24C080 ]********************************
void _Rd24C080(U32 slvAddr,U32 addr,U8 *data)
{
_iicMode = SETRDADDR;
_iicPt = 0;
_iicData[0] = 0;
_iicData[1] = (U8)addr;
_iicDataCount = 2;
rIICDS = slvAddr;
rIICSTAT = 0xf0; //MasTx,Start
//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(_iicDataCount!=-1)
Run_IicPoll();



_iicMode = RDDATA;
_iicPt = 0;
_iicDataCount = 1;
rIICDS = slvAddr;
rIICSTAT = 0xb0; //Master Rx,Start
rIICCON = 0xaf; //Resumes IIC operation.
while(_iicDataCount!=-1)
Run_IicPoll();

*data = _iicData[1];
}

//**********************[ Run_IicPoll ]*********************************
void Run_IicPoll(void)
{
if(rIICCON & 0x10) //Tx/Rx Interrupt Enable
IicPoll();
}

//**********************[IicPoll ]**************************************
void IicPoll(void)
{
U32 iicSt,i;

iicSt = rIICSTAT;
if(iicSt & 0x8){} //When bus arbitration is failed.
if(iicSt & 0x4){} //When a slave address is matched with IICADD
if(iicSt & 0x2){} //When a slave address is 0000000b
if(iicSt & 0x1){} //When ACK isn't received

switch(_iicMode)
{
case POLLACK:
_iicStatus = iicSt;
break;

case RDDATA:
if((_iicDataCount--)==0)
{
_iicData[_iicPt++] = rIICDS;

rIICSTAT = 0x90; //Stop MasRx condition
rIICCON = 0xaf; //Resumes IIC operation.
Delay(2); //Wait until stop condtion is in effect.
//Too long time...
//The pending bit will not be set after issuing stop condition.
break;
}
_iicData[_iicPt++] = rIICDS;
//The last data has to be read with no ack.
if((_iicDataCount)==0)
rIICCON = 0x2f; //Resumes IIC operation with NOACK.
else
rIICCON = 0xaf; //Resumes IIC operation with ACK
break;
13F
可愛的小學生
可愛的小學生
 
文章: 3
註冊時間: 週日 10月 28, 2007 3:42 pm

回到 embedded system

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客