Write Flash

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Write Flash

Jump to solution
1,221 Views
gregoryclement
Contributor I

Hello;

I program a microcontroller mc9s08sh4 .

 

I used the various discussing how to read and write to the flash . I use the example given on the forum:

Unable to write S08 flash in run mode 

 

I manage to save one time a character, but I can not do it after.

 

Here is my example code :

 

void main(void)
{

unsigned char Byte_To_Be_Programmed = 'D';

/* Start by copying the Flash Routine to RAM */
CopyInRAM();

/* Init Flash Clock Divider */
FlashInit();


if (Flash_Program(0xFFB0, Byte_To_Be_Programmed))
{
/* Error while programming a Byte, write your error handling here */
}


Byte_To_Be_Programmed = 'B';

if (Flash_Program(0xFFB0, Byte_To_Be_Programmed))
{
/* Error while programming a Byte, write your error handling here */
}



EnableInterrupts;

for(;;)
{

__RESET_WATCHDOG();
}

 

The first time , the variable 'D' ( 0x44 ) is stored in memory .

 

As against the variable 'B' does not register properly ( 0x40 )

 

Whatever the second variable , it is always 0x40 .

 

Do you have an idea of the problem?

 

Thank you for your help. DSL for my English

Labels (1)
0 Kudos
1 Solution
773 Views
kef2
Senior Contributor IV

You are erasing interrupt vectors table... Look in your SH4 manual for flash sector (page) size. It is as 512 bytes. Erasing sector at 0xFFB0 you erase everything between 0xFE00 and 0xFFFF

View solution in original post

0 Kudos
4 Replies
773 Views
gregoryclement
Contributor I

Super thank you for the reply , I understand now , I'll watch it this week .

I have another question for the same microcontroller . It seems that I can put a pull-up or pull-down on my entries.

When enabled, the IRQ pin, defaults to use an internal pull device (IRQPDD = 0). The device is a pullup or pulldown depending on the polarity chosen. If the user uses an external pullup or pulldown, the IRQPDD can be written to a 1 to turn off the internal device.

By cons , I can only put a pull-up . How to put a pull-down ?

0 Kudos
773 Views
kef2
Senior Contributor IV

It is because you need to erase flash sector before doing second write to the same byte. First write 'D' == 0x44 clears bits so that 2 bits are left unprogrammed, bits 6 and 2, resulting byte is 0x44. 2nd write 'B' = 0x42 additionally clears bit 2 and in the end only bit 6 is left unprogrammed (=1), and you see 0x40.

0 Kudos
773 Views
gregoryclement
Contributor I

Hello;  I finally have another problem to record in the flash memory. Using Processor exprert, I am able to register in the flash several times. By cons, by modifying the code to have interrupt every 15 ms,I can not save a block and everything seems to hang. Here are some of the code:

for(;;) // main { if(Seconde%5 == 0) // every 5 seconds { IFsh1_EraseSector(0xFFB0); //Erase Data = Seconde; IFsh1_SetLongFlash(0xFFB0, Data);  //Record } }

void TI1_OnInterrupt(void) // Event.c { DifTimer++; if(DifTimer == 64) { DifTimer = 0; Seconde++; } }

I have tried disabling TI1_OnInterrupt (void) and disable interrupts, but it did not work Which solution I have to direct me to have a intetturption every 15 ms and to record? Thank you for your help
0 Kudos
774 Views
kef2
Senior Contributor IV

You are erasing interrupt vectors table... Look in your SH4 manual for flash sector (page) size. It is as 512 bytes. Erasing sector at 0xFFB0 you erase everything between 0xFE00 and 0xFFFF

0 Kudos