Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

eeprom write dspic30f5013

Status
Not open for further replies.

Matteo Martinelli

Newbie level 6
Joined
Jan 10, 2014
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
Hi,
actually I'm using eeprom_rw.h library developed by btbass but it doesn't work.
I debugged my simple program carefully and the EEPROM's values doesn't change.

Someone have a solution?

Thanks
 

There are myriad reasons for causing the problem you reported, ranging from circuit up to the program.
Unless you provide more details concerning which was examined up to this point, we can not help much.


+++
 

Sorry me for the lack information.
I am using MPLAB 8.92 and C30 compiler.
I don't know that I add a deelay.

I attacched eeprom_rw.h and eeprom_rw.s file.
View attachment eeprom_rw.rar

If I would write a number like 55 in the first position and after read I must type:
Code:
WriteWord(0,55);
a=ReadWord(0);

But this code doesn't work, why?
 
Last edited:

This thread is now tagged as [SOLVED].
Does it means there are not any issue anymore ?



+++
 

No, I don't know this thread was marked as solved! (I remove SOLVED now)

anyone know the answer to the previous question?
 

I would suggest you employ another EEPROM library wrote in C language rather that this one in ASM, due could be easiest to handle some adjust. Moreover, I could not identify there, were is performed address device setup.






+++
 

In order to load some value inside internal EEPROM during firmware download, you could try this:


Code C - [expand]
1
2
3
4
5
extern unsigned short _EEDATA(2) ushEepromData[]  
   #ifdef extern 
      = {0x1234, 0x5678}    // any value
   #endif
   ;


You can check if were successfully stored by viewing content at IDE watch window ( assuming device under hardware debugger ).
Once confirmed, download the program again, but adding this code to declare...

...the read routine:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define ERASE_WORD 0x4044
      #define WRITE_WORD 0x4004
      #define ADDRESS_HI 0x007F
 
 unsigned short Eeprom_ReadWord(unsigned short * pushAddress) {
   unsigned short ushResult;
   register int eedata_addr; 
   register int eedata_val; 
   
   TBLPAG = ADDRESS_HI; // __builtin_tblpage()
   eedata_addr = (unsigned short)pushAddress; // __builtin_tbloffset()
   __asm__("TBLRDL [%[addr]], %[val]" : [val]"=r"(eedata_val) : [addr]"r"(eedata_addr)); 
  
   ushResult = eedata_val; 
   return (ushResult);
 }


...and this one to declare write routine:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void Eeprom_WriteWord(unsigned short * pushAddress, unsigned short ushValue) {
 
   TBLPAG = ADDRESS_HI;
   NVMADRU = ADDRESS_HI; // Write address of word to be erased into NVMADRU, NVMADR registers.
   NVMADR = (unsigned short)pushAddress;
   NVMCON = ERASE_WORD; // Setup NVMCON register to erase one EEPROM word.
   
   PROTECT_CODE_FROM_INTERRUPTS_START // Disable interrupts while the KEY sequence is written
      NVMKEY = 0x55; // Write the KEY sequence step1
      NVMKEY = 0xAA; // step2
      NVMCONbits.WR = TRUE; // Start the erase cycle
   PROTECT_CODE_FROM_INTERRUPTS_STOP // Enable interrupts
   
   while (NVMCONbits.WR == TRUE); // wait for the EEPROM
   
   NVMCON = WRITE_WORD; // Setup NVMCON register to write one EEPROM word. 
   {
      register int eedata_addr; 
      register int eedata_val; 
      
      eedata_addr = (unsigned short)pushAddress; // write low word of address
      eedata_val = ushValue; // write data
      
      __asm__ volatile ("TBLWTL %[val], [%[addr]]" : [val]"+r"(eedata_val) : [addr]"r"(eedata_addr));
   }
   
   PROTECT_CODE_FROM_INTERRUPTS_START // Disable interrupts while the KEY sequence is written
      NVMKEY = 0x55; // Write the KEY sequence step1
      NVMKEY = 0xAA; // step2
      NVMCONbits.WR = TRUE; // Start the erase cycle
   PROTECT_CODE_FROM_INTERRUPTS_STOP // Enable interrupts
   
   while (NVMCONbits.WR == TRUE); // wait for the word to be written
   
   // no proper watchdog protection in the 2 while loops
   // no proper check if bytes are written correctly by re-reading them
 }


The usage of the routine:

Code C - [expand]
1
2
uchValue = Eeprom_ReadWord(&ushEepromData[1]);
Eeprom_WriteWord(&ushEepromData[1], uchValue +1);



I don´t remember, but probably some file will be asked for during build process, but you must try first...
 

The Microchip C30 offers a fairly comprehensive set of EEPROM routines.

Reference: Microchip 16-Bit Language Tools Libraries Manual, Section: 4.6 FUNCTIONS FOR ERASING AND WRITING EEDATA MEMORY, Page: 204
_erase_eedata
Description: Erase EEDATA memory on dsPIC30F and PIC24FXXKA devices.
Include: <libpic30.h>
Prototype: void _erase_eedata(_prog_addressT dst, int len);
Argument: dst destination memory address
len dsPIC30F: length may be _EE_WORD or _EE_ROW(bytes)
PIC24FxxKA: length may be _EE_WORD, _EE_4WORDSor _EE_8WORDS (bytes)
Return Value: None.
Remarks: None.
Default Behavior: Erase EEDATA memory as specified by parameters.
File: eedata_helper.c

_erase_eedata_all
Description: Erase the entire range of EEDATA memory on dsPIC30F and PIC24FXXKA devices.
Include: <libpic30.h>
Prototype: void _erase_eedata_all(void);
Argument: None
Return Value: None.
Remarks: None.
Default Behavior: Erase all EEDATA memory for the selected device.
File: eedata_helper.c

_wait_eedata
Description: Wait for an erase or write operation to complete on dsPIC30F and PIC24FXXKA devices.
Include: <libpic30.h>
Prototype: void _wait_eedata(void);
Argument: None
Return Value: None.
Remarks: None.
Default Behavior: Wait for an erase or write operation to complete.
File: eedata_helper.c

_write_eedata_word
Description: Write 16 bits of EEDATA memory on dsPIC30F and PIC24FXXKA devices.
Include: <libpic30.h>
Prototype: void _write_eedata_word(_prog_addressT dst,
int dat);
Argument: dst destination memory address
dat integer data to be written
Return Value: None.
Remarks: None.
Default Behavior: Write one word of EEDATA memory for dsPIC30F devices.
File: eedata_helper.c

_write_eedata_row
Description: Write _EE_ROW bytes of EEDATA memory on dsPIC30F devices.
Include: <libpic30.h>
Prototype: void _write_eedata_row(_prog_addressT dst,
int *src);
Argument: dst destination memory address
*src points to the storage location of data to be written
Return Value: None.
Remarks: None.
Default Behavior: Write specified bytes of EEDATA memory.
File: eedata_helper.c


Example of Use – dsPIC30F DSCs

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "libpic30.h"
#include "p30fxxxx.h"
 
char __attribute__((space(eedata), aligned(_EE_ROW))) dat[_EE_ROW];
 
int main()
{
   char i,source[_EE_ROW];
   _prog_addressT p;
 
   for (i = 0; i < _EE_ROW; )
       source[i] = i++; /* initialize some data */
 
   _init_prog_address(p, dat); /* get address in program space */
   _erase_eedata(p, _EE_ROW); /* erase a row */
   _wait_eedata(); /* wait for operation to complete */
   _write_eedata_row(p, source); /* write a row */
}




BigDog
 

Thank you very much!

If I type this code:
Code:
//Read and write 1
Eeprom_WriteWord(&ushEepromData[0], 0x0023);
uchValue = Eeprom_ReadWord(&ushEepromData[0]);
//Read and write 2
Eeprom_WriteWord(&ushEepromData[1], 0x1111);
uchValue2 = Eeprom_ReadWord(&ushEepromData[1]);

The first time, the program write successfully and uchValue=0x0023.
Instead, the second write doesn't work, so when program execute the second ReadWord, in uchValue2 is saved the old value that was added in a declaration step.

I resolved this issue simply adding a for statement as below
Code:
//Read and write 1
Eeprom_WriteWord(&ushEepromData[0], 0x0023);
uchValue = Eeprom_ReadWord(&ushEepromData[0]);
for(i=0;i<10000;i++);
//Read and write 2
Eeprom_WriteWord(&ushEepromData[1], 0x1111);
uchValue2 = Eeprom_ReadWord(&ushEepromData[1]);

Now it works.
anyone who can explain me why the second block works, while the first one doesn't?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top