• AVR Freaks

Hot!Unable to read string the UART

Author
Findlay1746
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2019/11/11 03:25:13
  • Location: 0
  • Status: offline
2019/12/09 07:39:06 (permalink)
0

Unable to read string the UART

Hi all,
 
I'm brand new to the microchip forums and this is my first post :) 
 
I'm trying to read a particular string through UART5 and write the EXACT same string through UART6. I've used the MCC to configure all of my pins. I keep getting this particular error "warning: comparison between pointer and integer" on the UART5_Read line. Does anyone have any ideas or has anyone read a string through UART before? Any help and advice is much appreciated! PIC is PIC24FJ256GA406. 
 
void sensor_data()
{
//Sensor Set-up
char message[] = "$DBS,,f,00depth,M,,,F*hh<CR><LF>";

while(1)
{

if (UART5_Read == (message[0] =='$' && message[1] == 'D' && message[2] == 'B' && message[3] == 'S'))
{

UART6_Write(*message);
}
}
}
 
#1

5 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28433
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Unable to read string the UART 2019/12/09 20:18:06 (permalink)
    0
    Findlay1746
    if (UART5_Read == (message[0] =='$' && message[1] == 'D' && message[2] == 'B' && message[3] == 'S'))

    Do you have a variable called "UART5_Read", or are you trying to call a function by that name?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11984
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Unable to read string the UART 2019/12/09 21:59:36 (permalink)
    4 (1)
    You probably meant UART5_Read() where you have UART5_Read, and I'm not sure what you're expecting from  if (UART5_Read() == (message[0] =='$' ... 
     
    What does UART5_Read() return?
     
    UART6_Write(*message) probably isn't what you want either.
     
    And <CR><LF> in a string will not result in a CRLF if that's your expectation.
    #3
    Findlay1746
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2019/11/11 03:25:13
    • Location: 0
    • Status: offline
    Re: Unable to read string the UART 2019/12/11 02:04:52 (permalink)
    0
    UART5_Read() is a function created when setting up the UART within MCC. It returns a byte.
     
    However, I'd like to receive a string, store it, and transmit the exact string through UART6_Write.
     
    Apologise if I'm not explaining myself well, I'm still very new at this. 
    #4
    ric
    Super Member
    • Total Posts : 28433
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Unable to read string the UART 2019/12/11 03:37:37 (permalink)
    5 (1)
    Findlay1746
    UART5_Read() is a function created when setting up the UART within MCC. It returns a byte.

    Except if you forget to put the parenthesis after the name of the function (as you did), all you get is a pointer to the address of the function in memory.
    THAT is what the error message was telling you.
     

    However, I'd like to receive a string, store it, and transmit the exact string through UART6_Write.

    So you need a loop, calling the function (correctly), and saving each return value into successive locations in an array.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    Findlay1746
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2019/11/11 03:25:13
    • Location: 0
    • Status: offline
    Re: Unable to read string the UART 2019/12/11 05:58:09 (permalink)
    0
    Thanks very much Ric! I managed to clear the error as per your suggestion.
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5