Getting SERIN2 to work?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19

    Default Getting SERIN2 to work?

    Hello.

    This is my first post to this forum. I need help, please.

    I have been programming PICs for a few months successfully (turn things on and off, shift out/in, display on LCD, etc). I have a project where I need to convert working BS2 SERIN code to PIC code, so I am using the SERIN2 command for the PIC.
    BS2 code is SERIN 16, 16572, [DEC MAX1A]
    I know this BS2 code is for 4800 baud, but I want to use 2400 for my PIC project (mode = 16780)

    After MUCH trial (and error) over many days, I have NEVER been able to get SERIN2 to accept a string of numbers and place them into a WORD variable. I have tried all manner of combinations to try to get my code to receive a 5 (or fewer) ASCII numeric character string sent from my PC.

    Ref: PIC16F876A at 20 Mhz

    My PC waits for a "0" from the PIC, then sends the string of numbers.

    MAX1A VAR WORD

    mainloop:
    SEROUT2 TXPin, 16780, ["0"]
    SERIN2 RXPin, 16780, [DEC MAX1A]
    GOSUB Display
    ... and do other things then go back around for more input ...
    GOTO mainloop

    This PIC can receive and send back BYTES to the PC (one at a time) using a BYTE sized variable in the PIC just fine, so I know the baud/word/bit/parity are set correctly.

    I know my PC is sending the right characters because I use Serial Monitor software on the PC to watch it.
    I see the "0" coming to the PC, then PC sends the string (like "14425" for example), but the PIC never advances beyond the SERIN2 statement. It just hangs there. Note that 14425 is still not larger than a 16-bit integer so it should fit into a WORD sized variable in the PIC. Note also that 14425 should also fit into a 14 bit word.

    I have used different variable names, and even array variables without success. Still hangs.

    I have even used WAIT (","), and had the PC send the "," prior to the string, but still nothing.

    I have used a timeout and label sequence within SERIN2, but it just times out without "seeing" anything from the PC. I have added delays between statements without success. I've tried delays on the PC end., still no luck.
    I have made the string followed by a CR,LF characters - still nothing.

    There MUST be something FUNDAMENTAL that I do not understand about SERIN2 and WORD sized variables! What do I need to do so that SERIN2 fills the WORD sized variable and does not hang?

    PLEASE HELP ME. My frustration level is very high.

    Thanks in advance for all suggestions.

    Bob Pigford

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


    Did you find this post helpful? Yes | No

    Default

    Hi Bob,
    Welcome to the forum !<br>
    Are you sure your PC is sending actual numbers and not ASCII characters ?
    I use REAL Term and using it I can select either format. Get it here for free:
    http://sourceforge.net/projects/realterm

    EDIT: Since I have never bothered to use SERIN2, what I am going to say is purely conjecture on my part.
    Serin2 receives 8 bits and an optional parity bit, word is 16 bits so try:
    Code:
    SERIN2 RXPin, 16780, [DEC MAX1A.highbyte,MAX1A.LowByte]
    I don't know if it will work, but PBP doesn't choke on it.
    Last edited by Archangel; - 13th March 2009 at 23:23.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Default SERIN2 still hangs trying to fill a WORD variable

    Thanks Joe S.

    It will compile but it hangs up like the other efforts.
    I have considered a "resistor problem" and but only 1k receive and 1k transmit resistors work at all (the byte in, byte out test). That also agrees with the manual's recommendation.

    I cannot remember being this frustrated in at least 20 years!

    Why does it work so easily in a BS2 but seems impossible in a PIC?

    Thank you again for your suggestion. I will need all the help I can get.
    Bob

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobPigford View Post
    Thanks Joe S.

    It will compile but it hangs up like the other efforts.
    I have considered a "resistor problem" and but only 1k receive and 1k transmit resistors work at all (the byte in, byte out test). That also agrees with the manual's recommendation.

    I cannot remember being this frustrated in at least 20 years!

    Why does it work so easily in a BS2 but seems impossible in a PIC?

    Thank you again for your suggestion. I will need all the help I can get.
    Bob
    I always use a max232 between PC and PIC. You might try changing your mode to OPEN INVERTED instead of DRIVEN INVERTED mode 49548.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You may want to show your code, the whole code, nothing but the code....well, maybe the configs too.

    Point is, we do not know what pins you are using or the setup.

    You say you are sure the PC is sending because of some program on the PC, have you checked the wires from PC to PIC? Maybe there is a blockage???

    Give something like this a try
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    OPPS. I hit submit before I was finished.

    Change the code to fit your needs.
    Code:
    SERIN2 PORTB.5,24972,[WAIT("A"),STR NUMS\16]	'7, Even
    
    X1 = (NUMS[1]-"0")
    
    X2 = (NUMS[3]-"0")
    
    X3 = (NUMS[5]-"0")
    
    X4 = (NUMS[7]-"0")
    
    X5 = (NUMS[9]-"0")
    
    X6 = (NUMS[11]-"0")
    
    X7 = (NUMS[13]-"0")
    
    X8 = (NUMS[15]-"0")
    LCDOUT $FE,1,DEC X1,DEC X2,DEC X3,DEC X4,DEC X5,DEC X6,DEC X7,DEC X8
    The above brings the ASC|| data into an array then then does a little parsing.
    Dave
    Always wear safety glasses while programming.

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. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  3. with 40 MHZ osc serin2 not work
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th August 2006, 22:56
  4. SEROUT2 and SERIN2 commands
    By bangunprayogi in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th August 2005, 09:03
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

Members who have read this thread : 3

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