Shop OBEX P1 Docs P2 Docs Learn Events
Rs-232 — Parallax Forums

Rs-232

LightfootLightfoot Posts: 228
edited 2006-09-05 01:00 in General Discussion
I set up a circuit that has a 22000 ohm resistor between the TXD pin and ra.0 of an SX chip. I wrote this program to capture an 8 bit signal from the computer's serial port.

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
PROGRAM Start

tris_b = 0
sdata var byte 

Start:

DO
    SERIN RA.1, N2400, sData              
    rb = sData                             
LOOP




How come the LED's do not light up in accordence to the binary value sent? The transmitter is a computer using visual basic.NET to send the signal.

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Well well, I'm seeing things, three of them.

-Stanley Blystone

Comments

  • BeanBean Posts: 8,129
    edited 2006-09-01 10:55
    You cannot use the internal oscillator for serial communications.
    Change OSC4MHZ to OSCXT1 and use a 4MHz resonator.

    Also your "tris_b·=·0" will never get executed, because execution starts at the label "Start:".

    You can simplify your program by just using "SERIN RA.1, N2400, RB".

    I also recommend using the BORxx option on the DEVICE line. This prevents start-up problems.

    DEVICE          SX28, OSCXT1, TURBO, STACKX, OPTIONX, BOR42 ' Assume +5VDC supply
    FREQ            4_000_000 ' Use a 4MHz resonator
    
     
    PROGRAM Start
    
    Start:
      OUTPUT RB
      DO
        SERIN RA.1, N2400, RB
      LOOP
    END
    
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.


    Post Edited (Bean (Hitt Consulting)) : 9/1/2006 12:17:15 PM GMT
  • LightfootLightfoot Posts: 228
    edited 2006-09-01 16:13
    I have a 75mhz resonator, I can use higher baud rates with that, right?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Well well, I'm seeing things, three of them.

    -Stanley Blystone
  • BeanBean Posts: 8,129
    edited 2006-09-01 17:42
    Sure.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.
    ·
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-09-03 20:59
    RS232 requires you stay within something like 3% of the oscillator frequency, the internal oscillator is rated at +/-7%.
    Just too much drift.

    If you want to use the interanl oscillar, synchronous serial will work in some cases.{shift in, shift out, SPI, I2C}

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Dave HeinDave Hein Posts: 6,347
    edited 2006-09-05 01:00
    As I mentioned in another thread, it is possible to do serial communications with the internal RC oscillator.· The main problem with the internal RC oscillator is that it is difficult to manufacture semiconductor resistors within a tight tolerance.· Therefore, the center frequency of the internal oscillator·can be off by a large value.· Parallax doesn't publish the tolerance on the center frequency, but the FUSE register contains a 3-bit field named IRCTRIM, which can be calibrated at load time by specifying "IRC_CAL IRC_4MHZ" in the source file.· The IRCTRIM field can be set to one of 8 values,·with a step of 3% from one value to the next.· This provides a 21% range.

    In theory, the IRC could be calibrated to within 1.5% of 4 MHz.· I don't know how accurate the calibration procedure is, and I normally specify "IRC_CAL IRC_FAST", which sets the trim bits to all ones for the highest frequency trim.· I then run my own calibration program where I toggle an LED every 10 seconds and measure the frequency using a stop watch.· A second parameter can be used with the FREQ directive to indicate the actual frequency of the clock.· In my case I have an SX chip that runs at 4.48 MHz, so I would use the following directives for this chip:

    IRC_CAL·· IRC_FAST
    FREQ······ 4_000_000 4_480_000

    The other problem with the IRC is thermal drift.· The SX manual says that the IRC has a tolerance of +/- 8% over the thermal operating range.· If I read the manual correctly, the themal operating range is -40 degrees C to 85 degrees C.· This is -40 degrees fahrenheit to 185 degrees fahrenheit.· This is a 225 degree range.· The normal range in a household or office environment would be one-tenth of this, so I would expect the frequency drift to be more like 1% to 2% in a normal setting.

    The bottom line is that serial communications can work with the internal RC oscillator.· I run this way all the time, and I haven't seen any problems.· However, in a less controlled enviroment, or when·tighter tolerances are required a resonator or crystal oscillator should be used.

    Dave
Sign In or Register to comment.