Read/Write program flash memory of PIC18F67K40

General discussion on IDE.
Post Reply
Author
Message
thameemkj
Posts: 8
Joined: 19 Aug 2023 11:44

Read/Write program flash memory of PIC18F67K40

#1 Post by thameemkj » 17 Apr 2024 07:30

Hello,
I need assistance to write data into program flash memory of p18f67k40.
I am able to read data from pfm using FLASH_Read() under FLASH library.
But when I try to write data into pfm, its not making any change in the pfm.
But when I read after calling FLASH_Erase() on some address, I get FF on entire row.

The IDE that I use is MikroC Pro.
Looking forward for some advices.

Thankyou.

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Read/Write program flash memory of PIC18F67K40

#2 Post by IvanJeremic » 19 Apr 2024 08:18

Hi,

Make sure to erase to use FLASH Erase before writing anything to it.

You can find the example on how to use FLASH Write below:

Code: Select all

unsigned short toWrite[64];
...
// initialize array:
for (i = 0; i < 64; i++)
  toWrite[i] = i;

// write contents of the array to the address 0x0D00:
FLASH_Write_64(0x0D00, toWrite);
Regards,

Ivan.

thameemkj
Posts: 8
Joined: 19 Aug 2023 11:44

Re: Read/Write program flash memory of PIC18F67K40

#3 Post by thameemkj » 22 Apr 2024 10:07

Hello Ivan,
Thankyou for your answer.
But there are few things that I want to say,
1) PIC18F67K40 on MikroC Pro v7.6.0 have only functions like FLASH_Read/Write/Erase(). It does not have function like FLASH_Write_64().
2) The address parameter in FLASH_Read/Write/Erase() has type unsigned which has size 2 bytes according to MikroC Pro's documentation. Then how can we work with locations
of greater than 2 Bytes ? According to datasheet this mcu has 128KB of program flash memory.
3) With the functions FLASH_Read/Write/Erase(), Im able to work on memory locations within 2 Bytes of range.

Looking forward to hearing from you.
Regards.

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Read/Write program flash memory of PIC18F67K40

#4 Post by IvanJeremic » 23 Apr 2024 08:54

Hi,

You can still use the FLASH_Write function like the FLASH_Write_64.

You should be able to use the memory of the MCU with the available FLASH library.
flashmem.png
flashmem.png (22.92 KiB) Viewed 55 times
Regards,

Ivan.

thameemkj
Posts: 8
Joined: 19 Aug 2023 11:44

Re: Read/Write program flash memory of PIC18F67K40

#5 Post by thameemkj » 23 Apr 2024 10:39

Hi Ivan,
Thanks for this.
Just to make sure, so
1) FLASH_Erase() will erase 64(words) * 2(word size) = 128 locations (or bytes) from given address ?
2) Similarly FLASH_Write() will write 128 locations (or bytes) from the given address ?
3) But FLASH_Read() will read 1 byte from given address ?

Looking forward.
Regards.

Post Reply

Return to “IDE General”