4 Replies Latest reply on Jul 18, 2018 12:42 PM by user_1864790

    Bug in return from procedure PSoC5

    user_1864790

      It seems that Cypress Tech Support is no more. Oh dear!

      Here is my problem: I have small procedure that converts a binary number to an ASCII string, and returns the number of characters in that string. It includes leading zero blanking if desired (cFixedDigitCount=0) or a fixed length message with leading zeros. It looks like this.

       

      uint8 cBinaryToAscii (uint16 iSource, uint8 sConversion[], uint8 cFixedDigitCount)

      {//return the number of characters in the string

      //cFixedDigitCount to allow for leading zero  

          uint8 cPoint,cI;

          uint16 iRemainder;

          cPoint=0;

          while (iSource!=0)

          {

              iRemainder=iSource%10;

              sConversion[cPoint]=(uint8)(iRemainder) | 0x30;

              cPoint++;

              iSource/=10;

          }

          if (cFixedDigitCount)

          {//only if non-zero, else leading zero blnking

              if (cPoint<(cFixedDigitCount))

              {

                  for (cI=0;cI<(cFixedDigitCount-cPoint);cI++)

                  {

                      sConversion[cPoint]='0';

                      cPoint++;

                  }

              }

          }

          return cPoint;

      }

       

      Up till now it seems to have worked. The program has grown a lot since I tested it out, but I have not seen problems.

       

      I have just used it in a new module as follows

      cJ=cBinaryToAscii(iRetrievedParameter,cASCIIResult,0);

      cJ is a local uint8, cASCIIResult is a 5 uint8 array

       

      When I step through the cBinaryToASCII, or run through it with a breakpoint, the number appearing for cPoint is correct, 4 in this specific case. But in the calling module cJ has a value of 0x1A. If I change cJ from a local variable to a global one, it works correctly.

       

      Any idea what I am doing wrong, or is there a bug in the compiler?

      Compiler details

      PSoC Creator 4.2 (4.2.0.641)