• AVR Freaks

EUSART PIC18F26K22

Author
cipicips
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2013/06/11 10:40:46
  • Location: 0
  • Status: offline
2019/07/20 05:44:48 (permalink)
0

EUSART PIC18F26K22

Hello,
 
I am working on small project just to send and receive some data over EUSART with PIC18F26k22
Since I am new to all this I have successfully created project in MPLAB X, configure device using MCC (EUSART1 and EUSART2)
and successfully compiled it with XC8.
Since I will use only EUSART2, MCC generated two function EUSART2_Read() and EUSART2_Write()
 
Can someone show me how to use them for this problem:
 
Over terminal bunch of text is sent, for example:
aaaaaa
bbbbb
house:XXX   // XXX represent number in format 000-255
cccccc
 
How to use EUSART2_Read() function just to read string that contains "house:" and convert XXX to a number and store it in variable ?
 
Thank you
#1

2 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23259
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: EUSART PIC18F26K22 2019/07/20 06:38:47 (permalink)
    +1 (1)
    I've never used MCC, but I can fairly confidently guess that "EUSART2_Read() will return one character from the UART.
    No more, no less.
    It's your job to do anything more with those characters after they are received.
    So, what is your definition of "a string" ?
    I'm guessing "a sequence of characters terminated by CRLF"
    So, append the received characters into a buffer (making sure it doesn't overflow) until you receive a CR. You can probably just discard the LF.
     

    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
    katela
    Super Member
    • Total Posts : 1336
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: EUSART PIC18F26K22 2019/07/20 07:01:02 (permalink)
    0
    Make sure you are able to receive first a single correct character, your PIC and your terminal must communicate with the same baud rate.
    This article has an example how to send and receive with USART: https://microchipdeveloper.com/mcu1101:project-12
    As explained above, if more than one characters are to be received,  you can append the received characters into a buffer until you receive a CR, than you can check if that's what you wanted to receive.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5