• slider image 71
  • slider image 72
  • slider image 73
:::


Browsing this Thread:   1 Anonymous Users






PIC24FJ1024GB610 SMbus/I2C 問題
#1
新會員
新會員


查看用戶資訊
[size=x-small]各位先進好
我使用MCC的I2C 去寫
程式碼如下 LA看到想寫的data 並沒有輸出 我有遺漏的部分嗎?

uint16_t Start_Address = 0x0B;
uint8_t MNFnameCom[5] = { 0xFF ,0x03 ,0xA9 , 0x00 , 0x10 };
uint8_t MNFname[16] = { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00};


int main(void){
// initialize the device
SYSTEM_Initialize();
while (1)
{
// SMBus Write
#define SLAVE_I2C_GENERIC_RETRY_MAX 100
#define SLAVE_I2C_GENERIC_DEVICE_TIMEOUT 50
// initialize the module
I2C1_Initialize();
uint16_t timeOut;

timeOut = 0;

//I2C1_MasterWrite(MNFnameCom, sizeof(MNFnameCom) ,
Start_Address , &status);
while(status != I2C1_MESSAGE_FAIL)
{
I2C1_MasterWrite(MNFnameCom, 5 , Start_Address , &status);

while(status == I2C1_MESSAGE_PENDING);
if (status == I2C1_MESSAGE_COMPLETE) break;
if (timeOut == SLAVE_I2C_GENERIC_RETRY_MAX)
break;
else
timeOut++;
}
// SMBus Read
I2C1_MasterRead(MNFname ,sizeof(MNFname) ,Start_Address , &status);

}
}
LA訊號如附檔 address 有輸出但想寫的data都沒輸出

Attach file:



jpg  (0.00 KB)


jpg  (0.00 KB)


發表於: 6/1 18:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC24FJ1024GB610 SMbus/I2C 問題
#2
初級會員
初級會員


查看用戶資訊
mcc gen出來的code是用中斷進行的,也就是讀取i2c mif或是sspif
又由於這兩旗標是在9th clock後舉起來的。
它進中斷會判斷是否ack或是nack。
要是ack它會判斷是要接續送10bit address/data/stop等i2c斜協議;
要是nack就會停下等你重發(自行撰寫機制)。
換句話說你要用mcc gen出來的練習,你需要有該會回應address的device

發表於: 6/5 8:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







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.

[進階搜尋]