Skip to content

Instantly share code, notes, and snippets.

@nickfox-taterli
Created July 8, 2018 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickfox-taterli/2d924b9861302704aafee036425a47e6 to your computer and use it in GitHub Desktop.
Save nickfox-taterli/2d924b9861302704aafee036425a47e6 to your computer and use it in GitHub Desktop.
MSP430G2553 Seg Flash R/W Code
#include <msp430.h>
#include <stdint.h>
void FlashErase(uint16_t addr)
{
FCTL3 = FWKEY;
FCTL1 = FWKEY + ERASE;
while(FCTL3 & BUSY);
*(uint8_t *)addr = 0;
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
while(FCTL3 & BUSY);
}
void FlashProgram(uint16_t addr,uint8_t data)
{
FCTL3 = FWKEY;
FCTL1 = FWKEY + WRT;
while(FCTL3 & BUSY);
*((uint8_t *)addr)=data;
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
while(FCTL3 & BUSY);
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
BCSCTL2 = SELM_0 | DIVM_0 | DIVS_0;
DCOCTL = 0x00;
BCSCTL1 = CALBC1_16MHZ; /* Set DCO to 16MHz */
DCOCTL = CALDCO_16MHZ;
BCSCTL1 |= XT2OFF | DIVA_0;
BCSCTL3 = XT2S_0 | LFXT1S_2 | XCAP_1;
IFG1 &= ~OFIFG;
FCTL2 = FWKEY | FSSEL_2 | FN5 | FN3 | FN1 | FN0;
while(1)
{
FlashErase(0x1000);
FlashProgram(0x1000,70);
__no_operation();
FlashErase(0x1000);
FlashProgram(0x1000,80);
__no_operation();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment