Problem with I2C eeprom memory PIC32MX460

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
joseiut
Posts: 13
Joined: 20 Feb 2014 16:59

Problem with I2C eeprom memory PIC32MX460

#1 Post by joseiut » 15 Mar 2020 00:08

Greetings to all the members of the forum, I bring you a concern, and whoever can help me would appreciate it.
I am working with a pic32mx460, a TFT 7in 800x480 and an eeprom memory 24C01 or 24C02 ...
The problem is that I am using the I2C Advanced example with the library EEPROM_24C02.c and it does not work for me, if you write the eeprom but it does not read it, sometimes if we read say 1 time out of every 20 attempts ...
I have tried 2 new memories 24C02 I even made a program with the PIC16F877 to verify ...
Thanks

#include "EEPROM_24C02.h"
#include "resources.h"

char someData[14] = "I2C mikroE";
char writeData[14];
char i, tmpdata;

void Init() {
AD1PCFG = 0xFFFF; // Configure AN pins as digital I/O
JTAGEN_bit = 0; // Disable JTAG
TFT_BLED_Direction = 0; // Set TFT backlight pin as output
TFT_Init(320, 240); // Initialize TFT display
TFT_BLED = 1; // Turn on TFT backlight
}

void DrawFrame(){
TFT_Init(320,240);
TFT_Fill_Screen(CL_WHITE);
TFT_Set_Pen(CL_BLACK, 1);
TFT_Line(20, 220, 300, 220);
TFT_LIne(20, 46, 300, 46);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("I2C Advanced Example", 50, 14);
TFT_Set_Font(&Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL);
TFT_Write_Text("EasyPIC Fusion v7", 19, 223);
TFT_Set_Font(&Verdana12x13_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("www.mikroe.com", 200, 223);
TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
}

// Main
void main() {
Init(); // Initialize MCU
DrawFrame(); // Draw graphical frame
EEPROM_24C02_Init(); // performs I2C initialization


// Example for single-byte write
i = 0;
tmpdata = 1;
TFT_Write_Text("Writing Single Byte :", 50, 80);
Delay_ms(500);
while ((tmpdata = someData) != 0) {
i++;
EEPROM_24C02_WrSingle(i, tmpdata); // writes data, char by char, in the EEPROM
Delay_ms(20);
}
TFT_Write_Text(someData, 190, 80); // Display string on TFT

EEPROM_24C02_WrSingle(i+1, 0); // writes string termination
Delay_ms(20);

// Example for single-byte read
Delay_ms(1000);
i = 1;
tmpdata = 1;
TFT_Write_Text("Reading Single Byte :", 50, 100);
Delay_ms(500);
while ((tmpdata = EEPROM_24C02_RdSingle(i)) != 0) { // reads data, char by char, from the EEPROM
writeData[i-1] = tmpdata;
Delay_ms(20);
i++;
}
writeData[i-1] = tmpdata;
TFT_Write_Text(writeData, 190, 100); // Display string on TFT

// Example for sequential data read
Delay_ms(1000);
EEPROM_24C02_RdSeq(1, &someData, 13);
TFT_Write_Text("Sequential Reading :", 50, 120);
Delay_ms(1000);
TFT_Write_Text(someData, 190, 120);

Delay_ms(1000);
TFT_Write_Text("EEPROM Test Successful!", 80, 150);
}

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Problem with I2C eeprom memory PIC32MX460

#2 Post by jovana.medakovic » 16 Mar 2020 14:10

Hello,

Can you tell me which development board you are using?
24C02 EEPROM chip uses I2C communication, so can you tell me how you connect the chip with MCU?

Kind regards,
Jovana

Post Reply

Return to “mikroC PRO for PIC32 General”