This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

call by value does not work

Hello,

I'm trying to pass a variable to a function, but the value stored in the variable never arrives. When I pass a constant, however, the value is handed over. An example follows:

main.c
extern void TransmitHex( unsigned char hexval );

main{
unsigned char var;
var = 0x41;
TransmitHex( 0x41 ); // produces an "A" in ASCII
TransmitHex( var ); // nothing shows up, possibly 0x00 is transmitted
}
---
serial.c

void TransmitHex ( unsigned char hexval){
/* transmit hexval via serial port */
}

I've tried to locate var with NEAR and FAR, but the problem persists. I'm using the HLARGE memory model. I have an external RAM connected to the ST10, address window is configured properly.

any ideas?

regards,
Soenke

Parents
  • here is the code for TransmitHexByte()

    
    typedef unsigned char byte;
    
    void TransmitHexByte(byte sendstr)
    {
      S0TIR = OFF;          // clear transmit
      S0TBUF = 0x30;	// send "0" ASCII
      while(S0TIR == OFF){}	// wait
      S0TIR = OFF;
      S0TBUF = 0x78;        // send "x" ASCII
      while(S0TIR == OFF){}
    
      S0TIR = OFF;
      S0TBUF = ConvertQuadToChar(sendstr >> 4); // send character for higher quadlet
    
      while(S0TIR == OFF){}
    
      S0TIR = OFF;
      S0TBUF = ConvertQuadToChar(sendstr); // send character for lower quadlet
      while(S0TIR == OFF){}
      S0TIR = OFF;
      S0TBUF = 0x20;  // send space
      while(S0TIR == OFF){}
    }
    
    
    byte ConvertQuadToChar(byte zeichen)
    {
      // mask higher quadlet
      zeichen &= (byte) 0x0F;
      // if lower quadlet is between 0 and 9, add Offset +0x30
      if ((zeichen >= 0x00) && (zeichen < 0x0A))
      {
        zeichen += 0x30;
      }
      // if lower quadlet is between A and F, add Offset +0x37
      else if (zeichen > 0x09 && zeichen < 0x10)
      {
        zeichen += 0x37;
      }
      return zeichen;
    }
    

Reply
  • here is the code for TransmitHexByte()

    
    typedef unsigned char byte;
    
    void TransmitHexByte(byte sendstr)
    {
      S0TIR = OFF;          // clear transmit
      S0TBUF = 0x30;	// send "0" ASCII
      while(S0TIR == OFF){}	// wait
      S0TIR = OFF;
      S0TBUF = 0x78;        // send "x" ASCII
      while(S0TIR == OFF){}
    
      S0TIR = OFF;
      S0TBUF = ConvertQuadToChar(sendstr >> 4); // send character for higher quadlet
    
      while(S0TIR == OFF){}
    
      S0TIR = OFF;
      S0TBUF = ConvertQuadToChar(sendstr); // send character for lower quadlet
      while(S0TIR == OFF){}
      S0TIR = OFF;
      S0TBUF = 0x20;  // send space
      while(S0TIR == OFF){}
    }
    
    
    byte ConvertQuadToChar(byte zeichen)
    {
      // mask higher quadlet
      zeichen &= (byte) 0x0F;
      // if lower quadlet is between 0 and 9, add Offset +0x30
      if ((zeichen >= 0x00) && (zeichen < 0x0A))
      {
        zeichen += 0x30;
      }
      // if lower quadlet is between A and F, add Offset +0x37
      else if (zeichen > 0x09 && zeichen < 0x10)
      {
        zeichen += 0x37;
      }
      return zeichen;
    }
    

Children
  • I don't use ST but I tried your example on a C167 and don't have a problem.

    Sorry, but looks like you have a problem with some settings somewhere. Here is a complete example using your code (without start167.a66) that works correctly on hyperterminal.

    Data: "0x41 0x42 0x41 0x43"

    #include <reg167.h>
    
    typedef	unsigned char	   byte;  /*  8 bit */
    #define OFF 0
    
    byte ConvertQuadToChar(byte zeichen) {
      // mask higher quadlet
      zeichen &= (byte) 0x0F;
      // if lower quadlet is between 0 and 9, add Offset +0x30
      if ((zeichen >= 0x00) && (zeichen < 0x0A)) {
        zeichen += 0x30;
      }
      // if lower quadlet is between A and F, add Offset +0x37
      else if (zeichen > 0x09 && zeichen < 0x10) {
        zeichen += 0x37;
      }
      return zeichen;
    }
    
    void TransmitHexByte(byte sendstr) {
      S0TIR = OFF;          // clear transmit
      S0TBUF = 0x30;	// send "0" ASCII
      while(S0TIR == OFF){}	// wait
      S0TIR = OFF;
      S0TBUF = 0x78;        // send "x" ASCII
      while(S0TIR == OFF){}
    
      S0TIR = OFF;
      S0TBUF = ConvertQuadToChar(sendstr >> 4); // send character for higher quadlet
    
      while(S0TIR == OFF){}
    
      S0TIR = OFF;
      S0TBUF = ConvertQuadToChar(sendstr); // send character for lower quadlet
      while(S0TIR == OFF){}
      S0TIR = OFF;
      S0TBUF = 0x20;  // send space
      while(S0TIR == OFF){}
    }
    
    void SendData(void) {
       unsigned char a = 0x41;     // A in ASCII
       unsigned char b = 0x42;     // B in ASCII
       unsigned char c = 0x43;     // C in ASCII
    
       TransmitHexByte(a);         // puts out B!
       TransmitHexByte(b);         // again B
       TransmitHexByte(0x41);      // puts out C
       TransmitHexByte(c);         // puts out C
    }
    
    void main(void) {
      P3  |= 0x0400;
      DP3 |= 0x0400;
      DP3 &= 0xF7FF;
      S0TIC = 0x80;
      S0RIC = 0x00;
      S0BG  = 0x40;
      S0CON = 0x8011;
    
      SendData();
      while(1);
    }
    
    

  • Can you run your code in a debugger on the target hardware?

  • Think I've found the cause. I've relocated the NEAR memory area to on chip memory, and suddenly the code works. Might be a timing problem with the external RAM.

    Thanks for the helpful input!

    Regards,
    Soenke