Reputation: 155
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
Upvotes: 0
Views: 2416
Reputation: 2434
It doesnt look like you have set up the port pins for digital input and output. Check the datasheet for which pins are used for I2C and set the appropriate TRIS bits. You should also check that the analogue functions for the same pins is disabled (ANSEL register). Enabling the I2C module is not enough on its own.
Upvotes: 2