Hola All,
I'm trying to make a program that takes ADC readings twice a second for a hour and stores these values
in the Main flash memory of the MSP430x2274.Later this data will be sent to a computer and
then graphed using MatLab.
I've drawn out a general flow chart of how this program will function, and I've made and tested
functions to take care of the timing and the voltage readings with success. However, I've hit a
bump. I made functions that erase, write too, and get data from the information memory, but there
isn't enough room in information memory. I then tried to alter these functions so they would instead
write, read, and erase segments of main memory. Its this part that I'm stuck on.
I've made some code below that uses the functions i'm trying to use to accomplish reading and
writing to FLASH. Unlike the info memory, all the memory in the main section, when viewed in the Memory
window, are 0, and since bits in Flash memory can only be changed from 1 to 0 I
created an erase function, but it doesn't work and I don't know why. Sorry about that run on sentence.
There are also sections in the main memory that all have the same "random" value and are spaced the same
distance apart. I have no idea what these are or do, but they do change every time I step through the code.
So let me sum up my questions concisely.
1) In the code below, why don't the functions work as intended?
2) Can I use Flash memory as data storage, without moving or altering the code memory?
Thanks for looking over my code ,and any help you can offer.
Triston
____________________________________ CODE __________________________________________________
#include'msp430x22x4';
//******************************* Function declarations ****************
void Data_Erase_Main(void);
//******************************* Global Variables *********************
volatile unsigned int ADC, i, Temp;
//******************************* Main Program Start *******************
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Turn off WDT
// Clock Set Up
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
BCSCTL2 = SELM_0 | DIVM_0|DIVS_3; // Selects DCo as masterclock, Division
// for master clock and submaster clock
// (1, and 8, respectively)
for(;;)
{
Data_Erase_Main(); // supposed to erase a segment of main memory.
for( i = 1; i< 4 ;i++) // For loop places 1 - 3 in main memory
{
ADC = i;
Data_In_Main(i);
}
for( i = 1; i < 4; i++) // Using CCE Debug the values 1 - 3 are checked
{
Temp = Data_Out_Main();
}
}
}
//****************************** Function Definitions ************************************
//------------------------------ Data_Erase_Main -----------------------------------
void Data_Erase_Main(void)
{
int *P_int;
FCTL2 = FWKEY + FSSEL0 + FN1;
FCTL3 = FWKEY; // clr LOCK bit
FCTL1 = FWKEY + ERASE; // activate segment erase mode
P_int = (int*)0x4A00;
*P_int = 0; // Dummy write to erase.
}
// ----------------------------- Data_In_Main -----------------------------------------
void Data_In_Main(int n)
{
int *P_int;
FCTL2 = FWKEY + FSSEL0 + FN1;
FCTL3 = FWKEY; // CLR LOCK Bit
FCTL1 = FWKEY + WRT; // Set WRT bit to enable WRT mode
n--; // setting n to one will ensure a write to the
// original pointer location (i.e. 0x4A00).
P_int = (int*)0x4A00; // Intiate pointer to selected location
P_int = P_int - n;
*P_int = ADC;
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
}
//--------------------------- Data_Out_Main ------------------------------------------
unsigned int Data_Out_Main(int n)
{
volatile unsigned int x2 = 0;
int *P_int;
FCTL2 = FWKEY + FSSEL0 + FN1;
FCTL3 = FWKEY; // CLR LOCK bit
n--;
P_int = (int*)0x4A00; // Set pointer to reference location
P_int = P_int - n; // Go to location n away from reference
x2 = *P_int; // Store value in x2
return x2; // return x2 value to main function
}