@winfried: danke, genau sowas hab ich gemeint
nun zum aktuellen problem: ich kann keine daten in den flash
programmieren (löschen funktioniert).
hier der sourcecode:
//----------------------------------------------------------------------
-------
//function loads the page buffer
void loadPageBuffer(unsigned int *data, unsigned char count)
{
unsigned char word_counter;
for(word_counter=0;word_counter<count;word_counter++)
{
//load the actual word
page_data = data[word_counter];
//laod the actual address
page_address = word_counter;
//wait for the erase operation to be finished
while((SPMCSR&0x01)==1);
//write word to buffer
#asm
movw r30, r6 //move CurrentAddress to Z
pointer
movw r0, r2 //move current data
#endasm
//setup SPMCSR
SPMCSR = STORE_WORD;
//call the spm
#asm("spm");
}
}
//----------------------------------------------------------------------
-------
//function stores a page to the flash of the mcu
void writePage(unsigned char write_address)
{
page_address = write_address; //page_addres @ r4
page_address = page_address<<8;
//erase page
#asm
mov r31, r4 ;//move CurrentAddress to Z
pointer
#endasm
//set up SPMCS register
SPMCSR = PAGE_ERASE;
//call the spm
#asm("spm");
//wait for the erase operation to be finished
while((SPMCSR&0x01)==1);
//write page
#asm
mov r31, r4 ;//move CurrentAddress to Z pointer
#endasm
//set up SPMCS register
SPMCSR = PAGE_WRITE;
//call the spm
#asm("spm");
//wait for the erase operation to be finished
while((SPMCSR&0x01)==1);
}
zuerst wird loadPageBuffer() aufgerufen, und ein array aus 0 übergeben.
count = 230
dann wird writePage() aufgerugen
write_Address = 230
nach dem auslesen steh bis zur adresse des bootlaoders alelrdings immer
FF - also flash ist noch gelöscht.
korrigiert mich bitte, falls ich mich irre:
Zuerst lade ich die zu schreibenden daten in den temporären buffer
(addressiert über Z-pointer)
dann schreibe ich eine page (page adresse per z-pointer h-register)
nun sollte der wert doch drin stehn oder?