I am trying to read and write data to an 28256 EEPROM by using the Direct Port Manipulation in PORTA, PORTC and PORTL. I have an Arduino MEGA 2560 board
After writing some data, I checked the content by measuring the logic levels at data bus of the EEPROM and PORTL pin in Arduíno and they're both correct.
However, the data read from Arduino is not. The data read with PINL is not the same as read with digitalRead() and both are wrong.
This is the function for reading data:
byte ReadData (int iAddr)
{
int iMSB, iLSB;
byte cData = 0;
int x;
DDRA = B11111111; //ADDR
DDRC = B11111111; //ADDR
for (x = 42; x < 50; x++)
pinMode (x, INPUT); //I've tried with DDRL = B000000000 but nothing changed
pinMode (PIN_OE, OUTPUT);
pinMode (PIN_WE, OUTPUT);
digitalWrite (PIN_OE, LOW); //Output enabled
digitalWrite (PIN_WE, HIGH); //Write disabled
iMSB = iAddr/256;
iLSB = iAddr - iMSB*256;
PORTA = iLSB;
PORTC = iMSB; //Bits already inverted on the board
for (x = 42; x < 50; x++)
System.println (digitalRead (x)); //DBG - It does not matter if the bits are inverted here
return (PINL);
}
I really don't know what is happening here. If you can give some help, I appreciate it.
In the beginning, I put that once in setup() but it did not work. That's a kind of "pinMode forcing".
Not yet but I tested the logical levels at the EEPROM data bus for some values such as 0x00, 0x55, 0xAA and 0xFF (read/write at 0 address) and the write part seems to be ok.
Wouldn't that be a reason to stop and fix it, instead of moving on to port manipulation? You can guess, it should work, no "forcing" should be required, it's a sign that something else is breaking it.
@jairorm this may have been something of a hint that it would be easier on everyone if you posted a complete "it compiles and we could run it ourselves" sketch.
At a glance there isn't anything wrong.
A schematic, just drawn with a pencil, take a celly and post it here would also be good, if only to force you to look carefully at your wiring but certainly so we can take a peek also, instead of reverse engineering your code snippet or drawing our own from you prose dexcription.
For many the schematic is the only effective way to communicate about the actual circuit details.
I did some more tests and discovered that my Write function is not working. When I tested the logical levels at the data bus, actually, I was getting the data from Arduino's port when PORTL is OUTPUT. After setting PORTL as INPUT again (and set OE, WE conveniently), the data written in memory is wrong.
I'm gonna upload the schematic and the sketch in a few hours.