Using SerialPort communication between PC and MSP430F5438A. It's C# on the PC side and Code Composer Studio (CCS) on the MSP430 side. I'm sending "Hello World!" to MCU. I set the flash pointer to address 0x20000:
unsigned long *Flash_ptr= 0x20000; // Initialize Flash pointer
then I write to flash (This procedure repeat itself as the number of the chars in the string or the text file):
void write_SegC(char data)
{
//__disable_interrupt(); // 5xx Workaround: Disable global
// interrupt while erasing. Re-Enable
// GIE if needed
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE; // Set Erase bit
*(unsigned int *)Flash_ptr = 0; // Dummy write to erase Flash seg
FCTL1 = FWKEY+WRT; // Set WRT bit for write operation
while(!(WAIT & FCTL3));
*Flash_ptr++ = data; // Write value to flash
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}
And then send it back to PC:
void read_SegC(void)
{
unsigned long i;
Flash_ptr=0x20000;
for(i = 0; i < 8; i++)
{
while(!(WAIT & FCTL3));
while(!(UCA1IFG & UCTXIFG));
UCA1TXBUF=*Flash_ptr++; // Write long int to Flash
}
}
what I get in PC: 2d!Wo
instead of: Hello World! which means I just get some chars of the string! the rest are garbage. What I did wrong?