9 Replies Latest reply on Jan 19, 2017 4:14 PM by J.Pacheco

    Compare strings


      Hi everyone,


      I'm working on a code, where I receive text from the serial terminal, and I would like to compare the text in the serial to know if there's a command there.

      I'm using this article: Using UARTs on Intel® Quark™ Microcontroller D2000 | Intel® Software


      And I think that this code could help about what I want (basically to know if there's a "LED=ON" on the serial):


           if (qm_uart_get_status(QM_UART_0) && QM_UART_RX_BUSY) {

                  /* reads byte from UART_A */

                  if (qm_uart_read(QM_UART_0, &data) == QM_UART_OK) {

                      /* and sends to to UART_B */

                      qm_uart_write(QM_UART_1, data);

                      /* adds line feed in case of carriage return */

                      if (data == '\r') {

                          qm_uart_write(QM_UART_1, '\n');





      So instead of:

           data == '\r'

      I want:

           data == "LED=ON"


      But it doesn't work...

      Also, I was trying with strcmp but it doesn't exist... is there something similar or do I have to include a library for this?

        • 1. Re: Compare strings



          I have the same problem, I can not find the function that allows to compare two string to do an action with the programmer., Basically the same as the previous user, I need the function that matches the strcmp of c.

          • 2. Re: Compare strings

            Hi FelipeDelgado,


            Thanks for your interest in the Intel Quark Microcontrollers Platform.


            Could you provide me the error that displays when you compile your code?


            In the meantime maybe you can try to modify your code: Once you have send the data through UART try to store it in a register then compare this value. You can also try to make it simpler, try to compare first integers then you can move to strings.


            Hope you find this information useful, have a nice day!


            Best Regards,


            • 3. Re: Compare strings

              Hi J.Pacheco, Here is the code i'm using:


              #include "qm_pinmux.h"

              #include "qm_uart.h"

              #include "qm_interrupt.h"

              #include "qm_scss.h"



              #define BIG_NUMBER_RX (50)

              static uint8_t rx_buffer[BIG_NUMBER_RX];



              int main(void) {

                qm_uart_config_t cfg, rd_cfg;

                cfg.baud_divisor = QM_UART_CFG_BAUD_DL_PACK(0, 17, 6);

                cfg.line_control = QM_UART_LC_8N1;

                cfg.hw_fc = false;



                qm_pmux_select(QM_PIN_ID_12, QM_PMUX_FN_2);

                qm_pmux_select(QM_PIN_ID_13, QM_PMUX_FN_2);

                qm_pmux_input_en(QM_PIN_ID_13, true);



                clk_periph_enable(CLK_PERIPH_CLK | CLK_PERIPH_UARTA_REGISTER);

                qm_uart_set_config(QM_UART_0, &cfg);

                qm_uart_get_config(QM_UART_0, &rd_cfg);



                while(1) {

                 while(qm_uart_get_status(QM_UART_0) != QM_UART_IDLE) {

                 qm_uart_read(QM_UART_0, rx_buffer);

                 qm_uart_write(QM_UART_0, rx_buffer[0]);

                 if (qm_uart_read(QM_UART_0, rx_buffer) == QM_UART_OK) {

                 qm_uart_write(QM_UART_0, rx_buffer[0]);

                 if (rx_buffer[0] == '\r') { /* HERE IS WHEN I WANT TO COMPARE THE STRING */






                return 0;



              Instead of comparing the carriage return (\r) I would like to compare a string from the serial.


              Thanks in advance.

              • 4. Re: Compare strings

                Hi FelipeDelgado,


                Does your code work when you compare integers? If it doesn't work the maybe your problem is in your code.


                Also I see that you are not using the UART_B, are you doing this on purpose?


                Best Regards,


                • 5. Re: Compare strings

                  Actually, I changed it and didn't noticed but it works anyways...

                  The thing is that the buffer_rx[0] is just a byte, so I created an array that gathers every byte and then I search in that array the word that I wand to find.


                  int cont = 0;

                  char texto[] = "";

                  char *comando1 = "LED=ON";

                  char *s;


                  while (1) {

                    while (qm_uart_get_status(QM_UART_0) != QM_UART_IDLE) {

                    /*qm_uart_read(QM_UART_0, rx_buffer);

                    qm_uart_write(QM_UART_0, rx_buffer[0]);*/

                    if (qm_uart_read(QM_UART_0, rx_buffer) == QM_UART_OK) {

                    qm_uart_write(QM_UART_0, rx_buffer[0]);

                    texto[cont] = rx_buffer[0];



                    s = strstr(texto, comando1);

                    if (s != NULL) {

                    printf("Found string at index = %d\n", s - texto);

                    } else {

                    printf("x %d\n", cont);






                  • 6. Re: Compare strings


                    For using strcmp function just need to include header "string.h"

                    Good luck

                    • 7. Re: Compare strings

                      Hi FelipeDelgado,



                      Could you please try Lockdog recommendation? Please let us know your results.



                      I will be waiting for your reply, have a nice day!



                      Best Regards,


                      • 8. Re: Compare strings

                        I did it actually, I included the string.h library and it worked, but instead of use the strcmp() function, I used the strstr() function, from the same library, thanks everyone.

                        • 9. Re: Compare strings

                          I'm glad to hear that you solve your issue! If you have any more questions, please don't hesitate to ask.


                          Have a nice day!


                          Best Regards,