Hi,
I'm using MSP430f149 and I want to write data like presented below to flash information memory.
parameter | record | note |
Name | "Name" | |
Date | "01.01.2012" | |
Author | "Alex Biz" | name |
Version | "0100" | 1.00 |
Serial number | "12345" |
So I'm going to put strings (record from table) of data into memory.
How to do that?
Regards.
Maybe
#include "io430.h" #include <string.h> #define INFO_MEM_SEG_A (0x010FF) #define INFO_MEM_SEG_B (0x0107F) int main( void ) { int size_of_string=0x0000; //Data information memory char* naziv="Prrikup podataka"; char* datum_proizvodnje="20.02.2012."; char* proizvodac="Alo Malo"; char* verzija_sw="0100"; char* verzija_hw="0100"; char* serijski_broj_uredaja="12345678"; char* adresa_mjernog_mjesta="00000001"; // Function prototypes void write_SegA (char *value, int flash_ptr_val, unsigned int size_of_string); // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; // Upis podataka u trajnu INFO flash memoriju size_of_string = strlen(naziv); write_SegA (naziv, INFO_MEM_SEG_A, strlen(naziv)); size_of_string += strlen(datum_proizvodnje); write_SegA (datum_proizvodnje, INFO_MEM_SEG_A + size_of_string, strlen(datum_proizvodnje)); size_of_string += strlen(proizvodac); write_SegA (proizvodac, INFO_MEM_SEG_A + size_of_string, strlen(proizvodac)); size_of_string += strlen(verzija_sw); write_SegA (verzija_sw, INFO_MEM_SEG_A + size_of_string, strlen(verzija_sw)); size_of_string += strlen(verzija_hw); write_SegA (verzija_hw, INFO_MEM_SEG_A + size_of_string, strlen(verzija_hw)); size_of_string += strlen(serijski_broj_uredaja); write_SegA (serijski_broj_uredaja, INFO_MEM_SEG_A + size_of_string, strlen(serijski_broj_uredaja)); size_of_string += strlen(adresa_mjernog_mjesta); write_SegA (adresa_mjernog_mjesta, INFO_MEM_SEG_A + size_of_string, strlen(adresa_mjernog_mjesta)); return 0; } void write_SegA (char *value, int flash_ptr_val, unsigned int size_of_string) { char *Flash_ptr; // Flash pointer unsigned int i; Flash_ptr = (char *) flash_ptr_val; // Initialize Flash pointer FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY; // Clear Lock bit *Flash_ptr = 0; // Dummy write to erase Flash segment FCTL1 = FWKEY + WRT; // Set WRT bit for write operation for (i=0; i<size_of_string; i++) { *Flash_ptr++ = *value++; // Write value to flash } FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit }