Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Bert Van Den Berg
06/14/12 12:13
Read: 1081 times
Henderson
New Zealand


 
#187705 - C code sample from Silab website
Responding to: Rob Klein's previous message
Hi Rob,

Thanks for your comments. Below is the C code example to write to flash from firmware that Silabs suggests. I have converted the C code below to assembly and it also causes the micro to reset. Silabs seems to contradict itself in a number of places when looking at the C8051F504 datasheet their Application Notes (AN201) and code examples. I'm going to try some other things such as lowering the system clock frequency when writing to flash. I'm trying to make a bootloader to update the main code via the serial port because I can't use the C2 lines (too long a cable for C2 to work).

Cheers,

Bert




void FLASH_ByteWrite (FLADDR addr, char byte)
{
   bit EA_SAVE = EA;                   // Preserve EA
   char xdata * data pwrite;           // FLASH write pointer

   EA = 0;                             // Disable interrupts

   VDM0CN = 0xA0;                      // Enable VDD monitor and high threshold

   RSTSRC = 0x02;                      // Enable VDD monitor as a reset source

   pwrite = (char xdata *) addr;

   FLKEY  = 0xA5;                      // Key Sequence 1
   FLKEY  = 0xF1;                      // Key Sequence 2
   PSCTL |= 0x01;                      // PSWE = 1 which enables writes

   VDM0CN = 0xA0;                      // Enable VDD monitor and high threshold

   RSTSRC = 0x02;                      // Enable VDD monitor as a reset source

   *pwrite = byte;                     // Write the byte

   PSCTL &= ~0x01;                     // PSWE = 0 which disable writes

   EA = EA_SAVE;                       // Restore interrupts
}




List of 8 messages in thread
TopicAuthorDate
Problem writing to C8051F504 flash from firmware      Bert Van Den Berg      06/13/12 20:41      
   Some comments      Rob Klein      06/14/12 07:52      
      C code sample from Silab website      Bert Van Den Berg      06/14/12 12:13      
         the dog bites      Erik Malund      06/14/12 14:21      
      Responding to Bert's and Rob's prior messages        Brent Wilson      06/14/12 14:37      
         Wow      Rob Klein      06/14/12 15:08      
            Wow to you!      Brent Wilson      06/14/12 16:20      
   Problem solved        Bert Van Den Berg      06/14/12 17:49      

Back to Subject List