Browsing this Thread:
2 Anonymous Users
|
Re: ReadI2C
|
|
高級會員
Joined
: 2005/5/7 14:39 最後登入時間
: 2023/5/18 19:44
Group:
註冊會員
Level : 7 HP : 0 / 160 MP : 24 / 9089 EXP : 40
|
將那一行程式改成 while(SSPcon2bits.RCEN) 試試看
發表於: 2007/10/4 16:53
|
|
|
ReadI2C
|
|
中級會員
Joined
: 2007/9/20 13:35 最後登入時間
: 2008/6/27 9:38
From Taipei
Group:
註冊會員
Level : 5 HP : 0 / 114 MP : 15 / 5725 EXP : 59
|
Dear all,
小弟現在正在APP013上使用P18F4550嘗試透過I2C去讀取LM73(Sensor)的Produce ID. 程式內容如下:
#include "P18F_LCD.h" #include "i2c.h" #include "delays.h"
void OpenLCD(void); void Initialize_I2C_Master(void); void I2C_Done(void);
void main(void) { union { char b[2]; int data; } temp_data;
OpenI2C(MASTER,SLEW_OFF); //Fosc=24MHz; Fre=100KHz SSPADD=59;
IdleI2C(); StartI2C();
WriteI2C(0x90); //value = WriteI2C((int)write_addr); // Addr: R/W: 0 -> Write AckI2C();
WriteI2C(0x7); //Read Produce Id
RestartI2C();
WriteI2C(0x91); // Addr: R/W: 1 -> Read
temp_data.b[0] = ReadI2C(); //High_Value
temp_data.b[1]= ReadI2C(); //Low_Value NotAckI2C(); StopI2C(); CloseI2C(); }
在執行以上程式後, 程序總是會停在i2c_read.c裡面的(紅色字體):
unsigned char ReadI2C( void ) { SSPCON2bits.RCEN = 1; // enable master for 1 byte reception while ( !SSPSTATbits.BF ); // wait until byte received return ( SSPBUF ); // return with read byte }
請問這是卡在哪?
P.S 我有檢查過線路, 並沒有短路或是斷路發生
發表於: 2007/10/4 15:54
|
|
You can view topic.
你 不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.