Forum: Mikrocontroller und Digitale Elektronik AT45DB161D Page_Buffer_Compare liefert immer match?


von max (Gast)


Lesenswert?

Hallo,
ich habe Daten im SRAM Buffer und schon vorhandene in einer Flash-Page.

Unterscheiden sie sich soll geflasht werden.

Mein Problem ist nun das mein Code immer einen wert zurück liefert das 
Page und Buffer gleich sind (match).

Warum ist das so?

1
/*****************************************************************************
2
3
*
4
5
*  Function name : Read_DF_status
6
7
*
8
9
*  Returns :    One status byte. Consult Dataflash datasheet for further
10
11
*          decoding info
12
13
*
14
15
*  Parameters :  None
16
17
*
18
19
*  Purpose :    Status info concerning the Dataflash is busy or not.
20
21
*          Status info concerning compare between buffer and flash page
22
23
*          Status info concerning size of actual device
24
25
*
26
27
*   mt: the 'if' marked with 'mt 200401' is a possible optimisation
28
29
*   if only one type of Dataflash is used (like on the Butterfly).
30
31
*   If the uC controls different types of dataflash keep the PageBits
32
33
*   and PageSize decoding in this function to avoid problems.
34
35
******************************************************************************/
36
37
unsigned char Read_DF_status (void)
38
39
{
40
41
  unsigned char result,index_copy;
42
43
  DF_CS_inactive;              //make sure to toggle CS signal in order
44
45
  DF_CS_active;              //to reset dataflash command decoder
46
47
48
49
  result = DF_SPI_RW(StatusReg);      //send status register read op-code
50
51
52
53
        result = DF_SPI_RW(0x00);        //dummy write to get result ### Hier hängt er###
54
55
56
57
  index_copy = ((result & 0x38) >> 3);  //get the size info from status register
58
59
  // mtA
60
61
  /// if (!PageBits) { // mt 200401
62
63
    // PageBits   = DF_pagebits[index_copy];  //get number of internal page address bits from look-up table
64
65
    // PageSize   = DF_pagesize[index_copy];   //get the size of the page (in bytes)
66
67
    PageBits   = pgm_read_byte(&DF_pagebits[index_copy]);  //get number of internal page address bits from look-up table
68
69
    PageSize   = pgm_read_word(&DF_pagesize[index_copy]);   //get the size of the page (in bytes)
70
71
  /// }
72
73
  // mtE
74
75
  return result;              //return the read status register value
76
77
}
78
79
/*****************************************************************************
80
81
*
82
83
*  Function name : Page_Buffer_Compare
84
85
*
86
87
*  Returns :    0 match, 1 if mismatch
88
89
*
90
91
*  Parameters :  BufferAdr  ->  Decides usage of either buffer 1 or 2
92
93
*          PageAdr    ->  Address of flash page to be compared with buffer
94
95
*
96
97
*  Purpose :    comparte Buffer with Flash-Page
98
99
*
100
101
*   added by Martin Thomas, Kaiserslautern, Germany. This routine was not 
102
103
*   included by ATMEL
104
105
*          
106
107
******************************************************************************/
108
109
unsigned char Page_Buffer_Compare(unsigned char BufferNo, unsigned int PageAdr)
110
111
{
112
  unsigned char stat;
113
114
  
115
116
  //DF_CS_inactive;          //make sure to toggle CS signal in order
117
118
  //DF_CS_active;          //to reset dataflash command decoder
119
120
  
121
122
  if (1 == BufferNo)                  
123
124
  {
125
126
    DF_SPI_RW(FlashToBuf1Compare);  
127
128
    DF_SPI_RW((unsigned char)(PageAdr >> (16 - PageBits)));  //upper part of page address
129
130
    DF_SPI_RW((unsigned char)(PageAdr << (PageBits - 8)));  //lower part of page address and MSB of int.page adr.
131
132
    DF_SPI_RW(0x00);  // "dont cares"
133
134
  }
135
136
  #ifdef USE_BUFFER2
137
138
  else if (2 == BufferNo)                      
139
140
  {
141
142
    DF_SPI_RW(FlashToBuf2Compare);            
143
144
    DF_SPI_RW((unsigned char)(PageAdr >> (16 - PageBits)));  //upper part of page address
145
146
    DF_SPI_RW((unsigned char)(PageAdr << (PageBits - 8)));  //lower part of page address
147
148
    DF_SPI_RW(0x00);                    //don't cares
149
150
  }
151
152
  #endif
153
154
  
155
156
  DF_CS_inactive;                        
157
158
  DF_CS_active;    
159
160
  
161
162
  do {
163
164
    stat=Read_DF_status();
165
  } while(!(stat & 0x80));              //monitor the status register, wait until busy-flag is high
166
167
  
168
169
  return (stat & 0x40);
170
171
}

Page_Buffer_Compare(1, i); liefert immer 0x00 aber warum?

von max (Gast)


Lesenswert?

keiner eine Ahnung?

von Arc N. (arc)


Lesenswert?

Höchstens die etwas merkwürdige /CS "Behandlung" bzw. die 
Statusregisterabfrage...
In den alten Quelltexten hier sieht das in etwa so aus (Timerabfragen um 
Endlosschleifen zu verhindern fehlen)
1
...
2
DFSELECT();
3
SPITransceive(DFBUFFER1TOMAINWE);
4
SPITransceive(h);
5
SPITransceive(l);
6
SPITransceive(0);
7
DFDESELECT();
8
9
do {
10
    DFSELECT();
11
    SPITransceive(DFREADSTATUS);
12
    res = SPITransceive(0);  
13
    DFDESELECT();
14
} while (!(res & 0x80));

Als Kommentar steht hier noch "DS 24.10 or 11.4"...

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.