SERIN2 Question


Closed Thread
Results 1 to 8 of 8

Thread: SERIN2 Question

Hybrid View

  1. #1
    eoasap's Avatar
    eoasap Guest

    Default SERIN2 Question

    I am using a 14.7456 MHz crystal, defined as 16 in PBP and am having problems using SERIN2 command. could this be due to the difference in crystal?

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    We will need a couple of pieces of information.

    What baud rate are you using? What is not working about it?

    Yes the define being different than the actual crystal speed could play a large part.
    Last edited by DynamoBen; - 30th December 2005 at 04:28.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Because your frequency isn't 16Mhz, your baud rate will be not what you expect. Look at the data sheet for your chip. You will have to use the formula provided in the datasheet to set the SPBRG register yourself. Don't forget to add 16384 to the number if you are using INVERTED mode.
    Charles Linquist

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I apologize - I am so used to HARDWARE serial ports that I forgot that SPBRG has nothing to do with SERIN2/SEROUT2.

    You will have to go to the PBP manual and choose the right value for your new XTAL frequency. Page 137 of the PBP manual states that you should use the value (1000000/baud)-20 as the value to use for MODE.


    Since your Xtal is lower in frequency than your DEFINE, your baud rate will be too low. You will have to configure the MODE to give you a higher baud rate than nominal. For example: If you are running 9600 baud, the formula would indicate that MODE should be 84, but since you are actually running at 14.7456Mhz, which is 92.2% of 16, then you should set your baud rate to be 1/92.2% = 1.0844 X 9600 Baud = 10410 baud. Instead of setting the MODE to 84, you would set it to 76. The actual baud rate will be 9600.
    Charles Linquist

  5. #5
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    Charles, that did the trick! i found the formula, but i mistakenly did it the other way and got 93 instead of 74. i think that fixed the problem. thank you!
    still not sure if it's right, but i'm getting ascii numbers back like i believe i'm supposed to. Also each time through the program i get the same values returned, which also should happen. (more in post below this)
    Last edited by eoasap; - 30th December 2005 at 14:13.

  6. #6
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    DynamoBen, rate is 9600 baud. i'm communication (or trying to) with a FAT16 chip that for now, is supposed to simply reset and send back a string. this chip comes pre-programmed and transmits at 9600 baud.

    here is the relevent code i have:

    'PIC18F8722
    DEFINE OSC 16 'when actually its 14.7456mhz
    ASM
    __CONFIG _CONFIG1H, _OSC_HS_1H
    ENDASM

    gosub alfat_reset
    .... main code ....


    ALFAT_RESET:
    LCDOUT CMD, CLR 'Clear LCD Screen
    SEROUT2 ALFAT_RX,76, ["RS OK",13]
    ; SEND ALFAT RESET STRING
    READ2:
    LCDOUT CMD, CLR
    SERIN2 ALFAT_TX , 76, [BUFCHAR]
    LCDOUT BUFCHAR
    PAUSE 1000

    RETURN

  7. #7
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    after the first initial send "RS OK" and receive "BL" (both work fine), it seems like any command after that the first character is dropped and prints the 2nd char. I've tried speeding up the baud rate, but that doesn't work. any ideas ?

  8. #8
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    the baud rate is accurate according to the formula also (assuming the xtal is reported speed, haven't been able to check on a scope). could this be solved by adding a pullup resistor on the transmit lines ?

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. Yet another SERIN2 question
    By ozarkshermit in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 31st March 2009, 20:11
  4. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  5. serin2 question
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd July 2006, 21:28

Members who have read this thread : 0

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