AnsweredAssumed Answered

HC12: Problem passing values between routines

Question asked by Daniel Rogers on Nov 20, 2006
Latest reply on Nov 21, 2006 by bigmac
Why does the value being returned from my routine different from the value in the routine sending it?
Im using MC9S12DP256 processor.
 
here is the routine doing the sending
 
uchar is declared as #define uchar unsigned char
 
/*------------------------------------------------------------*
| Name: SPI_Proc. uchar SPI_Proc(cValue);
|
| Description: Read port
*/
uchar SPI_Proc (/*uchar cPort,*/ uchar cValue)
{
 uchar cData
/*  while (!(*(char*)SPI_STATUS[cPort] & SPI_TEF));         // Wait for SPTEF set
 *(char*)SPI_DATA[cPort] = cValue;
 while (!(*(char*)SPI_STATUS[cPort] & SPI_IF));          // Wait for SPIF set
 return *(char*)SPI_DATA[cPort];*/
 
 while ((SPI0SR & 0x20) != 0x20);         // Wait for SPTEF set
 SPI0DR /**(char*)SPI_DATA[cPort]*/ = cValue;
 while ((SPI0SR & 0x20) != 0x20);         // Wait for SPTEF set
 cData = SPI0DR;
 Disp_8b_Dec(cData);
 return cData; /**(char*)SPI_DATA[cPort];*/
}
 
Data is 154 in this routine
 
Next routine in the link is in a different file
 
decleared as extern uchar SPI_Proc(uchar cValue);
 
/*------------------------------------------------------------*
| Name: MAX7301_Read. uchar MAX7301_Read(cCommand);
|
| Description: Read port
*/
uchar MAX7301_Read(/*uchar cDevice,*/ uchar cCommand)
{
 uchar cData;
 
 MAX7301_Write(/*cDevice,*/cCommand | 0x80,0);
 PTS /**(char*)MAX7301_SS_Port[cDevice]*/ &= ~ 0x80; //MAX7301_SS_SET[cDevice];
 (void)  SPI_Proc(/*MAX7301_Port[cDevice],*/0);
 cData = SPI_Proc(/*MAX7301_Port[cDevice],*/0);
 PTS /**(char*)MAX7301_SS_Port[cDevice]*/ |= 0x80; //MAX7301_SS_SET[cDevice];
 Disp_8b_Dec(cData);
 return cData;
}
 
cData is 154
 
the start of the link is
 
void MAX7301_Config_Port (/*uchar cDevice,*/ uchar cCommand, uchar cDir, uchar cBit)
{
 uchar cData;
 
//  Disp_8b_Dec(cCommand);
//  Disp_8b_Dec(cDir);
//  Disp_8b_Dec(cBit);
 cData = MAX7301_Read(/*cDevice,*/cCommand);
//  cData = cRetData;
 Disp_8b_Dec(cData);
 cDir = cDir << (cBit * 2);
 cData &= ~(0x03 << (cBit * 2));
 cData |= cDir;
 MAX7301_Write (/*cDevice,*/cCommand, cData);
//  Disp_8b_Dec(cCommand);
//  Disp_8b_Dec(cData);
 Disp_8b_Dec(255);
}
cData when read fromMAX7301_Read is 48
 
Why is this?
 
 


 

Message Edited by CrasyCat on 2007-04-13 11:51 AM

Outcomes