Serial Communication Problem


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You're welcome.

    You'll clear then RCREG by reading it 2 times

    TempVar=RCREG
    TempVar=RCREG
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65


    Did you find this post helpful? Yes | No

    Talking Solution!

    Upon having another set of eyes look at my code and using the debugger I'm learning to use slowly with more interest, I forgot to clear the counter and i variables. Effectively it was continuing to loop because those variables still had values assigned. Thank you for your time and help Steve, I do appreciate it.

    To anyone else who may be interested in receiving a serial string, reading it and then doing something based upon a character(s) received, let me know and I'll post some really nice code to play with.

    Thanks again to Joe, Luciano, and Steve. I learned a great deal by all the info and code posted.

  3. #3
    Dalomir's Avatar
    Dalomir Guest


    Did you find this post helpful? Yes | No

    Post Same programming

    I put the schematic in the attachement of this post.

    Its an usart with 2 PIC18F452 linked together by PIN 25 and PIN 26

    One receive a paralelle 4 bits number from a numerical keyboard, light LED at PIN 2, 3, 4, 5, 6, 8, 9 and 10 to show that number and send that number directly to the other PIC RX PIN.

    Thats other PIC then receive that serial number and lights LED in the same way as the other PIC, showing that the number was successfully sent.

    If anyone has a code that would make it work, I would really appreciate.
    Attached Images Attached Images  

  4. #4
    leemin's Avatar
    leemin Guest


    Did you find this post helpful? Yes | No

    Default help

    To anyone else who may be interested in receiving a serial string, reading it and then doing something based upon a character(s) received, let me know and I'll post some really nice code to play with.

    yupe. i need a program to receive a serial string, reading it and then doing something. my string is something like this X-Addr-Mode-Data(30bytes)-Y
    where X stand for SOT and Y stand for EOT. Addr is use to indicate the dedicated address value i want to send data.

    my code is something like below:
    include "modedefs.bas"
    DEFINE SHIFT_PAUSEUS 20
    define OSC 20
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error

    TRISA=%11110000
    TRISB= %11111011
    TRISC.6 = 1
    TRISC.7 = 0

    symbol Addr_Data_In=porta.4
    symbol en=porta.3
    symbol stb=porta.2
    symbol clk=porta.1
    symbol data_out=porta.0

    SPBRG = 32 ' Set baud rate to 9600
    RCSTA = $90 ' Enable serial port and continuous receive
    TXSTA = $24 ' Enable transmit and asynchronous mode
    RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
    TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
    OERR var RCSTA.1 ' Overrun error
    CREN var RCSTA.4 ' Continuous receive
    ADCON1=6

    display: if RCIF then
    i=RCREG
    if i != "X" then discard

    redo: hserin 500,discard,[i]
    if i="Y" then discard
    serialstring[counter]=i
    counter=counter+1
    goto redo

    discard: if i="Y" then success=1
    endif
    if success then
    cren = 0
    if (serialstring[0] <> address_Value) then reset
    if serialstring[1] = $30 then turn_off_led
    serialstring[2]=a29
    serialstring[3]=a28
    serialstring[4]=a27
    serialstring[5]=a26
    serialstring[6]=a25
    serialstring[7]=a24
    serialstring[8]=a23
    serialstring[9]=a22
    serialstring[10]=a21
    serialstring[11]=a20
    serialstring[12]=a19
    serialstring[13]=a18
    serialstring[14]=a17
    serialstring[15]=a16
    serialstring[16]=a15
    serialstring[17]=a14
    serialstring[18]=a13
    serialstring[19]=a12
    serialstring[20]=a11
    serialstring[21]=a10
    serialstring[22]=a9
    serialstring[23]=a8
    serialstring[24]=a7
    serialstring[25]=a6
    serialstring[26]=a5
    serialstring[27]=a4
    serialstring[28]=a3
    serialstring[29]=a2
    serialstring[30]=a1
    serialstring[31]=a0
    endif
    reset: cren=1 ' Enable receiver
    goto display

  5. #5
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    I need to sift through my code and pull out the serial stuff (it's a long code as it stands) and reply to you this evening. What PIC are you using by the way?

    Also, could you describe what you want to do again in more detail? I'm a little confused when you say X stands for SOT and Y for EOT. I'm still a newbie in programming, but I'm sure I can help you with this. So far I gather you want to receive a serial string and read it. You then want the PIC to do something by way of transmitting another serial string and placing the characters in a specific location along that string? Which is no problem I just want to make sure I'm giving you what you want.

    -Tony

  6. #6
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65


    Did you find this post helpful? Yes | No

    Default Sample Code

    Okay, I brought this home, tweaked it with a different programmer and when I try to compile it, it says it is unable to "fit variables". I'm think this will work as it stands, but you may find some errors on my part.

    In any event, this waits for serial data and once received looks at the first two characters to be sure the string is what you expect it to be. You can take this out if your serial input changes every time (the first two and last two characters in a string). If you ever expect more than 40 bytes on a single serial string be sure to change that in the variable definitions.

    The branch command really comes in handy for looking at a single character at a specific location in the string and doing different things instead of using the if command.

    Take a look at this and see if it helps. Feel free to ask questions.

    -Tony
    Attached Files Attached Files
    Last edited by elec_mech; - 26th August 2005 at 01:13. Reason: Forgot attachment

  7. #7
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65


    Did you find this post helpful? Yes | No

    Default P.s.

    ASII Table - All important to serial comms - Check this out:
    http://www.lookuptables.com/

  8. #8
    leemin's Avatar
    leemin Guest


    Did you find this post helpful? Yes | No

    Exclamation

    ok. thanks for you all previous help. i can work with the USART interrupt with my code already but now i encounter with a new problem.
    im using 16f877a.
    i need to receive a string of command from computer. then execute some function after received a valid command. now i need to execute the blinking effect by toggling the enable pin to let the led on and off continuosly untill another set string of command come in and either stop blinking or continue blinking.
    but now i found out that the blinking sub-routine is a dead loop. when i continuosly execute the blink function and a new string command come in from computer my firmware will hang there.
    any solution for this?
    i need you all suggestion.
    thanks

Similar Threads

  1. Replies: 18
    Last Post: - 4th July 2017, 14:26
  2. serial communication problem
    By kindaichi in forum Serial
    Replies: 13
    Last Post: - 11th March 2010, 16:37
  3. Replies: 5
    Last Post: - 20th March 2006, 01:34
  4. Problem in Serial Communication
    By uuq1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th June 2005, 07:17
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts