arduino-as-pic18f-programmer icon indicating copy to clipboard operation
arduino-as-pic18f-programmer copied to clipboard

"readFlash" function, and "Table Read" command

Open blueaiz-nsr opened this issue 1 year ago • 6 comments

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,

blueaiz-nsr avatar Dec 03 '24 05:12 blueaiz-nsr

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?

maximevince avatar Dec 03 '24 10:12 maximevince

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,

blueaiz-nsr avatar Dec 05 '24 13:12 blueaiz-nsr

I don't have a working setup to test this myself, currently, but here's how I'd proceed:

  • Make a variant of the readFlash function (which only reads a single byte now), and add a len and out parameter, like so: void readFlashBytes(byte usb, byte msb, byte lsb, int len, byte *out)

  • Then have it set up the address, like readFlash is doing, but loop the last 20-bit instruction len times, and write the result to out[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;
    }
}

maximevince avatar Dec 05 '24 14:12 maximevince

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);
}

}`

blueaiz-nsr avatar Dec 06 '24 07:12 blueaiz-nsr

Very nice. So did it work out? If it works nicely and is indeed faster, feel free to send a pull request!

maximevince avatar Dec 06 '24 07:12 maximevince

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.

blueaiz-nsr avatar Dec 16 '24 05:12 blueaiz-nsr