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.

Regarding : dsPIC30F4011 Flash memory read/write/erase operations

Status
Not open for further replies.

htcompany

Junior Member level 2
Joined
Feb 2, 2016
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
220
Hello to all,

I am doing operations in dsPIC30F4011 controller in Flash memory. i am not getting proper output on LCD. I am posting the C code for the same.
Please kindly suggest solution as soon as possible.


Regards....

/

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
***********************************  dsPIC30F4011_Flash program *************************************/
 
#include <p30f4011.h>
#include <libpic30.h>
#include <stdio.h>
#include "lcd.h"
 
#define ERASE_WORD 0x4041   //#define ERASE_WORD 0x4044
#define WRITE_WORD 0x4001   //#define WRITE_WORD 0x4004
#define ADDRESS_HI 0x007F
#define EEPROM_LOW_START_ADDRESS 0x0000
#define TRUE 1
 
// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, Fcy=30MHz
_FWDT(WDT_OFF);                  // Watchdog timer off
_FBORPOR(MCLR_DIS);              // Disable reset pin
_FGS(CODE_PROT_OFF); 
 
 
 
 
int main(void)
{
     int value=0,  digit=0;
 
    
    lcd_init();   
                    //Setup UART for debugging
    U1BRG = 48;     // Setup UART for debugging;;;  38400 baud @ 30 MIPS;;
    U1MODEbits.UARTEN = 1; // Enable UART
  
        while(1)
            {
                //digit = Eeprom_ReadWord(0);  
      
                //LCDWriteIntXY(0,0,digit,4);          // Eeprom_WriteWord(13,0x4612 );Eeprom_WriteWord(84,0xf123 );Eeprom_WriteWord(30,0x4444 );                 
 
                //digit++;
        
                //Eeprom_WriteWord(0,digit);
 
                //del(300);  // original loop
                               
                    digit = Eeprom_ReadWord(5);
                    if(digit == 255)
                      // lcd_data('P');
                    
                    LCDWriteIntXY(0,0,digit,3);
                    digit++;
                    Eeprom_WriteWord(5,digit);
                     
                    del(400);
                
             }
    
 return 0;
}
    
 
 
void Eeprom_WriteWord(unsigned short  pushAddressOffset, int value) 
{
     unsigned short pushAddress;
     pushAddressOffset = pushAddressOffset*2; //word offset , byte addressable so multiply by 2
     pushAddress = pushAddressOffset + EEPROM_LOW_START_ADDRESS;
     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 EEPROMS
    
          NVMCON = WRITE_WORD; // Setup NVMCON register to write one EEPROM word. 
              {
                int eedata_addr; 
                unsigned char eedata_val; 
       
                      eedata_addr = (unsigned short)pushAddress; // write low word of address
                      eedata_val = value; // write data
       
                    __asm__ volatile ("TBLWTL %[val], [%[addr]]" : [val]"+r"(eedata_val) : [addr]"r"(eedata_addr));
              }   
                 
    
    NVMCON = WRITE_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;
 
             //NVMCONbits.WREN = 0; // Start the erase cycle
             //PROTECT_CODE_FROM_INTERRUPTS_STOP // Enable interrupts
    
   while (NVMCONbits.WR == TRUE); // wait for the word to be written
    
              
 }
 
 
 
int Eeprom_ReadWord(unsigned short  pushAddressOffset) 
{
   int Result;
 
   register int eedata_addr; 
   register unsigned char eedata_val; 
 
         unsigned short pushAddress;
 
                pushAddressOffset = pushAddressOffset*2; //word offset , byte addressable so multiply by 2
                pushAddress = pushAddressOffset + EEPROM_LOW_START_ADDRESS;
    
                                TBLPAG = ADDRESS_HI; // __builtin_tblpage()
 
                               eedata_addr = (unsigned short)pushAddress; // __builtin_tbloffset()
                              __asm__("TBLRDL [%[addr]], %[val]" : [val]"=r"(eedata_val) : [addr]"r"(eedata_addr)); 
       
   Result = eedata_val; 
   
   return Result;
 }

 
Last edited by a moderator:

Hi,

i am not getting proper output on LCD
This is no error description.

--> please describe what you expect
--> and tell us what happens instead.

Klaus
 

Regarding : dsPIC30F4011 Flash memory read/write/erase operations

hello,
on LCD, data keeps incrementing as per intsruction written in while() loop. but when i swiff off controller and then switch on, i dont find any data on LCD. the code is supposed to keep incrementing value when i again switch on controller from the value where it was switched off.


Thanks...
 

Hi,

"if(digit == 255)"
What happens exactely when digit = 255

What if not digit == 255?

Klaus
 

hello,
when i load code, it starts incrementing from 00000 and recheas upto 00255. again it starts 00000 and upto 00255. my intention is, i want to store the value of "digit" variable in flash and when i remove power supply to uController and again applying supply, it should keep incrementing value...that is all....... "if(digit == 255)" statement is only for testing purpose. it serves nothing in this code.


Thanks....
 

Hi,

"pushAddressOffset" is modified within the function. (I´d avoid this, because you can easily do the same with local variable "pushAddress")

If it is transferred as pointer, then it will be modified in the main loop also.
If it is transferred as variable, then it should not be modified in main loop. Please check this.

Klaus
 

hello,
sorry dear to say but, all your answers are irrelevant of my questions. you are not getting my problem properly, and you are answer something that is not related to asked questions. i am asking something, and you are answering something else.


Thanks for cooperation....
 

Hi,

Maybe you don´t see the relationship:

If the variable is modifiend within the ISR --> you won´t get the expected results.
Because the "write" takes place at the modified address (not at address "5" anymore) , then the data at address "5" will never be changed. It stays "0".
And that is what you describe .. if i understand right.

But the IF is underlined, because I´m not very faimilar the varaible handling in C. ...and we had similar problems in yóur company.

***
that is not related to asked questions. i am asking something, and you are answering something else.
To be honest: I don´t see a single question in all your posts.

But I understand there is a mistake.

Where can it be:
* You don´t write at all (--> check EEPROM contents with a programmer/debugger)
* You don´t write the correct data (--> check EEPROM contents with a programmer/debugger)
* you don´t write at correct address (--> check EEPROM contents with a programmer/debugger)
* Your read function doesn´t read the correct address (Debug_output data via UART)
* your read function does not transfer the correct data (Debug_output data via UART within read function)
* your LCD doesn´t show the correct data

Klaus
 
OK..... Thanks......... i am trying.....:)
 

Hello,
Good morning.......... Flash programming is successfully done.......... Thanking you Sir............. Great Help from you............



Regards...
htcompany
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top