Hi,
I'm trying to save the conversion data of the SD24 ADC od MSP430AFE253 into the flash memory, but it sucks. My idea was: I collect 32 conversion values, save them into an array, and then quit the ADC ISR, go back to the main program where the content of the array gets saved to the flash memory. this actions are built in an infinte loop, so that the conversion/savin of the data is continous.
Unfortunately, when I look into the memory, I notice that only oone value (0) got saved at the address 0x1040. All other memory cells seem to be untaoched. Any body has a clue?
Here is my code:
//*****************************************************************************
#include <msp430afe253.h>
#define Num_of_Results 32
unsigned int results[Num_of_Results];
unsigned char lowbyte;
unsigned char highbyte;
void Write_Data(int n, char value);
void main(void)
{
volatile unsigned int j; // Use volatile to prevent removal by compiler optimization
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
SD24CTL = SD24REFON + SD24SSEL0; // 1.2V ref, SMCLK
SD24INCTL2 |= SD24INTDLY0; // Interrupt on 3rd sample
SD24CCTL2 |= SD24IE ; // Enable interrupt
SD24CCTL2 |= SD24UNI ; // Unipolar conversion
for (j = 0; j < 0x3600; j++); // Delay for 1.2V ref startup
while(1) {
SD24CCTL2 |= SD24SC; // Set bit to start conversion
for (j = 0; j < Num_of_Results; j++)
{
lowbyte = results[j] & 0xff;
highbyte = results[j] >>8;
Write_Data(2*j, lowbyte);
Write_Data(2*j+1, highbyte);
}
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
}
}
#pragma vector=SD24_VECTOR
__interrupt void SD24AISR(void)
{
static unsigned int index = 0;
switch (SD24IV)
{
case 2: // SD24MEM Overflow
break;
case 4: // SD24MEM0 IFG
break;
case 6: // SD24MEM1 IFG
break;
case 8: // SD24MEM2 IFG
results[index] = SD24MEM2; // Save CH0 results (clears IFG)
if (++index == Num_of_Results)
{
index = 0;
return;
}
break;
}
}
// ----------------------------- Write_Data_To_Memory -----------------------------------------
void Write_Data(int n, char value)
{
char *Flash_ptr; // Flash pointer
Flash_ptr = (char *)0x1040; // Initialize Flash pointer
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + ERASE; // Set Erase bit
Flash_ptr = Flash_ptr-n;
*Flash_ptr = 0; // Dummy write to erase Flash seg
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
*Flash_ptr = value; // Write value to memory
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}