I am playing around with the USBMem example for the MCB214x Board. Using a hex editor I found the offset (0x800) of the data area on the RAM and wrote the following code to change the data in the readme.txt file.
I created a counter variable and it increments when I press switch sw1. I want to store its value into the file every time I push the switch.
class variables
U8 * offset = &Memory[0x800];
int counter=0;
now inside main function I wrote following code
PINSEL0 = PINSEL0|(0<<15);
IO0DIR = (0<<15);
while (1){
if(!SW1){
counter = counter+1;
LED_On(1<<16);
*offset = counter; //line 1
offset +=4; // line 2
} else {LED_Off(1<<16);}
};
The problem is that when I run the code on the board the led remains on after I have pressed the switch and the USB device becomes in accessible! However When I comment out the lines "line 1" and "line 2" and run the code the led switches on and off perfectly fine!
can anybody explain me whats going on wrong here ?
Your Problem is "line 2". Just adding 4 will make offset
run to the end of RAM very fast. Accessing beyond the end will probably trigger a fault.
Keep in mind that even a short a button press will be in the order of several ms, and the loop has no delays and is only a few instructions long.