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/LAUNCHXL-F28379D: SCI Reading Issues

Part Number: LAUNCHXL-F28379D

Tool/software: Code Composer Studio

Good afternoon,

It took a lot of work but I was finally able to communicate between my PC with a serial adaptor and the dev board. I am now trying to take in the data that is being sent through TR on the PC to the RX on the board. I have it set up to work with interrupts and it is firing. I am having some weird behavior in that the code will either read in a digit number or a char* but not both. I am going to need to be able to read in both because strings and numbers will be used to configure the device. 

Example code is below that shows how I am trying to sort the incoming data. This is in the RX ISR

 receivedChar = SCI_readCharBlockingFIFO(SCIB_BASE);

    if (receivedChar != NULL)

    {
        // TODO make it check for char or int and convert accordingly and store it

        // if its is a digit

        if (isdigit(receivedChar) || receivedChar == ".")

        {
            digitArray[count] = receivedChar - '0';
        }

        // if its is a character

        else if (isalpha(receivedChar) || receivedChar == '-')
        {
            charArray[count] = receivedChar;
        }

Like I said if I put just characters it reads fine or digits but not if the file is sending both. It is also very difficult to debug because I am running the transmission code from python using pyserial and receiving it with ccs on the dev board. I also tried adding a delay between each send of data thinking it needed it. 

  • I think I have figured out an issue I am having. I think that when it gets into the RX interrupt it just sits and waits for stuff indefinitely. How would I send something from my python code that would make it stop waiting for incoming data? Or is there something in the ccs code that I can have it stop waiting after a short wait? I can't really use a SCI_readCharArray because the size of the things I will be sending will be changing so I can't give it the correct size. So I am running SCI_readCharBlockingFIFO in a for loop and putting the stuff in an array to sort through after. But it just hangs waiting for more stuff on the RX line. 

  • hi ,

    Didn't the basic example of sci echoback not enable using both chars and digits ?

    To make it stop waiting for incoming data, Is there any specific pattern that could be setup like a 3 char pattern which can be received and checked like a magic packet?

    Regards.

  • I was able to get it working by changing how I was doing things. I took everything into a rec array and sorted it all after. It was not working when attempting to sort them as they came in. By sending data from the python application and adding some delays between sends I was able to get it to read in a length in characters that is used to initialize the SCI_readCharArray size to be the correct size and bring in all the data. Now I need to dynamically create some arrays to store the various settings that will be sent from the python application.

  • hi ,

    Ok. Sounds good.

    Regards.

  • I am running into issue now that I am trying to send multiple things. 

    The first send I am sending from the python application is the number of characters which will tell me how big to make the SCI_reacCharArray(size). I would then like to send an acknowledge to the application to let it know it can then send the number of words which will tell me how many arrays I need to make to hold the data coming across and acknowledge this as well. Then finally send all of the data with the delimiters to the hold array. Then split that data up into the digits and chars and throw them into new arrays when it sees the delimiter. 

    I am having issue with sending multiple times from the python application and being able to read it correctly on dev board. That is why I was going to try and implement a send and ack back an forth to have better control of what was going on. Are there any examples I might be able to look at where this has been done? I am also wondering if every time I do a send from my python application if the RX interrupt is fired? If that is the case I can keep a count that of how many times its fired and modify my code to work with that instead. It has been incredibly difficult to debug the problems in the code due to it being run in seperate instances and when one will hit a break point and pause the other keeps going cause problems. 

  • Another odd occurrence when I run the debugger it does not seem the for loops are working correctly. The index int is not increasing with each pass. It is making it harder to debug the code correctly. 

  • I cannot get this SCI to work the way I want it to. If I give it the exact size the SCI_readCharArray will work. However, my settings file that I am sending across can have a variable size. So it has been very difficult for me to get it working. If I give it the exact size it works fine but I am unable to do that. Is there a way to break out of it reading input? I have tried to use special characters to break it out like a magic packet suggested above to no avail. I am getting incredibly frustrated with this. I have been beating my head against it for days. 

    I have also tried to set it up to work on one character at a time and have had no success there either. Any help would be greatly appreciated I have to get this working very soon. I will keep messing with it and keep updating. 

    When I try and read character by character the buffer keeps getting back 2 no matter what I send to it with SCI_getRxFIFOStatus. Is the FIFO buffer only able to hold two chars? If it is how would I reset it so that I can send more stuff. I think the way to get this working is to do it character by character but I am having trouble getting it to work correctly. 

  • I have been able to get the problem above resolved by simply padding all the settings coming in with junk that will be removed later so I could get the correct size each time. 

    I have now taken all of the code we have written and put it together and now the SCI RX interrupt keeps firing when I am not sending anything from my application. There are a lot of interrupts being used in the device we have two timer interrupts and some GPIO triggered interrupts as well as the TX and RX ones. When we run the code it is behaving very bizarrely and will change the code that the debug is running on. It will change from main() to another portion of the code and it gets into the SCI RX interrupt and forever waits to receive stuff from the FIFO buffer that has nothing in it because I have not sent anything to it. 

    Has anyone ever experienced anything like this? Is there a good place for me to look to see how the SCI interrupt works?

  • hi,

    No the device has a 16-level transmit/receive FIFO. 

    The SCI chapter in the TRM would give more details on FIFO and its usages.

    Specific details are in section 19.13.1 SCI FIFO Description

    http://www.ti.com/lit/ug/spruhm8h/spruhm8h.pdf

    The FIFO levels can be updated in the RXFFIL bits of SCIFFRX register. Similar register is available for TX too.

     

    Regards.

  • hi,

    Good to hear you were able to make progress.

    The FIFO levels can be used to make sure the interrupt is received only when some valid character is received.

    The TRM is the best place to look for details on the SCI interrupts .

    But details on the interrupts and PIE can be seen in the Interrupts chapter.

    The movement across interrupts could have to do with the priority of the interrupt triggered..

    Regards.

  • We want the SCI interrupt to take priority over all of the rest of them. So when it fires we disable the other and renable them as we are leaving the ISR. This is behaving correctly but for some reason it is firing the ISR when no signal is being sent to the device. Then since nothing was sent it waits while(true) for something to happen that won't and our application dies. 

    This is something we would like to do when first starting our device to initialize it. Is there any way to make the program go back to the start of main after it is finished with the ISR? I looked into goto command but that only works within functions and not across the ISR and main. I also tried to do with an asm() instruction but that did not seem to work as intended. 

    Thanks for the other infomation I will look into TRM. We are almost done with the project and are working non stop to have it fully functional.

  • I am trying to make some changes to my code and noticed I did not disable loopback. So I disabled loopback and my code stopped working when I called 

    SCI_readCharArray it hangs and when I examine the stuff in the array in the 3rd part is 255 and seems to hang there. If I comment out the section that disables the loopback it works as intended. I am not enabling the loopback in my code but when I disable it the code breaks. What might be the cause of this?

    I reloaded the code and ran it again and now it works. 

    Is there anyway to make the SCI_readCharArray to cancel after a timeout of some time? When all of the code is put together it appears to hang on the reading it in and waits for characters that are not coming. If I can add a timout that might correct the problem.

  • hi,

    To check cause of ISR being fired you could look at the PIE FLG registers to check the cause.

    This could also be due to system level interrupts too.

    Why would you want to jump to start of main from ISR ?
    Wouldn't it hamper your stack push pop settings and contents?

    Instead it would be better to use some flag in the ISR and check it in the main to do any further processing.

    Regards.

  • hi,

    When you enable the loopback it will make sure all contents from TX pin and put into RX pin without going out on the line.

    The loopback isn't applicable in your case.

    The device rx data and then echos it back . But when you turn on the loopback , It makes the data send from device post echo back to the device too.

    The only issue i see is if the RX interrupt was enabled it would get triggered again since it received the content twice once from terminal and once from the loopback.

    "I am not enabling the loopback in my code but when I disable it the code breaks. " Are you sure this is not being tampered when modifying other init configurations.

    To get SCI_readCharArray to cancel after a timeout of some time -> use counters or cputimer if time based or flags set on receive of particular packets.

    Regards.

  • I have been able to get it working completely. I did not have to change the interrupt priority it worked as I wanted it to. Just had to make some minor modifications to the sysclk because there is no external oscillator on the board we produced. Now it works and is taking in all the settings I send to the RX. Now I need to do it in reverse and take the settings I stored in my struct into an array and send back to the python application. I am now having some difficulty getting some of the struct numbers into the array. Because it sends and receives bytes. 

    The sprintf is used to store the floating point number into the char array to hold the digits. I then want to go through char array and put each of those into the send array so I can use the sci TX functions. When I am debugging the code it will work and jump over until I get to the sprintf it then seems to hang when I try to jump over. I have used sprintf in other parts of the code and it worked as intended so I am confused here.

            
            sprintf(digit_char_array, "%.2f", settings_ptr->max_mva);
            length = strlen(digit_char_array);
            for (i = 0; i < length; i++)
            {
                send_array[sa_i] = digit_char_array[ptr_i];
                ptr_i++;
                sa_i++;
            }
            ptr_i = 0;
            memset(digit_char_array, 0, 40);

    I am also adding the characters to the array. The thing that is off about this is that every element puts the character and then a zero after it. So for example the "Test" become 'T' , 0, 'e', 0, 's', 0, 't', 0

    I have a send array index sa_i and a settings struct pointer index ptr_i  and I increment them both and they line up correctly. It is putting the chars into the array but leaving the blank space between and it's confusing me.

            length = strlen(settings_ptr->name);
            for (i = 0; i < length; i++)
            {
                send_array[sa_i] = settings_ptr->name[ptr_i];
                ptr_i++;
                sa_i++;
            }
            ptr_i = 0;
            length = 0;

  • After diving deeper into the adding of the 0 to each element it appears that the character is going into the first byte and the 0 is going into the second byte. I can try and bitmask the two together to remove the 0. However, I was wondering if this is how they are normally sent from the SCI_writeCharArray?  

    I am still encountering the problem with the sprintf. I don't know why it's not working I have used it in other places in my code the same way and it worked. 

  • hi,

    Were you able to make progress?

    Regards.