0

I am working on a university project in which i need to interface pic18f4550 with i2c EEPROM.

I read many codes and saw many projects on this topic. and I wrote a sample code from MPLAB C18 ( and i tried many codes also) but no one worked with me.

I dont where is the problem. Every thing is ok with my code and with my circuit, but the sck did not genrate clk for writing and nothing has been wriiten to eeprom. so if any one can help me plz.

NOTE: I can't post an image of my circuit, since I'm new user ! Here is the code:

    #include "p18f4550.h"
    #include "i2c.h"
    #pragma config FOSC = HS
    #pragma config PWRT = OFF
    #pragma config BOR = OFF
    #pragma config MCLRE = ON
    #pragma config PBADEN = OFF
    #pragma config ICPRT = OFF
    #pragma config LVP = OFF
    #pragma config WDT = OFF,DEBUG=OFF

    unsigned char arraywr[] = {1,2,3,4,5,6,7,8,0};
    unsigned char arrayrd[20];
    //***************************************************
    void main(void)
    {
    OpenI2C(MASTER, SLEW_ON);// Initialize I2C module
    SSPADD = 10; //400kHz Baud clock(10) @20MHz
    while(1)
    {
     EEByteWrite(0xA0, 0x30, 0xA5);
     EEAckPolling(0xA0);
     EECurrentAddRead(0xA0);
     EEPageWrite(0xA0, 0x70, arraywr);
     EEAckPolling(0xA0);
     EESequentialRead(0xA0, 0x70, arrayrd, 20);
     EERandomRead(0xA0,0x30);
   }
  }

Thanks in advance

4

1 に答える 1

2

デジタル入出力用のポートピンを設定していないようです。I2C に使用されるピンのデータシートを確認し、適切な TRIS ビットを設定します。また、同じピンのアナログ機能が無効になっていることも確認する必要があります (ANSEL レジスタ)。I2C モジュールを有効にするだけでは十分ではありません。

于 2011-12-22T14:39:38.783 に答える