Thread: Uart psoc3

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    9

    Uart psoc3

    Hi,
    I am trying to read some data from UART, and put it in the variable Rxbuffersize and then I am making a comparison between the Received data and the expected data. But what I see on my terminal is not what I send, which is UART_1_PutString("11");
    Do anybody have clue about what is wrong?
    Code:
    #include <project.h>
    char Rxbuffersize[3]; 
    char i = 0;
    uint8 ans = 0; 
    char response[100] = {0};
    char x = 0; 
     
     
    int main()
    {
       UART_1_Start();
       CyGlobalIntEnable
     
     
        if(UART_1_GetRxBufferSize() != 0){   // Returns the number of received bytes remaining in the RX buffer
                    Rxbuffersize[i++] = UART_1_GetChar();  // Get the bytes and put it in the array
                
                     if (strstr(Rxbuffersize, "1011") != NULL)    //compare the two;
                      {                
                      UART_1_PutString("11");                    //print this out;
                      ans = 1;  
                   
                  
    }
        } 
         while(ans == 0); 
    }
    Regards

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    char Rxbuffersize[3];
    ...
    strstr(Rxbuffersize, "1011")

    Well the latter implies that Rxbuffersize needs to be at least 5 characters long.

    My guess, it's a buffer overflow
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2015
    Posts
    9
    I got it to work. though I am having a new Problem. My complier gives me this error: multi- character character constant, when trying to do this
    Code:
     char array[100] = {'32','11','50','10'};

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    The content between single quotes are characters and will be converted to the integer value of the actual coding (mostly ASCII).
    As far as i see, you give directly the integers, so you should not enclose the integers in single quotes.
    Oh, and you forgot the terminator if you want output this character array as string.
    Code:
    char array[100] = {32, 11, 50, 10, 0};
    Other have classes, we are class

  5. #5
    Registered User
    Join Date
    Aug 2015
    Posts
    9
    Ok thanks. What I really want is to send an index message such as
    Code:
      char array[100] = {"1,'0','<EOM>'};
    since //"<EOM>" is not an integer, I can't do that right?

    Regards-

  6. #6
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Code:
    char array[100] = "10<EOM>";
    This set the characters as text.
    So, the '1' is a character with the integer value 49 and the '0' as integer value 48.

    Code:
    char array[100] = {1, 0, '<', 'E', 'O', 'M', '>', 0};
    This set the characters one by one to the values.
    So, the first byte has the value 1, the second has 0 and so on.
    But i think this will not work, because the second value is 0 and this means that the character array ends here.
    Other have classes, we are class

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Uart interrupt triggers after one keystroke
    By munchie146 in forum C Programming
    Replies: 6
    Last Post: 03-30-2014, 05:32 PM
  2. UART Serial Communication
    By VoqionXazr in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-03-2013, 11:50 PM
  3. Getting a string from the UART/COM port
    By thatchergrey in forum C Programming
    Replies: 10
    Last Post: 01-23-2009, 04:18 AM
  4. 16450 UART interupt issue
    By abachler in forum Networking/Device Communication
    Replies: 4
    Last Post: 04-25-2008, 12:50 PM
  5. Bluetooth UART
    By ssharish2005 in forum Tech Board
    Replies: 2
    Last Post: 02-06-2008, 06:31 AM

Tags for this Thread