AnsweredAssumed Answered

Weird error. Codewarrior 6.2 Release, build 8127, HC908AP32

Question asked by Felix Straube on Sep 23, 2008
Latest reply on Oct 1, 2008 by Felix Straube
Hi
I have a really weird problem.
I am using the SCI port of the AP32 to communicate with a VDRIVE2 from Vinculum (http://www.vinculum.com). And to build the command to open a file on the USB Flash drive I use the following function:

Code:
void buildOpenFileCmdString(unsigned char *filename, datetime fileDatetime){  unsigned char a;  unsigned char c;  unsigned char inFileName_F = 1;    unsigned char years, months, days, hours, minutes, seconds;  volatile unsigned long tempDatetime;  unsigned char *tempDatetime_P;   // write filename to vcmCmd_OpenFile  for (a = 0; a < 12; a++)  {    c = *(filename + a);    if (inFileName_F)    {      if (c != '\0')      {         vcmCmd_OpenFile[2 + a] = c;                }            else       {        inFileName_F = 0;                }    }        if (!inFileName_F)    {      vcmCmd_OpenFile[2 + a] = ' ';              }  }  // convert and write datetime    years   = BCDToByte(fileDatetime.years); // convert from BCD to binary  months  = BCDToByte(fileDatetime.months);  days    = BCDToByte(fileDatetime.days);  hours   = BCDToByte(fileDatetime.hours);  minutes = BCDToByte(fileDatetime.minutes);  seconds = BCDToByte(fileDatetime.seconds);      tempDatetime  = (long)(years + 20) << 25  // convert binary datetime to 32 bit VCM format                | (long)months << 21                | (long)days << 16                | (long)hours << 11                | (long)minutes << 5                | (long)(seconds / 2);                                  tempDatetime_P = (unsigned char *)&tempDatetime;                  vcmCmd_OpenFile[15] = *tempDatetime_P++;  // write to VCM-format-datetime to vcmCmd_OpenFile  vcmCmd_OpenFile[16] = *tempDatetime_P++;                     vcmCmd_OpenFile[17] = *tempDatetime_P++;   vcmCmd_OpenFile[18] = *tempDatetime_P; }


 The thing is that, when the code
Code:
tempDatetime  = (long)(years + 20) << 25  // convert binary datetime to 32 bit VCM format                | (long)months << 21                | (long)days << 16                | (long)hours << 11                | (long)minutes << 5                | (long)(seconds / 2);   
executes, the VDRIVE2 module resets itself. ?????? I can't understand why.

And i found out that if I comment the line "| (long)minutes << 5" so that the code would be:

Code:
tempDatetime  = (long)(years + 20) << 25  // convert binary datetime to 32 bit VCM format                | (long)months << 21                | (long)days << 16                | (long)hours << 11//                | (long)minutes << 5                | (long)(seconds / 2);
The VDRIVE2 module does NOT reset itself and runs perfectly.

Also if I define the variables "
unsigned char years, months, days, hours, minutes, seconds;" as global instead of local, all runs perfect.

And also if I use this code to convert binary datetime to VCM format, (with local defined variables)
Code:
  tempDatetime  = (long)(years + 20) << 25;  // convert binary-datetime to 32-bit-VCM-format  tempDatetime  |= (long)months       << 21;  tempDatetime  |= (long)days         << 16;  tempDatetime  |= (long)hours        << 11;  tempDatetime  |= (long)minutes      <<  5;  tempDatetime  |= (long)(seconds / 2);
all runs as it should.

So i really was scraching my head for a while, trying to understand what happened.
I consider myself as a beginner in C coding, so if anybody has any idea what it could be, please let me know.
I thought maybe it could be that the stack is "full" and is interfering with some other variables, but even so i dont understand how the VDRIVE2 module resets itself. There isnt even any command to reset the module.
Maybe it is just a bad power supply (???) but i don't see why one code would alter it and the other not.

If anybody has any idea or suggestion of why this is happening please let me know.
I just want to know what is happening to avoid such problems in the future.
Thanks in advance
Regards
Felix
 
P.S.: Sorry for my bad english



 










Outcomes