This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trouble passing 32-bit parameter

Hi,

I am experiencing trouble passing a 32-bit variable to a subroutine. I developing on the MSP43F5437A using CCS v4.2.5
Here's a snippet of the code:

void mainChargingRoutine(void)
{

    static uint32_t firstBattVal;

    ......

    analysisComplete = chargeRateAnalysis(firstBattVal, chargingMins, chargingTimer);

uint16_t chargeRateAnalysis(uint32_t begBattVal, uint16_t chrgMins, int16_t chrgTimer)
{

    //do stuff


What is happening is that when the function "mainChargingRoutine" calls "chargeRateAnalysis", it passes the 32-bit local variable called "firstBattVal." Inside the "chargeRateAnalysis" function its value should be available in the begBattVal, which is also declared as an unsigned 32-bit value.
However, the problem is that when I use the debugger to check the values of these variables, I see that as soon as the "chargeRateAnalysis" function is called, the value for begBattVal is being truncated to a 16 bit version of "firstBattVal."
Since it is declared as an unsigned 32-bitt variable in all the relavent locations, why would it be truncated like that?

Let me know if I can provide any more information to help solve this question.

Thanks!

  • Is the prototype for chargeRateAnalysis visible before function mainChargingRoutine? If not, the compiler will assign a default prototype to the function for the purpose of the call. You can detect this problem by adding -pdr.  If that is the problem, either add a prototype for chargeRateAnalysis before mainChargingRoutine or move the definition above mainChargingRoutine.

  • Thanks for the input. I moved the prototypes for these functions so that they are local functions and so that the chargeRateAnalysis prototype comes before the mainChargingRoutine prototype:

    // Local functions
    void initGladiatorInfo(gladiatorInfo_t * );
    void initPortPins(void);
    uint16_t chargeRateAnalysis(uint16_t chrgMins, int16_t chrgTimer, uint32_t begBattVal);
    void mainChargingRoutine(void);

    This, however, didn't seem to make a difference.  When I step through mainChargingRoutine to where chargeRateAnalysis is called, I still see the truncation occur.
    I'm going to try different ways of passing the variables.  If you have any more thoughts/insight, it would be appreciated.

    Thanks! 

  • Also, I am using the Large Memory Model, if you think that may be causing any issues.

  • I cannot reproduce this problem.

    How do you know that the code is incorrect?  If you are only looking at the CCS variable view, you should also check that the execution of the function is also incorrect.  It may be the case that the value is actually correct, but CCS is for some reason unable to display the correct value.

    What version of the compiler are you using?  (It is not the same as the CCS version).

    What compiler options are you using besides large model?

  • Ahh. Good point.  I checked the results of the calculations and it appears that are performed correctly with the necessary 32-bit values.  For whatever reason, the variable window was displaying only their 16-bit truncated values.
    I suppose I trusted too much in CCS.  

    Thanks for your help!