SERIN2 Syntax


Closed Thread
Results 1 to 7 of 7

Thread: SERIN2 Syntax

  1. #1
    Join Date
    Apr 2008
    Posts
    3

    Default SERIN2 Syntax

    Hello all,

    I am very new to microcontroller programing so this is probably a simple question.

    I am using an 18F2321 and I want to receive serial data to it using the SERIN2 command. The 18F2321 will receive a number in ASCII format at 1200 baud and I will need to convert it to decimal. I have successfully communicated with a Basic Stamp BS2 using the SERIN command. I just can't figure out why it isn't working in the 18F2321. The code compiles with no errors. My code is below. Thanks for the help.

    DEFINE OSC 8
    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2
    DEFINE CCP2_REG PORTC
    DEFINE CCP2_BIT 1

    Pin15 Con 15
    Setting VAR Word
    MotorState VAR Word
    ValveState VAR Word

    Main:
    SERIN2 Pin15, 17197, 100, Main, [DEC Setting]
    SELECT Case Setting
    CASE Is < 255
    MotorState = Setting
    Case 300
    ValveState = 0
    Case 400
    ValveState = 210
    Case 500
    ValveState = 255
    END SELECT
    HPWM 1, MotorState, 16000
    HPWM 2, ValveState, 8000
    Goto Main

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Filbert View Post
    Pin15 Con 15
    ........................
    SERIN2 Pin15, 17197, 100, Main, [DEC Setting]
    Pin 15 usage looks a bit suspect.
    Try using an actual port value (i.e. porta.5 or whatever).
    And 15 looks to be porta.7, which is OSC2. If you're using an external oscillator, this won't work. Even if you're using the internal oscillator, if it's not configured right, the pin won't work as advertised.
    Last edited by skimask; - 16th April 2008 at 13:53.

  3. #3
    Join Date
    Apr 2008
    Posts
    3

    Default

    That was a fast reply thank you.

    According to the data sheet, pin 15 is PORTC.4 and my handy dandy cheat sheet said the same. I removed the "Pin15 Con 15" line and inserted PORTC.4 in the SERIN2 command line and it still didn't work. I am using the internal oscillator. Could that be the problem?

  4. #4
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Filbert View Post
    According to the data sheet, pin 15 is PORTC.4 and my handy dandy cheat sheet said the same. I removed the "Pin15 Con 15" line and inserted PORTC.4 in the SERIN2 command line and it still didn't work. I am using the internal oscillator. Could that be the problem?
    Pin 15 may be PortC.4 to the PIC...
    Pin 15 isn't PortC.4 to PBP (READ the PBP manual)

    Internal oscillator - yep, sure could be the problem. But generally, 1200 baud works even when the osc is out in the weeds a bit.

    AND...your SERIN2 line is giving you 100ms to send and fill a DEC variable. Can you type that fast?

    Get rid of that motor stuff, plug in an LCD and watch what your inputs are doing, hook up some LEDs, do some troubleshooting. Don't just assume that anything works right.

  5. #5
    Join Date
    Apr 2008
    Posts
    3

    Default

    Thanks again for your help.

    Since it works perfectly with the BS2 and the two languages are similar, I thought it would be an easy transition from one to the other.

  6. #6
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Filbert View Post
    Thanks again for your help.
    Since it works perfectly with the BS2 and the two languages are similar, I thought it would be an easy transition from one to the other.
    I suppose it's all easy...in theory...until you figure out it ain't so easy
    The main thing is the manual. Most, if not all, of your differences are spelled out there in one way or another.

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

    Default

    When your PIC have an internal USART/EUSART... don't mess with DEBUG/DEBUGIN/SERIN/SERIN2... use HSERIN and that's it.


    If you still want to use a specific pin.. use it's PORT name.. not PIN number...it's just unreadable and mix-up everybody for nothing

    Code:
    SERIN2 PORTA.7...........
    SERIN PORTA.7............
    
    or better
    
    MySerialInput VAR PORTA.7
    '
    '
    '
    '
    SERIN MySerialInput..............
    Don't forget PIC have more interesting stuff than those stupid useless Stamps.. you MAY need to disable some feature to a specific pin prior to use it as Digital i/o. Few things like ADCs, comparators can cause some strange behaviours.

    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Last edited by mister_e; - 16th April 2008 at 20:43.
    Steve

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

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Getting SERIN2 to work?
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 20:10
  3. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  4. SERIN2 Command Syntax
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th November 2005, 01:42
  5. Syntax SEROUT2 and SERIN2 commands
    By crocodilebobbie in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th October 2005, 15:35

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