Created
July 8, 2018 13:25
-
-
Save nickfox-taterli/2d924b9861302704aafee036425a47e6 to your computer and use it in GitHub Desktop.
MSP430G2553 Seg Flash R/W Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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