16F877 and Hserout command


Closed Thread
Results 1 to 6 of 6
  1. #1
    fbestepe's Avatar
    fbestepe Guest

    Question 16F877 and Hserout command

    Hi Friends,

    I am a new member of this forum. I hope I could get help from you and also I could help you.
    I have a problem about Hserout. While receiving chars from PC to Pic via Hserin I have no problem, Everything is OK, pic can get the chars and sent to LCD perfectly. But when I am trying to send chars from pic to PC , something is wrong. For example, when Hserout["MA"] , only M can be seen normally on Serial Comm. Interface Receive Window of Microcode Studio, instead of A a strange char is seen. I tried twice for 2400 and 4800 baudrates, but the situation is same. Also I send all capital letters via Hserout["A"], Hserout["B"]...... one by one, instead of C,E,F,I,J,L,O,R,T and X letters some strange chars are seen on receive window. All other letters are OK. It looks very confusing to me. Does anbody have an idea about solution?
    Thanks a lot...
    Firat Bestepe

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    There's insufficient info here to give us a clue to start playing with... sending to an LCD (with LCDOut commands) is not dependant on a stable oscillator. Sending Serial output is very much dependant on a good oscillator.

    Are you using an xtal or resonator... and what frequency? Try starting at 300 baud and working up.

  3. #3
    fbestepe's Avatar
    fbestepe Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you for your interest Melanie. I had started to think that nobody would reply. Sorry for insufficient info! I have been using 4 MHz xtal oscillator. You are right serial ouput procedure with Hserout is dependent to ascillator performance, but Hserin is also dependent to ascillator. Hserin performs normal but Hserout does not. The most confusing point for me is that.
    I will try with 300 baud as you recommend. If you have any other comments on the problem, I will be pleased to hear them.
    Thanks....

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Serial communications is a long and complicated subject, and you could write a book about just on it's own. Lot's of people successfully implement Serial comms and get away with it, and just because they never encounter any problems they become ‘instant experts’. And because they never had problems, it's always assumed neither should anyone else. This is not the case. There's lots of problems that can creep in and it’s more luck and good fortune if you never encounter any.

    Here’s a small checklist…

    1. Firstly a stable oscillator is a must. If you have 4MHz, and it's a Crystal or a Resonator (or other type of external oscillator - eg TTL oscillators - but NOT RC types) then that’s fine. If you rely on an internal oscillator or RC type oscillators, it’s unlikely you will get stable communications above 1200 baud. If you do, again it’s down to good fortune. Experimenting with a latest batch of 100 PIC16F628’s running on internal oscillator, about 80% managed 2400 baud, 17% managed only 1200 baud, and 3% only reliably managed 300 baud. You can see it’s a lottery so Serial Comms MUST have a good stable oscillator.

    2. If you’re using a Xtal or Resonator, have you remembered the appropriate loading Capacitors? Some Resonators (especially the 3-pin ones) have them built-in and do not need any external Capacitors added.

    3. Have you remembered to tell PBP what oscillator setting you’ve got? 4MHz is the default so no additional action needs to be taken if you have 4MHz.

    4. Have you remembered to tell the PIC what oscillator it is to use. You might have a 4MHz Xtal or Resonator, but if the PIC is set to Internal Oscillator then it’s not going to make any difference. With a 4MHz Xtal or Resonator, your PIC should be set to XT-OSC.

    5. When playing, always start at the lowest baudrate and work up. So if 1200 baud doesn’t work, drop to 600 or 300. If however you have a good Xtal or Resonator (or other external oscillator), and you cannot get at least say 4800 baud reliably (at 4MHz), then you have other problems that need investigating (for example see point 4).

    6. If using HSERIN/HSEROUT remember you need to hardware INVERT your comms signal before it is sent to your PC. The use of a MAX232 or equivalent is the usual route although there are many other methods.

    7. A lot of garbage can get pipelined in Serial Communications and a single bit misplaced can ruin your day. So to flush this out, always prefix your transmission packet with a number of NUL ($00) characters… this little loop is a good test sending to your PC…

    Loop:
    HSEROUT [REP $00\8,13,10,”The quick brown fox jumps over the lazy dog”,13,10]
    Pause 1000
    Goto Loop

    8. If sending to a PC, always try to terminate your data packet with a CR/LF (13,10 in my above example). This terminates the Data Buffer String at the PC’s end and starts a new string with the next data packet. Lots of people try to send mountains of data to the PC and wonder why everything hangs after about 32K characters. It’s because Microsoft DOS/Microsoft Languages only allocate around 32K to the comms input buffer (certainly was the case with Microsoft Basic). When this buffer is full no more data will be accepted and everything hangs. Send periodic CR/LF’s to flush the buffer and ensure this never happens.

    Hope these tips will be handy on the road to resolving your issue.

    Melanie

    Oh, as an afterthought, if your Hardware is good, and you still have problems, post your code (showing any and all defines) and we can all take a look at it...

  5. #5
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    I'd like to add something if I may? Take a look at this thread:

    http://www.picbasic.co.uk/forum/show...=&threadid=428

    This will show you just one of the things Mel was telling you about. I assumed my factory made rs232 <> TTL converter hardware was built with MAX232, but instead it was built with SMD transistors with open collector and 16F628's harware USART disliked this very much... Just my 2 cents

    --
    Sincerest regards,

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

  6. #6
    fbestepe's Avatar
    fbestepe Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Atomski,

    I have solved my Hserout problem. You and Melanie estimated the problem truely. The problem was because of max232, I checked everything and all were normal. At the end I decided to change my max232 and now the system is OK. I can send and receive all characters between PC and pic. But still strange, If max232 is not working correctly, how the pic could receive chars from PC by Hserin? This is stil a mystery for me but anymore an unimportant mystery.
    Now I have a new problem about Serin2 and Serout2! I will write a message to the forum about it. It is related with other part of my project. I solved the part of Pic from/to PC owing to your helps. Now Pic from/to Electronic Electricity Meter. Please take a look to my new message.
    Thank you for your all interest Atomski and Melanie.

    Best Regard

Similar Threads

  1. Reading analogs with 16F877
    By Andre_Pretorius in forum Serial
    Replies: 10
    Last Post: - 8th July 2008, 19:07
  2. Replies: 2
    Last Post: - 23rd July 2006, 08:16
  3. HSerOut 16F877 Interrupt Driven
    By BigH in forum Serial
    Replies: 2
    Last Post: - 15th January 2006, 00:09
  4. Serial from 16F877 to VB
    By jrudd in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th March 2005, 23:33
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36

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