Home > Back-end >  Encounter strange phenomenon, a great god ~ ~
Encounter strange phenomenon, a great god ~ ~

Time:11-24

fun () {
The if () {
Fun_1 ();
}
Else if () {
Fun_2 ();
}
}



In fun_1 () in the assignment of global variables in the loop to the fun for the second time in () else if the monitor shows zero it, is this why?

CodePudding user response:

The code completion, see you is how to operate the global variable

CodePudding user response:

reference 1st floor qybao response:
code completion, see you is how to operate the global variable

The switch (USB_FunCode) {
Case USB_FUN_READ: {
If (USB_CtrlCode==USB_CTRL_LIST) {
FLASH_READ_LIST (LIST_ARRAY_TEMP, & amp; DATA_SUMNUM, & amp; DATA_FLAG);
DataLen=DATA_SUMNUM * 9 + 3;
//FrameLen=DataLen + 5;
//USB_Frame [2]=DataLen & gt;> 8;
//USB_Frame [3]=DataLen;
USB_Frame [6]=DATA_SUMNUM;
for(i=0; I & lt; DATA_SUMNUM * 9; I++) {
USB_Frame [I + 7]=LIST_ARRAY_TEMP [I];
}
//USB_Frame] [FrameLen - 1=USB_SendFrameSum (& amp; USB_Frame [4], DataLen);

}
Else if (USB_CtrlCode==USB_CTRL_DATA) {
DATA_SN=* (+ 6) data;
//FLASH_READ_LIST (LIST_ARRAY_TEMP, & amp; DATA_SUMNUM, & amp; DATA_FLAG);
If (DATA_SN & gt; 0 & amp; & DATA_SN & lt;={DATA_SUMNUM)
DataLen=FLASH_READ_DATA (& amp; USB_Frame [6], DATA_SN) + 2;


Void FLASH_READ_LIST (uint8_t * pBuffer, uint8_t * SUMNUM, uint8_t * FLAG)
{

Uint8_t HEAD [2]={0};

Hal_W25QXX_Read (HEAD, 0, 2);
If (HEAD [1]==255) {
Hal_W25QXX_Erase_Chip ();
The HEAD [0]=0;
The HEAD [1]=0;
* SUMNUM=HEAD [0];
* FLAG=HEAD [1].
Hal_W25QXX_Write (HEAD, 0, 2);
}
The else {
* SUMNUM=HEAD [0];
* FLAG=HEAD [1].
}
Hal_W25QXX_Read (pBuffer, 2, * SUMNUM * 9);
}


Uint16_t FLASH_READ_DATA (uint8_t * pbuff, uint8_t SN)
{
Uint16_t NumByteToRead=0;
NumByteToRead +=LIST_ARRAY_TEMP [SN * 9-2] <8;
NumByteToRead +=LIST_ARRAY_TEMP [SN * 9-1);
Hal_W25QXX_Read (pbuff, SN * 65536, NumByteToRead);
Return (NumByteToRead);
}

CodePudding user response:

reference 1st floor qybao response:
code completion, see you is how to operate the global variable

Found that from the monitor when entering FLASH_READ_DATA this function, the value is zero it LIST_ARRAY_TEMP, I FLASH_READ_LIST to call this function within the else if problems can be solved, don't know why in this way, the global variable value is not should after a fu can save to the next is to rewrite it,

CodePudding user response:

Where LIST_ARRAY_TEMP defined, a global variable is sure? If it is really, in addition to the system reset, the contents of the array may be reset, watchdog has software?

CodePudding user response:

reference 5 floor poetryTang reply:
LIST_ARRAY_TEMP where is defined, the global variable is sure? If it is really, in addition to the system reset, the contents of the array may be reset, watchdog has software?
thank you, I also have this doubt, at first LIST_ARRAY_TEMP defined in the source file, in. H in the declaration, and in the main. Include in c, I try to directly in the main, the main c () defined before, still, and make sure not reset, because only the array have been reset, the other variables are fine,

CodePudding user response:

Do you have in this
If (USB_CtrlCode==USB_CTRL_LIST)
Else if (USB_CtrlCode==USB_CTRL_DATA)
How do you ensure that which branch to perform? If you don't have to enter the if (condition does not meet), enter the else if conditions (meet), that LIST_ARRAY_TEMP is not set,

CodePudding user response:

refer to 7th floor qybao response:
you
If (USB_CtrlCode==USB_CTRL_LIST)
Else if (USB_CtrlCode==USB_CTRL_DATA)
How do you ensure that which branch to perform? If you don't have to enter the if (condition does not meet), enter the else if conditions (meet), that LIST_ARRAY_TEMP is not set,
I debug, first send instructions read the list information, PC reply after confirm correct, then send to read data command, found a discrepancy between the results of debug monitor variables, found the problem,
  • Related