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.

CCS Version: 5.2.1.00018 converting char to int

Other Parts Discussed in Thread: CODECOMPOSER

Hi All,

This is Mahesh. I have a very basic problem while copy a character to integer. I have written windows side c# application to communicate with ek lm4f120xl board. I am sending 1 to 10 numbers from windows application to UART .

After receiving the number(char) using  ROM_UARTCharGetNonBlocking(UART0_BASE) API. I want to convert this char to integer to use in switch statement. But I am unable to do that.

CodeComposer Studio is giving the following error for the following line

   command = (unsigned char *)cmmd[0];

#515-D a value of type "unsigned char *" cannot be assigned to an entity of type "unsigned long"

CCS is not executing this line. Please help on this how to convert unsigned char to unsigned long

void
UARTIntHandler(void)
{
    unsigned long ulStatus;
    unsigned long  command;
    unsigned char cmmd[1] = {0};

    //
    // Get the interrrupt status.
    //
    ulStatus = ROM_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ulStatus);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART0_BASE))
    {

        cmmd[0] = ROM_UARTCharGetNonBlocking(UART0_BASE);
        command = (unsigned char *)cmmd[0];

        switch(command)
        {
        case 1: command =100;

        }

}

Please help me on this.

Thanks

  • Hello Mahesh,

    Shouldn't statement be

    command = (unsigned long *)cmmd[0];

    if you are converting to integer

    Regards

    Amit

  • Hi Amit,

    Thanks for the quick reply.

    command = (unsigned long *)cmmd[0]; with this i am getting the following error.

    #515-D a value of type "unsigned long *" cannot be assigned to an entity of type "unsigned long"

     

    Thanks,

     

  • First note the signature of the ROM function (Ref: UG-ROM-TM4C129x)

    int32_t ROM_UARTCharGetNonBlocking(uint32_t ui32Base)

    This function returns a 32-bit integer: either -1 if no characters are available in FIFO or the value of the character.


    So you should really not need to do any casting for the switch.  But if you must, you should use this code...

    command = (unsigned long) cmmd[0];

    The reason is your destination (command) is an unsigned long, so you should cast cmmd[0] value to an unsigned long before assigning it to command.  But note that if the value is ever -1, you will get 0xFFFFFFFF as the value.  In this case, you probably do not have to worry about that because of your use of ROM_UARTCharsAvail.


    What might be better is if you had...

    int32_t command

    ...

    command = ROM_UARTCharGetNonBlocking(UART0_BASE);

    cmmd[0] = (unsigned char) command;

    ...

    This way, you do not lose any information for the return of the ROM function.  You never know if you'll ever need that information in the future.

  • Hi quark thanks for the reply,

    I used this way,

    command = ROM_UARTCharGetNonBlocking(UART0_BASE);


    But when i add command as a watch expression then it shows as command    unknown    Error: identifier not found: command    


    while debugging I am unable to find int integer value in this command. Control is not entering to switch statement.

    Thank u.

  • I take it that since you got it to run, the code compiled fine.

    Sometimes, the compiler will optimize out variables - which will make the watch window not able to find some identifiers.  Try turning off all optimization and recompile the code.

    In your switch block, I would recommend you adding a default: case and put a breakpoint there.

    Another idea, try...

    static int32_t cmdSaveForWatch = -42;

    ...

    cmdSaveForWatch = command;

    ...

     

    And put a break point right on the switch() statement.  Take a look at the value of cmdSaveForWatch.

  • While using

    cmmd[0] = ROM_UARTCharGetNonBlocking(UART0_BASE);

    this i am able to see watch expression for cmmd[0]. And able to see the number(char) which i have sent from my windows applications.

     

    Than q.

  • Hi Quark,

    Thanks for the reply.

    When I change optimization level 2 to 0 now I am able to see the watch expression command active.


    Now I am able to see the values. Thanks for the reply. my code working

    than q.