Forum: Mikrocontroller und Digitale Elektronik dsPIC33E RTSP


von Gee (Gast)


Lesenswert?

Habe Probleme den PIC eine Variable selbst schreiben zu lassen im Flash.
Er beschreibt zwar die richtigen Zellen, allerdings landet da nur 
Datenmüll drin (Randomzahlen)

In meinem Test Code Adressiere ich die Zellen ab 0x22000 und schreibe 
ein DWORD und 2 Bytes mit 0x66666 bzw. 0x66

Die Zellen sind frei und werden sonst nicht verwendet, eine 
Unterbrechung der Routine durch Interrupts ist ebenfalls nicht gegeben

hier mein code:
1
      mov  #0x2000,W0    ; 
2
      mov  W0,E_ZELLE
3
4
      mov  #0x6666,W0
5
      mov  W0,E_DATA
6
      call  WRITE_EE
7
8
WRITE_EE:  
9
; Load the destination address to be written
10
                        MOV #0x2,W9
11
                        MOV E_ZELLE,W8
12
                        MOV W9,NVMADRU
13
                        MOV W8,NVMADR;
14
; Load the two words into the latches
15
            MOV     #0x6666,W2  ; 1. Word
16
      MOV     #0x66,W3
17
      MOV     #0x6666,W4    ; 2. Word
18
      MOV     #0x66,W5
19
20
      TBLWTL  W2, [W0]
21
      TBLWTH  W3, [W0++]
22
      TBLWTL  W4, [W0]
23
      TBLWTH  W5, [W0++]
24
; Setup NVMCON for word programming
25
                        MOV     #0x4001,W0
26
                        MOV     W0,NVMCON
27
; Disable interrupts < priority 7 for next 5 instructions
28
; Assumes no level 7 peripheral interrupts
29
                        DISI    #06
30
; Write the key sequence
31
                        MOV     #0x55,W0
32
                        MOV     W0,NVMKEY
33
                        MOV     #0xAA,W0
34
                        MOV     W0,NVMKEY
35
; Start the write cycle
36
                        BSET    NVMCON,#15
37
                        NOP
38
                        NOP
39
      BTSC NVMCON, #15 ; Wait for the sequence to be completed
40
      BRA $-2 ;
41
  
42
      return

von Gee (Gast)


Lesenswert?

achja um verwirrung wegen dem code vorzubeugen: nach dem "call 
WRITE_EE" endet das programm und der Prozi geht in eine Schleife

von Gee (Gast)


Lesenswert?

ok für alle die es wissen wollen, ich habe jetzt die Funktionierende 
schreibroutine:
1
WRITE_EE:
2
; Initialize the TBLPAG register for writing to latches.  
3
    MOV     #0xFA,W12
4
    MOV     W12,TBLPAG
5
6
; Load W0:W2 with the next two instruction words to program.
7
    MOV     E_WORD_1,W0  ; 1. Word
8
    MOV     E_BYTE,W1
9
    MOV     E_WORD_2,W2  ; 2. Word
10
11
;  Set the read pointer (W6) and writer pointer (W7), and load the (next set of) write latches.
12
    CLR        W6
13
    NOP
14
    CLR       W7
15
    NOP
16
    TBLWTL    [W6++], [W7]    
17
    NOP
18
    NOP
19
    TBLWTH.B  [W6++], [W7++]  
20
    NOP
21
    NOP
22
    TBLWTH.B  [W6++], [++W7]    
23
    NOP
24
    NOP
25
    TBLWTL.W  [W6++], [W7++]  
26
    NOP           
27
    NOP
28
29
; Set the NVMADRU/NVMADR register-pair to point to the correct address
30
    MOV   E_ZELLE,W3
31
    MOV   #0x05,W4
32
    MOV   W3,NVMADR;
33
    MOV   W4,NVMADRU
34
35
; Set the NVMCON to program two instruction words
36
    MOV     #0x4001, W10
37
    NOP
38
    MOV     W10, NVMCON
39
    NOP
40
    NOP
41
42
; Initiate the write cycle.
43
    MOV     #0x55, W1
44
    MOV     W1, NVMKEY
45
    MOV     #0xAA, W1
46
    MOV     W1, NVMKEY
47
    BSET    NVMCON, #WR
48
    NOP
49
    NOP
50
    NOP
51
    NOP
52
    NOP
53
    NOP
54
55
      BTSC NVMCON, #WR ; Wait for the sequence to be completed
56
      BRA $-2 ;
57
  
58
      return

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.