Hallo, ich versuche mich gerade an Schreibvorgängen im Flash-Speicher (Programm-Speicher) des PIC18F46K22). Die Funktion habe ich weitestgehend aus WriteBlockFlash.c übernommen. Ich verstehe nicht, wieso es heissen muss:
1 | tbl_ptr = (const uint8_type *)startaddress; |
Wenn ich dass schreibe:
1 | tbl_ptr = (uint8_type *)startaddress; |
so wird die Adresse des TablePointers (Register TBLPTR im PIC) beim Durchlaufen der Schleife (*tbl_ptr++ = *flash_array++;) nicht erhöht und die Funktion macht dann nicht dass, was sie soll. Ich konnte das mit dem Debugger testen.
1 | void save_eeprom_to_flash(uint16_type startaddress, uint8_type num_blocks, uint8_type *flash_array) |
2 | {
|
3 | uint8_type flag = 0; |
4 | uint8_type i = 0; |
5 | uint8_type *tbl_ptr = 0; |
6 | for(i=0;i<64;i++) |
7 | {
|
8 | flash_array[i]=i; |
9 | }
|
10 | startaddress /= FLASH_BLOCK_SIZE; /*Anfangsadresse auf Vielfaches von 64Byte setzen (Blockgroesse PIC46K22 = 64Byte fuer schreiben/loeschen)*/ |
11 | startaddress *= FLASH_BLOCK_SIZE; |
12 | tbl_ptr = (const uint8_type *)startaddress; /*so ist es richtig*/ |
13 | //tbl_ptr = (const uint8_type *)startaddress; /*falsch, Adresse von TBLPTR wird nicht in while-Schleife erhöht*/
|
14 | for(i=0;i<FLASH_BLOCK_SIZE;i++) |
15 | {
|
16 | *tbl_ptr++ = *flash_array++; |
17 | }
|
18 | EECON1bits.EEPGD = 1; |
19 | EECON1bits.CFGS = 0; |
20 | EECON1bits.WREN = 1; |
21 | if(INTCONbits.GIE == 1) |
22 | {
|
23 | flag = 1; |
24 | INTCONbits.GIE = 0; |
25 | }
|
26 | EECON2 = 0x55; |
27 | EECON2 = 0xAA; |
28 | EECON1bits.WR = 1; |
29 | while(EECON1bits.WR == 1); |
30 | if(flag == 1U) |
31 | {
|
32 | INTCONbits.GIE = 1; |
33 | }
|
34 | EECON1bits.WREN = 0; |
35 | }
|
Vielen Dank