Read a long data from RAM address 0x0200 and burn it into flash with address 0x1800.

code:

#include“io430.h”

void main(void)

{

//Initializes the pointer of the ram information segment

unsigned long * RAM_ ptr = (unsigned long *) 0x0200;

//Initializes the pointer of the flash message segment

unsigned long * Flash_ ptr = (unsigned long *) 0x1800;

How to burn the long data in MSP430 MCU into flash

//Variables for storing data

unsigned long value;

WDTCTL = WDTPW + WDTHOLD; // Close the watchdog

P4DIR |= BIT2; // Set P4.2 as the output port and connect the LED as the indication

while(FCTL3 & BUSY); // Determine whether it is busy

FCTL3 = FWKEY; // Clear lock flag

FCTL1 = FWKEY + ERASE; // Select segment erase and set erase

*Flash_ ptr = 0; // Write the address pointed by the pointer to 0 and start erasure

FCTL1 = FWKEY + BLKWRT; // Write allowed, long word

//Read ram information to value variable

value = *RAM_ ptr;

*Flash_ ptr = value; // Write flash

while(FCTL3 & BUSY); // Determine whether it is busy

FCTL1 = FWKEY; // Clear wrt bit

FCTL3 = FWKEY + LOCK; // Set lock flag

while(1)

{

P4OUT ^= BIT2; // When the burning is completed, the green indicator light is on

__ delay_ cycles(1000000);

}

}

Topic 2

Read a character array with length of 8 from RAM address 0x0200 and burn it into flash with address 0x1800.

#include“io430.h”

# define NumToWrite 8

void main(void)

{

//Initializes the pointer of the ram information segment

unsigned char * RAM_ ptr = (uint8_t *) 0x0200;

//Initializes the pointer of the flash message segment

unsigned char * Flash_ ptr = (uint8_t *) 0x1800;

//Variables for storing data

unsigned char value[NumToWrite];

int i;

WDTCTL = WDTPW + WDTHOLD; // Close the watchdog

P4DIR |= BIT2; // Set P4.2 as the output port and connect the LED as the indication

while(FCTL3 & BUSY); // Determine whether it is busy

FCTL3 = FWKEY; // Clear lock flag

FCTL1 = FWKEY + ERASE; // Select segment erase and set erase

*Flash_ ptr = 0; // Write the address pointed by the pointer to 0 and start erasure

FCTL1 = FWKEY + BLKWRT; // Write allowed, long word

//Read ram information to value variable

for (i=0;i

value[i] = *RAM_ ptr++;

//Write array to flash

for (i=0;i

*Flash_ ptr++ = value[i];

while(FCTL3 & BUSY); // Determine whether it is busy

FCTL1 = FWKEY; // Clear wrt bit

FCTL3 = FWKEY + LOCK; // Set lock flag

while(1)

{

P4OUT ^= BIT2; // When the burning is completed, the green indicator light is on

__ delay_ cycles(1000000);

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *