"readFlash" function, and "Table Read" command
Hello,
I am planning to use your program and have encountered a question regarding functionality. In my Arduino project, I am currently using the "readFlash" function, which utilizes the "Table Read" command. However, I would like to switch to using the "Table Read with Post-Increment (1001)" command.
When I apply this command, the first byte is read correctly, but the second byte outputs a completely different value. Would there be any issues or limitations if I were to use "Table Read with Post-Increment (1001)" for my project?
I would greatly appreciate your guidance on this matter.
Best regards,
Hi,
I haven't tested this myself:
send4bitcommand (B1001); /* Table Read with Post-Increment */
What's the reason you want to switch to this command?
Hello,
This command allows for faster communication since the address needs to be sent only once, followed by the 1001 command. My intention is to simplify the transmission and reception process to improve efficiency.
So, could you please give me some guide or comment?
Best regards,
I don't have a working setup to test this myself, currently, but here's how I'd proceed:
-
Make a variant of the
readFlashfunction (which only reads a single byte now), and add alenandoutparameter, like so:void readFlashBytes(byte usb, byte msb, byte lsb, int len, byte *out) -
Then have it set up the address, like
readFlashis doing, but loop the last 20-bit instructionlentimes, and write the result toout[i].
It could look roughly like this:
void readFlashBytes(byte usb, byte msb, byte lsb, int len, byte *out) {
// [...]
// ADDRESS SETUP AS USUAL
// [...]
for (int i = 0; i < len; i++) {
send4bitcommand (B0010);
for (byte i = 0; i < 8; i++) { //dummy read 1 byte
digitalWrite(PGC, HIGH);
digitalWrite(PGC, LOW);
}
for (byte i = 0; i < 8; i++) { //shift out 1 byte
digitalWrite(PGC, HIGH);
digitalWrite(PGC, LOW);
if (digitalRead(PGD) == HIGH)
value += 1 << i; //sample PGD
}
out[i] = value;
}
}
hello.
thanks for your guide.
Finally, I am using the send4BitCommand(B1001) command and dividing it into the 1st read byte and the 2nd to final read bytes.
`void readFlashBytes(byte usb, byte msb, byte lsb, int len, byte *out) { // [...] // ADDRESS SETUP AS USUAL // [...]
send4bitcommand (B1001);
for (byte i = 0; i < 8; i++) { //dummy read 1 byte
digitalWrite(PGC, HIGH);
digitalWrite(PGC, LOW);
}
for (byte i = 0; i < 8; i++) { //shift out 1 byte
digitalWrite(PGC, HIGH);
digitalWrite(PGC, LOW);
if (digitalRead(PGD) == HIGH)
value += 1 << i; //sample PGD
}
serialPrintHex(value);
}
for (int i = 0; i < len-1; i++) {
send4bitcommand (B1001);
for (byte i = 0; i < 8; i++) { //dummy read 1 byte
digitalWrite(PGC, HIGH);
digitalWrite(PGC, LOW);
}
for (byte i = 0; i < 8; i++) { //shift out 1 byte
digitalWrite(PGC, HIGH);
digitalWrite(PGC, LOW);
if (digitalRead(PGD) == HIGH)
value += 1 << i; //sample PGD
}
serialPrintHex(value);
}
}`
Very nice. So did it work out? If it works nicely and is indeed faster, feel free to send a pull request!
I can save the time of sending read commands every byte. and I don't know how to send a pull request. sorry.
I have one more question why do you use dummy clock? what is meaning for PIC? Could you explain it for me? I had checked the dummy clock at PICKIT device too.