16F628 Hardware USART problem


Closed Thread
Results 1 to 8 of 8
  1. #1
    atomski's Avatar
    atomski Guest

    Question 16F628 Hardware USART problem

    Hello everyone,

    I have written this little piece of code for
    testing the HW USART on 16F628 @ 4MHz,
    because I've expirienced strange
    behaviour on 2 of my 628's. I would
    appreciate if someone could take a look
    and tell me if something is wrong with my
    code... Thanks!

    PS When I power up the PIC the first
    message doesn't come out in HyperTerm,
    when I type on the keybd, HSERIN
    doesn't seem to work and all I get is
    "Type anything to test HW USART..."
    every 2 secs.

    --
    Sincerest regards,

    YZ7REA Vladimir M Skrbic
    4N7ATV Repeater Administrator
    YU7GHZ Radio Club President
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Are you using an RS232 driver loke MAX232 ?
    the HW USART output is inverted as it is designed to work with an RS232 driver.
    unfortunately you can't run the HW USART in true mode.

  3. #3
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    Yes, I am using the inverter hw. As I
    mentioned in my previous post I do get
    data comming out from the pic, however
    nothing is received when I type on the
    keyboard. And the first line comming out
    from the pic is not sent/seen in HyperTerm
    (i.e. I don't see the "greeting" msg)

    PS I'm using 16F628/04

    Vlad YZ7REA

  4. #4
    Join Date
    Oct 2003
    Location
    Cyprus
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Hello Atomski,
    try to use some delays
    before your greeting, put the line PAUSE 500
    and between the following line as indicated.
    HSERIN 2000, No_Data, [Ser_data]
    PAUSE 500
    IF Ser_Data <> 0 THEN

    Personally I had used the following and worked fine (for higher baud)

    INCLUDE "modedefs.bas"

    ' ******* Definitions *******
    ' ------------------------------

    DEFINE OSC 16 ' Define clock Oscillator Frequency at 16Mhz
    DEFINE HSER_RCSTA 90H ' Enable Hardware USART receive
    DEFINE HSER_TXSTA 24H ' Set Hardware USART parameters
    DEFINE HSER_BAUD 9600 ' Set baud rate to 9600
    define HSER_CLROERR 1
    CMCON=%00000111 ' Make PortA digital

    ' ****** Initialise PORTs ******
    '----------------------------------

    TRISA = %11110000 ' Set PORTA status (Low byte=Output, for LEDs)
    TRISB = %11100010 ' Set PORTB status
    PORTA = %00000000 ' Initial state of PORT A
    PORTB = %00000001 ' Initial state of PORT B


    This might help ... I hope.

  5. #5
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    I'll give it a try. However, I did try putting
    PAUSE 5000 in front of the first HSEROUT
    command, but no dice. I could try with
    PAUSE 500 between HSERIN and IF/THEN
    statements, though. I would appreciate
    if someone could run my code on their
    hardware and tell me if it worked...
    Thanks in advance.

    Vlad YZ7REA

  6. #6
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Unhappy

    Hi I've tried what you suggested, but
    nothing signifficant happened. I did add
    a label called "Init" at the beginning of
    my code right after DEFINE(s) and put the
    PAUSE 500, HSEROUT [...], PAUSE 5000
    statements there. And voila the welcome
    message appeared in HyperTeminal. Why,
    I'm not sure but that's what happened...
    HSERIN is still not getting anything from
    the comm port, though. Oh, another thing,
    I added some extra lines in order to
    troubleshoot the code and a wierd thing
    happened. The led kept blinking at the
    steady rate of 1s no matter if I typed or
    not. Take a look at the code, please. If
    someone has a suggestion on what else
    I could try I'm all ears

    --
    Sincerest regards,

    YZ7REA Vladimir M Skrbic
    4N7ATV Repeater Administrator
    YU7GHZ Radio Club President
    Attached Files Attached Files

  7. #7
    Join Date
    Oct 2003
    Location
    Cyprus
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Hello again atomski,

    I think that the line

    IF Ser_Data <> 0 THEN

    is not necessary. Try to remark it and run the code again.

  8. #8
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    Hey everyone,

    Problem solved! HSEROUT and HSERIN
    now work flawlesly. The problem was
    the rs232 <> TTL converter. I used a
    factory made converter I got with one
    of my digital diary's accessories. I used
    it for years with various devices and it
    worked every time like a charm. Now, I
    assumed it had a max232 built in, but
    after cracking the case open I found out
    it wasn't the case. It was made with SMD
    transistors and had no pull-up resistors,
    rather it was an open collector type. PIC
    MCU's abviously don't like this very much
    when used with their hardware USART.
    I made a max232 converter and now
    everything works 100%. I'd like to thank
    everyone for their help.

    --
    Sincerest regards,

    YZ7REA Vladimir M Skrbic
    4N7ATV Repeater Administrator
    YU7GHZ Radio Club President

Similar Threads

  1. Benefits of hardware usart over software?
    By sccoupe in forum Serial
    Replies: 2
    Last Post: - 19th March 2009, 01:16
  2. byte Tx w/ USART 16f876a problem
    By GargamelDigi in forum mel PIC BASIC
    Replies: 2
    Last Post: - 15th July 2008, 05:50
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. Hardware problem or what ?
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th March 2007, 21:39
  5. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56

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