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/TM4C123GH6PM: Problem about coding

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello, my code is behaving strangely. Currently I'm having several lines of code (which is "return 0") in my main function. They will never be executed under normal condition. And they are even not in the main loop (the while(1) one). But if I delete them, my while(1) loop will fail to function.

One of those "return 0" is shown as below:

BTW, my main loop is a ping-pong buffer code to write data into SD card. 

I'm really confused. I guess maybe the code composer is not working properly? 

  • Han Hao said:
    I guess maybe the code composer is not working properly? 

    Unlikely but you haven't given us enough to even guess what might be happening.

    Robert

  • Hi Robert,

    Sorry if you find the information is too little. I was trying to simplify the situation. Here is more about my issue:
    Upon power up, my code will send out some SPI command to inialize a slave device (as shown in the picture, the "headstage_init()" function is one of them). Then the return value is checked (if the slave device is inialized successfully, it will return 1) to make sure the initialization is properly done. If I got a return value of 0, which means something about the hardware went wrong, the main function will return 0 and stop.
    Now the issue is, if I have the "return 0" in my code, my main loop, which is far behind this inialization code, will fail. (Sorry I just realized I made a mistake before, that is, I must delete this "return 0" to make sure my code works, but not leave it there.)

    And I'm pretty sure this "return 0" will not be executed, because the UART sent back to my PC shows that "Headstage successfully inialized ".

    Again, my main loop is a ping-pong buffer code to write data into SD card. (A timer interrupt will keep sending data to one of the two buffers, if the buffer is full, the main loop will write it into sd card, while the other buffer is used to store data.)

    If I have that "return 0" in my code, by looking at the UART strings sent back to my PC, I know that all the inialization is done, and the code will run till the main loop ("return 0" is not executed). But then it just get stuck, and the ping-pong buffer stops working.

    Some similar situation would be, if I add something like "GPIOPinWrite()" to the code (as shown in the picture above), the code will also fail. I don't think this single line of code would have effect on my main loop later. (And I've made sure that the written pin is not used by SD card.) That's why I guess my CCS have something wrong, otherwise I cannot understand why this is happening.

    Thanks a lot!
  • From your description, I'd strongly suspect you have a problem with your while loop.

    The first rule when suspecting the compiler has a bug is "You're wrong"

    Robert

    BTW, if you can, get a copy of PC-Lint. Use it as part of your compile process (you must pass lint before compile) and turn up the error detection as far as you can stand.

  • Thank you Robert, I'll look into my while loop more carefully and use PC-Lint.