serin string question


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2004
    Posts
    92

    Default serin string question

    Hi,

    I'm trying to learn how to have serin wait for a string and then output a reply.
    This is actually a continuation of my previous thread, I think I did have it working at one point then changed everything and now I'm lost. I've read the manual and re read it and searched and tried many different ways but I can't seem to get it right. Please point me in the right direction. Please tell me what I'm doing wrong.

    Here is a test routine I'm trying to learn from:


    '12F675
    _CONFIG
    _INTRC
    _OSC
    _NOCLKOUT
    _WDT_ON
    _PWRTE_ON
    _MCLRE_OFF
    _BODEN_ON
    DEFINE OSCCAL_1K 1

    INCLUDE "modedefs.bas"
    TX_Pin VAR GPIO.0 'To DB9 RX pin 2
    RX_Pin VAR GPIO.1 'To DB9 TX pin 3

    TRISIO.0 = 0 'Set GPIO.0 to output.
    TRISIO.1 = 1 'Set GPIO.1 to input

    ANSEL = 0 'disable ADCs
    CMCON = 7 'disable comparator



    MyText VAR BYTE [5]
    tx_pin = 0 'inverted mode idle state

    MyText[0]="H"
    MyText[1]="E"
    MyText[2]="L"
    MyText[3]="L"
    MyText[4]="O"





    Pause 100 'OSC settle time...

    loop:
    SerOut tx_pin,N9600,["Waiting for ",MyText,13,10]
    SerIn rx_pin,N9600,[STR MyText]
    SerOut tx_pin,N9600,["I GOT IT...",10,13]
    GoTo loop


    Thanks for any help

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default TRY This

    Quote Originally Posted by Sam
    Hi,

    I'm trying to learn how to have serin wait for a string and then output a reply.
    This is actually a continuation of my previous thread, I think I did have it working at one point then changed everything and now I'm lost. I've read the manual and re read it and searched and tried many different ways but I can't seem to get it right. Please point me in the right direction. Please tell me what I'm doing wrong.

    Here is a test routine I'm trying to learn from:


    '12F675
    _CONFIG
    _INTRC
    _OSC
    _NOCLKOUT
    _WDT_ON
    _PWRTE_ON
    _MCLRE_OFF
    _BODEN_ON
    DEFINE OSCCAL_1K 1

    INCLUDE "modedefs.bas"
    TX_Pin VAR GPIO.0 'To DB9 RX pin 2
    RX_Pin VAR GPIO.1 'To DB9 TX pin 3

    TRISIO.0 = 0 'Set GPIO.0 to output.
    TRISIO.1 = 1 'Set GPIO.1 to input

    ANSEL = 0 'disable ADCs
    CMCON = 7 'disable comparator



    MyText VAR BYTE [5]
    tx_pin = 0 'inverted mode idle state

    MyText[0]="H"
    MyText[1]="E"
    MyText[2]="L"
    MyText[3]="L"
    MyText[4]="O"





    Pause 100 'OSC settle time...

    loop:
    SerOut tx_pin,N9600,["Waiting for ",MyText,13,10]
    SerIn rx_pin,N9600,[STR MyText]
    SerOut tx_pin,N9600,["I GOT IT...",10,13]
    GoTo loop


    Thanks for any help
    Hi Sam, I tried to compile your code and that failed.
    Looking at the code posted, and really not all that familiar with arrays,
    I think you need to use serin2 as listed below, It compiles anyway.
    Code:
    __CONFIG
    _INTRC
    _OSC
    _NOCLKOUT
    _WDT_ON
    _PWRTE_ON
    _MCLRE_OFF
    _BODEN_ON
    DEFINE OSCCAL_1K 1
    
    INCLUDE "modedefs.bas"
    TX_Pin VAR GPIO.0 'To DB9 RX pin 2
    RX_Pin VAR GPIO.1 'To DB9 TX pin 3
    
    TRISIO.0 = 0 'Set GPIO.0 to output.
    TRISIO.1 = 1 'Set GPIO.1 to input
    
    ANSEL = 0 'disable ADCs
    CMCON = 7 'disable comparator
    
    
    
    MyText VAR BYTE [5]
    tx_pin = 0 'inverted mode idle state
    
    MyText[0]="H"
    MyText[1]="E"
    MyText[2]="L"
    MyText[3]="L"
    MyText[4]="O"
    
    
    
    
    
    Pause 100 'OSC settle time...
    
    loop:
    SerOut2 tx_pin,N9600,["Waiting for ",STR MyText\5,13,10]
    SerIn2  rx_pin,N9600,[STR MyText\5]
    SerOut2 tx_pin,N9600,["I GOT IT...",10,13]
    GoTo loop
    That is about all I can do, let me know if it works
    JS

  3. #3
    Join Date
    Mar 2004
    Posts
    92

    Default

    Hi Joe,

    Thanks for the reply, that does compile ok but it doesn't work,seems to keep sending data in a loop very fast by looking at the rx LED but nothing shows in hyperterminal.

  4. #4
    skimask's Avatar
    skimask Guest

    Default

    Is there a level converter (MAX232 type) between the PIC and the PC?
    If there is, change the N9600's to T9600. If not, your PC might have a problem receiving the 'weak' 5v RS232 coming from the PIC and you might have to use a MAX232 to get the PC to receive it. I know I almost have to use a MAX232 with my laptops and one of my newer desktops. But one of my 'old' desktops will take a 5v RS232 signal without a problem.
    JDG

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

    Default

    Bad config fuse setting, 9600 baud, using internal OSC AND with Serout combination??? no big chance that it's going to work.

    At least fix your config fuse setting, try with a lower baudrate first and use DEBUG.

    Sure it's compile OK probably you're using PM to compile AND those
    Code:
    _CONFIG
    _INTRC
    _OSC
    _NOCLKOUT
    _WDT_ON
    _PWRTE_ON
    _MCLRE_OFF
    _BODEN_ON
    are considered as Label... not much!
    Last edited by mister_e; - 30th November 2006 at 03:36.
    Steve

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

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default mpasm

    Quote Originally Posted by mister_e
    Bad config fuse setting, 9600 baud, using internal OSC AND with Serout combination??? no big chance that it's going to work.

    At least fix your config fuse setting, try with a lower baudrate first and use DEBUG.

    Sure it's compile OK probably you're using PM to compile AND those
    Hello mister_e,
    I compiled with MPASM, and didn't mess with his fuses except to add _ to config.
    I tend to agree good luck getting any serout to work with internal osc, but as you see I missed that! Too busy fighting bad internet connection also not familiar with 12F series, look like PIA to me. Glad you are helping him. MY question is, did I do the changes in the serin2 correctly?
    JS
    Last edited by Archangel; - 30th November 2006 at 05:18.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Hyperterminal

    Quote Originally Posted by Sam
    Hi Joe,

    Thanks for the reply, that does compile ok but it doesn't work,seems to keep sending data in a loop very fast by looking at the rx LED but nothing shows in hyperterminal.
    Hi Sam
    I can send data out from my keyboard using hyperterminal, but to save my butt I cannot receive any using it. Can you configure this with a resonator or a crystal instead of int osc, as mister_e pointed out?
    Quote Originally Posted by mister_e
    no big chance that it's going to work.
    JS

  8. #8
    Join Date
    Mar 2004
    Posts
    92

    Default

    Thanks for the help so far,
    I can send from pc to pic and rx from pic using the code below with the settings I first posted and the pic does reply "got it" when I enter an "f".

    CODE:

    loop:
    SerOut tx_pin,N9600,["waiting for f ",10,13]
    SerIn rx_pin,N9600,["f"]
    SerOut tx_pin,N9600,["got it",13,10]
    GoTo loop


    This works most of the time. But yes, I will change to a external osc and I don't have to use a 12F675, I have some 16F628A's and some F84's.

    I really need to have an example,any example of the correct syntax to recognize and reply to a defined string of char's.

    Thanks again,I'm trying to get my brain around working with serial.

    Sam

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default check this out


  10. #10
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Sam
    Thanks for the help so far,
    I can send from pc to pic and rx from pic using the code below with the settings I first posted and the pic does reply "got it" when I enter an "f".

    CODE:

    loop:
    SerOut tx_pin,N9600,["waiting for f ",10,13]
    SerIn rx_pin,N9600,["f"]
    SerOut tx_pin,N9600,["got it",13,10]
    GoTo loop


    This works most of the time. But yes, I will change to a external osc and I don't have to use a 12F675, I have some 16F628A's and some F84's.

    I really need to have an example,any example of the correct syntax to recognize and reply to a defined string of char's.

    Thanks again,I'm trying to get my brain around working with serial.

    Sam

    If you're using the internal oscillator and it's messing up some of the time, switch to a lower baud rate. That might cure most of the problem. Also, try adjusting your OSC_CAL value. If you don't want to do that, use SEROUT2 instead of SEROUT. With that command, you can 'fine adjust' your baud to compensate for your oscillator being a bit out of whack.
    I forget which-is-which, but I think if you get overrun errors, you're clock might be running fast, framing errors mean the clock is a bit slow (on the PIC that is).

    JDG

  11. #11
    Join Date
    Mar 2004
    Posts
    92

    Default

    Thank you all for the advice you've given me!

    I did switch from intrc to XT ceramic 4mhz and that did it! I've been able to do allot of the things that just wasn't working before changing to XT. I also did start at lower baud rates as advised here and increased them as I made sure things were working correctly.



    Thanks and best regards,
    Sam

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

    Default

    Steve

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

Similar Threads

  1. serin question?
    By sachymo in forum General
    Replies: 5
    Last Post: - 27th July 2008, 10:04
  2. SERIN from a large string
    By earltyso in forum Serial
    Replies: 5
    Last Post: - 2nd May 2008, 22:23
  3. Simple question about Serin..
    By Donat in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th March 2008, 16:26
  4. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  5. 16f872. config ports and serin question.
    By kitcat in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th July 2005, 03:03

Members who have read this thread : 1

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