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.
Save variable to ROM PIC32MZ2048EFG144
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: Save variable to ROM PIC32MZ2048EFG144
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,
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 135 times
Stefan Filipović
-
- Posts: 73
- Joined: 11 Jul 2015 17:59
Re: Save variable to ROM PIC32MZ2048EFG144
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:
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
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: Save variable to ROM PIC32MZ2048EFG144
Hi Ahmed,
Could you please attach that project for inspection?
Kind regards,
Could you please attach that project for inspection?
Kind regards,
Stefan Filipović
-
- Posts: 73
- Joined: 11 Jul 2015 17:59
Re: Save variable to ROM PIC32MZ2048EFG144
Attached.
- Attachments
-
- Project.rar
- (191.6 KiB) Downloaded 101 times
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: Save variable to ROM PIC32MZ2048EFG144
Hi Ahmed,
You need to do that with pointers, for example in this way.
Kind regards,
You need to do that with pointers, for example in this way.
Kind regards,
- Attachments
-
- Project.zip
- (191.14 KiB) Downloaded 110 times
Stefan Filipović
-
- Posts: 73
- Joined: 11 Jul 2015 17:59
Re: Save variable to ROM PIC32MZ2048EFG144
Thanks Stefan, i'll check it and inform you.
Bon week-end!
Bon week-end!
-
- Posts: 73
- Joined: 11 Jul 2015 17:59
Re: Save variable to ROM PIC32MZ2048EFG144
Hi Stefan,
Thanks a lot, it works.
one last question:
how to know if the memory address i choose is free or not?
Thanks.
Thanks a lot, it works.
one last question:
how to know if the memory address i choose is free or not?
Thanks.
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: Save variable to ROM PIC32MZ2048EFG144
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:
You may find this forum post useful:
https://www.microchip.com/forums/m1019271.aspx
Kind regards,
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:
- - Row programming, with 512 instruction words at a time.
- Word programming, with 1 instruction word at a time.
You may find this forum post useful:
https://www.microchip.com/forums/m1019271.aspx
Kind regards,
Stefan Filipović
-
- Posts: 73
- Joined: 11 Jul 2015 17:59
Re: Save variable to ROM PIC32MZ2048EFG144
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.
thanks.
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)
-
- Posts: 73
- Joined: 11 Jul 2015 17:59
Re: Save variable to ROM PIC32MZ2048EFG144
Solved
Thanks.
Thanks.