This is a very strange error that, I feel, should be impossible, but I've been seeing this behaviour now in two separate MSP430g2553 chips. I am sure it's due to my hardware or software, but I can't figure out what. The error is that when I try to write data to the flash from the ADC, sometimes the data will not be written correctly. The strange things about this error are:
1) It is only the ADC data that gets corrupted. If I just write integers (say from 0 to 1000, or the counter, or anything) there is never any corruption
2) I strongly suspect that the data is being written by losing some of the most significant bits. For example, if my ADC reading is typically 500 +/- 40, I'll see data that goes 500, 501, 14, 503, etc. That drop to 14 suggests that I'm just losing half of the data on the write, or something?
3) The data is being read in from the ADC correctly. I've tested this in two ways. First, I sent the ADC data directly out of my UART without saving it first in flash. I cannot replicate the dropped bits when directly passing the data through. Second, in my flash write function, I compare the data in the just-written address to the data I wanted to write. I send an error flag if they are different, and this flag does indeed get set.
4) Very similar code worked just last week. However, there have been some changes that are worth mentioning:
a) I added a timer_A0 ISR to the code, but the interrupts are not enabled. I have been told that the memory I set aside in my flash memory overlaps the ISR storage area. I removed the ISR from the code and no longer use interrupts but the problem persists.
b) I have added a few functions to the code relating to timer A. I do not use them in my code (they are for a separate project and it is convenient to store everything in one file), so I suspect the compiler does not add them in, but I can't be sure.
If my problem were for ALL flash writes, I'd be unconcerned and just assume that my hardware setup screwed something up. I have tried four different sensors attached to my ADC with the same result, so it is clearly not a hardware issue on the sensor side. And here is the most confusing part of all:
5) I used to write two integers to the flash memory in my "flash_write" function. They were the readings from ADC pins 1.0 and 1.6. I have since changed that. I now write three integers. The first is just an index corresponding to the sample number, and the next two are the integers described above. For whatever reason this has stopped the corruption of the ADC values.
It's worth noting that BOTH ADC values could be corrupted, but typically the corruption happens at different samples for different ADC pins.
Can anyone think of what's going on?
Mike