Zapis do flash u PIC18F4685

Jan Smrz jan.smrz na email.cz
Úterý Květen 7 23:20:30 CEST 2013


Zdravim,

prosim o radu. Nemohu prijit na to, co delam spatne. Snazim se zapsat 
data do flash a stale bez uspechu. Zkusebni program pro XC8 je v priloze.
Data z flash se prectou spravne (pouze pri debugovani s PICKIT3, v 
simulatoru to nefunguje). Mazani ani zapis uz nefunguje vubec. Pricemz 
kod je tak jednoduchy, ze tam snad nejde nic zkazit.

Pripadne jestli nekdo nemate nejaky overeny kus kodu.


Dekuji,

J.S.



------------- další část ---------------
// PIC18F4685

#include <htc.h>


#pragma config CONFIG1H = 0x06		// Clock source setting, HSPLL (external resonator + PLL 4x)
#pragma config CONFIG2L = 0x1F		// Brown-out enabled, PWRT disabled
#pragma config CONFIG2H = 0x00		// Watchdog disabled
#pragma config CONFIG3H = 0x80		// Pin muxing
#pragma config CONFIG4L = 0x01		// Debug disabled, Extended instr. set disabled, Low-volt. programming disabled, Stack overflow resets
#pragma config CONFIG5L = 0x3F		// Code not protected
#pragma config CONFIG5H = 0xC0		// EEPROM and BOOT not protected
#pragma config CONFIG6L = 0x3F		// Write protection disabled
#pragma config CONFIG6H = 0xE0		// EEPROM and BOOT write protection disabled
#pragma config CONFIG7L = 0x3F		// Table reads not protected
#pragma config CONFIG7H = 0x40		// Boot block table reads protection disabled

typedef unsigned char uint8_t;
typedef unsigned long int uint32_t;

#define OFFSET	5


const char pdt_user_data[20] =
{
   0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 
   0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
};


int main(void)
{

   uint8_t block_data[64];
   uint8_t store_data[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
   uint32_t address;
   uint32_t address_block;
   uint8_t address_block_offset;
   uint8_t i;


   address = (uint32_t)pdt_user_data + OFFSET;
   address_block = address & (uint32_t)0xFFFFFFC0;			// set to nearest lower multiple of 64
   address_block_offset = address & 0x3F;

   // read block data
   ReadFlash(address_block, 64, (uint8_t*)block_data);

   // erase block
   EraseFlash(address_block, address_block+63);			// whole block should be erased

   //  define new block data
   for (i = 0; i < sizeof(store_data); i++)
      block_data[i+address_block_offset] = store_data[i];

   // write block back
   WriteBlockFlash(address_block, 1, (uint8_t*)block_data);


   while(1)
      ;

}






Další informace o konferenci Hw-list