We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello!
A function is called with three pointer parameters to assemble command messages for SPI-mode communication in SPI initialization function as follows.
Problem is that the addresses of parameters change when they go into the function.
This error occurs in working with debugging version and monitor program.
CMD_Message 0x00007DD0 -> 0x7FDD0 CMD_Argument 0x00007DCC -> 0x7FDCC CMD_Index 0x00007DCA -> 0x7FDCA
So that the assembled CMD_Message shows wrong results. I am working with Memory model of HCompact:'huge' data, 'near'func.
unsigned integer i; unsigned char CMD_Index; unsigned char CMD_Argument[4]; unsigned CMD_Message[6]; Assemble_CMDMessage(&CMD_Index, CMD_Argument, CMD_Message);
void Assemble_CMDMessage(unsigned char *CMD_index, unsigned char *CMD_argument, unsigned char *CMD_Message) { // Command Index consists of star bit of 1 bit, transmission bit of 1 bit, and command index of 6 bits. unsigned char good_crc7; xmemcpy(CMD_Message, (unsigned char *)CMD_index, sizeof(unsigned char)*1); // CMD_Message[0] xmemcpy(CMD_Message+1, (unsigned char *)CMD_argument, sizeof(unsigned char)*4); // CMD_Message[1] - CMD_Message[4] //Generate_CRC7(CMD_message); //generate a valid CRC field; good_crc7 = Generate_CRC7(CMD_Message); good_crc7 = good_crc7 << 1; // shift to left by 1 CMD_Message[5] = good_crc7; CMD_Message[5] = CMD_Message[5] + 1; // add end bit }
I would be really happy if anybody inform me of what causes this eror. Thanks. Yoong-Goog Cho
"Problem is that the addresses of parameters change when they go into the function"
Is that a problem? It's the values of the parameters that should concern you...
It's also very poor style to have your formal parameter names being almost - but not quite - identical to your global variable names (in fact, one of them is identical).
There's nothing illegal about it, but you are laying a trap for yourself and your successors that somebody is bound to fall into sooner or later due to just one little slip of the Shift key...
Thanks Andy!
Probably my description seems to be a little bit confusing. Here, the values of parameter are addresses because the parameters are pointer variables.
The addresses (values of parameters) change after they are transferred into the function.
Thanks.
http://www.keil.com/forum/docs/thread8590.asp