Save variable to ROM PIC32MZ2048EFG144

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Save variable to ROM PIC32MZ2048EFG144

#1 Post by ahmed.hasib » 01 Dec 2019 19:01

Hi,
How can i save a variable to rom which changed every time i power my pic32mz2048efg144?
also i want to read it every time i power my pic.
thanks.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Save variable to ROM PIC32MZ2048EFG144

#2 Post by stefan.filipovic » 03 Dec 2019 12:35

Hi Ahmed,

You can do it with our FLASH Library, please find the simple example I've made for you in the attachment.

Kind regards,
Attachments
Reset Counter.zip
(351.98 KiB) Downloaded 124 times
Stefan Filipović

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Save variable to ROM PIC32MZ2048EFG144

#3 Post by ahmed.hasib » 04 Dec 2019 16:16

Hi Stefan,
i tried to adjust your code to mikrobasic pic32 but it didn't work. also i checked the flash code in examples folder but didn't work too.
can i use the lib as simple as:

Code: Select all

Address=0xBD030000
variable=10 
Flash_Erase_Page(Address)                 ' erase page
Flash_Write_Word(Address, variable)   ' write 10 to the flash rom

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Save variable to ROM PIC32MZ2048EFG144

#4 Post by stefan.filipovic » 09 Dec 2019 12:00

Hi Ahmed,

Could you please attach that project for inspection?

Kind regards,
Stefan Filipović

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Save variable to ROM PIC32MZ2048EFG144

#5 Post by ahmed.hasib » 12 Dec 2019 11:57

Attached.
Attachments
Project.rar
(191.6 KiB) Downloaded 93 times

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Save variable to ROM PIC32MZ2048EFG144

#6 Post by stefan.filipovic » 13 Dec 2019 17:30

Hi Ahmed,

You need to do that with pointers, for example in this way.

Kind regards,
Attachments
Project.zip
(191.14 KiB) Downloaded 104 times
Stefan Filipović

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Save variable to ROM PIC32MZ2048EFG144

#7 Post by ahmed.hasib » 13 Dec 2019 18:15

Thanks Stefan, i'll check it and inform you.
Bon week-end!

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Save variable to ROM PIC32MZ2048EFG144

#8 Post by ahmed.hasib » 16 Dec 2019 11:45

Hi Stefan,
Thanks a lot, it works.
one last question:
how to know if the memory address i choose is free or not?
Thanks.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Save variable to ROM PIC32MZ2048EFG144

#9 Post by stefan.filipovic » 17 Dec 2019 09:58

Hi Ahmed,

You will read 0xFFFFFFFF from that address if the memory address is free.

Things you need to know:

The program Flash array for the PIC32MZ device is built up of a series of rows. A row contains 512 32-bit instruction words or 2048 bytes. A group of 8 rows composes a page; which, therefore, contains 8 × 2Kb = 16 Kb or 4096 instruction words.

A page of Flash is the smallest unit of memory that can be erased at a single time. The program Flash array can be programmed in one of two ways:
  1. - Row programming, with 512 instruction words at a time.
    - Word programming, with 1 instruction word at a time.
The CPU stalls (waits) until the programming operation is finished. The CPU will not execute any instruction, or respond to interrupts, during this time. If any interrupts occur during the programming cycle, they remain pending until the cycle completes.

You may find this forum post useful:
https://www.microchip.com/forums/m1019271.aspx

Kind regards,
Stefan Filipović

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Save variable to ROM PIC32MZ2048EFG144

#10 Post by ahmed.hasib » 18 Apr 2020 01:45

Hi,
i think it is working ok as i'm able to read, write and erase word to memory.
the question is:
can i add one word to the ptr^ and update it? i tried to do but when i read the memory it returns strange value.

Code: Select all

ADDRESS=0xBD030000
ptr = ^longword(ADDRESS)
Flash_Erase_Page(Address)         
update= ptr^+counter
Flash_Write_Word(Address, update)
thanks.

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Save variable to ROM PIC32MZ2048EFG144

#11 Post by ahmed.hasib » 19 Apr 2020 00:22

Solved :D
Thanks.

Post Reply

Return to “mikroBasic PRO for PIC32 General”