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.

TMS320F2800157: CCS bit left shift

Part Number: TMS320F2800157


Hi,

I was just facing a problem in CCS where in I had to left shift bits by more than 15 places and it just dropped them off completely.

I have attached an image showing the code and the variable values. I need to shift the bits because the ref manual says 

  • Hello,

    I'm assuming the issue is with how the variable is displayed in the Expressions view.

    I will try this out locally with my F2800157 target when I have access to it next week on Tuesday. Please note that Monday is a local holiday.

    Thanks

    ki

  • Hi,

    sorry for my late reply, sat and sun were local holiday for us.

    its not just how variables are displayed in expressions view, when I push the value to the register  its is the same as displayed in expressions view and peripheral doesn't work as intended

    Thanks 

    Manas

  • Thank you for the additional details. I will take a closer look when I return to the office tomorrow.

  • The problem is this expression ...

    (uint32_t)(1 << 31)

    ... does not work as you expect.  The type of the constant value 1 is int.  In the C2000 compiler, an int is 16-bits wide.  In C, if the shift amount is greater than or equal to the width of the left operand, the behavior is undefined.  The C2000 compiler issues a diagnostic similar to ...

    "file.c", line 5: warning: shift count is too large

    ... and changes the expression to 0.  Rewrite it ...

    (1L << 31)
     

    The L suffix to the constant 1 changes the type to long.  The type long is 32-bits wide.  That works as you expect.

    Thanks and regards,

    -George