SEROUT Just Garbage!


Closed Thread
Results 1 to 37 of 37
  1. #1
    Join Date
    Jan 2005
    Posts
    21

    Unhappy SEROUT Just Garbage!

    Im trying to get a PIC12F629 to send a simple "hello world" to my pc using windows Hyperterm, and I have the Pic conected as showed in the manual (1k resistor to pin 2 on the db9 connector)
    All I get is garbage on the screen !
    Can anyone HELP? here is my code that I trying to get working


    INCLUDE "modedefs.bas"
    DEFINE CHAR_PACING 1000
    DEFINE OSC 4
    Pause 200 ' Allow pic to Stabilize
    TRISIO = %00000000
    'ADCON0 = 0 ' no adc
    OPTION_REG.7 = 0 ' gpio 0 - 2 digital
    WPU = 255 ' week pull ups on all pins
    CMCON = 7 ' turn week pull ups on
    'ANSEL = 0

    loop:

    SerOut GPIO.0,N300,["Hello World"]
    Pause 1000
    SerOut GPIO.0,N300,["abc",13,10]
    Pause 4000
    GoTo loop

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you don't need those
    DEFINE CHAR_PACING 1000
    DEFINE OSC 4
    OPTION_REG.7 = 0 ' gpio 0 - 2 digital
    WPU = 255 ' week pull ups on all pins


    AND you must set the OSCCAL to get accuracy with SEROUT. I hope your OSCCAL is not erase as now...

    at the end your code will look like this.


    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
        ' Internal Oscillator
        ' Enable watch dog timer
        ' Enable power up timer
        ' Disable MCLR pin
        ' Enable brown out detect
    DEFINE OSCCAL_1K 1
    INCLUDE "modedefs.bas"
    TRISIO.0 = 0 ' set GPIO.0 as output
    CMCON = 7 ' turn off analog comparator
    
    Pause 200 ' Allow pic to Stabilize 
    
    loop:
    
    SerOut GPIO.0,N2400,["Hello World"]
    Pause 1000
    SerOut GPIO.0,N2400,["abc",13,10]
    Pause 4000
    GoTo loop
    and this one is working @2400 baud

    The most important thing here is to set the OSCCAL at the begining.

    hope this help you
    Last edited by mister_e; - 31st January 2005 at 16:02.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2005
    Posts
    21


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks for the Fast responce Mister E!
    Since you said that the code was working for you, I rechecked my comm port settings (found FIFO buffers was not checked). I still had garbage so I added a .22uf cap on the powersuply and BINGO! "Hello worldabc"

    I just wounder How my other code ever worked without a cap?

    Kman

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I just wounder How my other code ever worked without a cap?
    it can, but without OSCCAL... i don't think so, OR intermittent.

    Place a 0.1uF or 0.22uF it's a need for all PICs apps. More than often people forget that the problem can comes from the hardware.

    I always place 0.1uF + 10uF tantalum as close as possible to the PIC. Since now... only software problem
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Kman,

    Kman>>I just wounder How my other code ever worked without a cap?<<

    Well, this seems to be very common. I use a computer power supply, (stolen from older computers). If I do not use a cap on it, I will not get anything, and if I do, it will be garbage.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  6. #6
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    you don't need those
    DEFINE CHAR_PACING 1000
    DEFINE OSC 4
    OPTION_REG.7 = 0 ' gpio 0 - 2 digital
    WPU = 255 ' week pull ups on all pins


    AND you must set the OSCCAL to get accuracy with SEROUT. I hope your OSCCAL is not erase as now...

    at the end your code will look like this.


    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
        ' Internal Oscillator
        ' Enable watch dog timer
        ' Enable power up timer
        ' Disable MCLR pin
        ' Enable brown out detect
    DEFINE OSCCAL_1K 1
    INCLUDE "modedefs.bas"
    TRISIO.0 = 0 ' set GPIO.0 as output
    CMCON = 7 ' turn off analog comparator
    
    Pause 200 ' Allow pic to Stabilize 
    
    loop:
    
    SerOut GPIO.0,N2400,["Hello World"]
    Pause 1000
    SerOut GPIO.0,N2400,["abc",13,10]
    Pause 4000
    GoTo loop
    and this one is working @2400 baud

    The most important thing here is to set the OSCCAL at the begining.

    hope this help you

    Im trying to connect a 12F675 to my machine to test it out but I get nothing in hyperterm.
    Have
    +5 to pin 1
    1K resistor on pin 7 connected to pin 2 on DB9
    Ground on pin 8
    and a 0.1uF from pin 1 to 8.
    pin 5 on DB9 to ground.

    Do I connect first on hyper term or power the chip up first? what setting should I have?

    Thanks

    Using the above code and as 12F675 I can't get it to send anything.

  7. #7
    Join Date
    Jan 2005
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Set up "Hyper term" using "VT100 Emulation".

    Then set the comm port like this
    Bits per sec = 2400
    Data bits =8
    Parity = none
    Stops bits = 1
    Flow control = none

  8. #8
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Tried that but still nothing

  9. #9
    Join Date
    Jan 2005
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Can you post youre code!

  10. #10
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    I thought that was you that asked me for it. I emailed it to someone.
    Here it is I had added a led to it just to make sure the chip was actually working but here it is.

    Code:
    '12F675
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
    TRISIO.0 = 0   'Set GPIO.0 to output.
    ANSEL.0 = 0    'Set GPIO.0 to digital		
    GPIO.0 = 0
    CMCON = 7 ' PortA Digital inputs
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    DEFINE OSCCAL_1K 1
    INCLUDE "modedefs.bas"
    
    
    led2 var GPIO.1
    
    loop:
    
    SerOut GPIO.0,N2400,["Hello World"]
    Pause 1000
    SerOut GPIO.0,N2400,["abc",13,10]
    Pause 4000
    
    high LED2
    pause 500
    LOW LED2
    pause 500
    high LED2
    pause 500
    LOW LED2
    pause 500
    GoTo loop

  11. #11
    Join Date
    Jan 2005
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    I Think your Oscal might be off or Lost!
    Try this code below to see.

    'Lost oscal recover program
    ' Use Hyper_Term settings "9600 N,8,1"
    '
    @ DEVICE pic12F675
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
    @ DEVICE pic12F675, WDT_OFF
    @ DEVICE pic12F675, MCLR_OFF
    @ DEVICE pic12F675, CPD_OFF
    @ DEVICE pic12F675, BOD_OFF
    @ DEVICE pic12F675, PWRT_ON
    @ DEVICE pic12F675, PROTECT_OFF
    SO VAR GPIO.0 ' serial out pin

    ANSEL = 0 ' disable converters
    CMCON = 7 ' disable comparators

    OSCCAL = 0 ' starting value

    Pause 2000

    loop:
    OSCCAL = OSCCAL + $10 ' increment calibration value
    SerOut2 SO,16468,[HEX2 OSCCAL, " This is a close OSC Value!",10,13] ' Display the hex value

    Pause 750 ' give time to read the value
    GoTo loop ' do it forever

  12. #12
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ok I had to make a chane to get it to compile mine doesn't like how you did the defines but here it is
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF

    SO VAR GPIO.0 ' serial out pin

    ANSEL = 0 ' disable converters
    CMCON = 7 ' disable comparators

    OSCCAL = 0 ' starting value

    Pause 2000

    loop:
    OSCCAL = OSCCAL + $10 ' increment calibration value
    SerOut2 SO,16468,[HEX2 OSCCAL, " This is a close OSC Value!",10,13] ' Display the hex value

    Pause 750 ' give time to read the value
    GoTo loop ' do it forever

    I setup hyperterm with the settings you said and then set it to vt100 as well? its running now will let you know how it does.

  13. #13
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Also I should be using pin 2 on serial as the input? and pin 5 to ground?

  14. #14
    Join Date
    Jan 2005
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    The Gpio.0 ---->1k resistor---->pin 2 on a DB9 "rxpin" --->computer

  15. #15
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ok cool I left it running for a while and got
    80
    90
    A0
    B0
    all close so how do I program that into the chip?
    I mean permanitly because I think I lost it on a number of chips when I very first started.
    Using Pic Kit 1 I don't see a way to manually set it.
    Last edited by geckogrotto; - 4th September 2006 at 03:47.

  16. #16
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Also could I get a sample of using SERIN?
    I have tried this and it outputs the hello world and then waits there and never loops. So I can only assume that its not getting the "A" char when I try and send it.

    InputSig var GPIO.0

    loop:
    SerOut Inputsig,N2400,["Hello World",13,10]
    Serin InputSig,N2400,["A"]
    Pause 200
    GoTo loop

  17. #17
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    SerOut Inputsig............
    Serin InputSig............
    must be a copy/paste error...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  18. #18
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Code:
    SerOut Inputsig............
    Serin InputSig............
    must be a copy/paste error...

    Not sure what you are trying to tell me but I'm still stuck.

  19. #19
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you send on the same pin you receive?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  20. #20
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Oh lol yea guess that wouldn't work well thanks... hmm How do you send to serial port on a different serial pin? Now I understand the problem im confused on how to fix it lol.

    I seem to have a lot of "Only learning opportunities." but atleast im learning

  21. #21
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    how about something like
    Code:
    '12F675
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    DEFINE OSCCAL_1K 1
    INCLUDE "modedefs.bas"
    TX_Pin var GPIO.0    'To DB9 RX pin 2
    RX_Pin var GPIO.1    'To DB9 TX pin 3
    
    TRISIO.0 = 0         'Set GPIO.0 to output.
    TRISIO.1 = 1         'Set GPIO.1 to input     
    
    ANSEL = 0            'disable ADCs
    CMCON = 7            'disable comparator
    
    AChar var byte
    tx_pin = 0           'inverted mode idle state
    
    achar="A"
    Pause 100            'OSC settle time... 
    
    loop:
        SerOut tx_pin,N2400,["Waiting for ",achar,13,10]
        SERIN  rx_pin,N2400,[achar]   
        serout tx_pin,N2400,["Got it...",13,10]
        goto loop
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  22. #22
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thank you very much Mister_e that works perfect and will get me a good start on serial

    Its so great to have cool people around that help us noobs

  23. #23
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    You're welcome. Great to hear it help you.

    Have fun!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  24. #24
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Mister_e Mind if I email you or ask a non related question here?

  25. #25
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    No problem.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  26. #26
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default

    geckogrotto,

    I'm actually trying to understand a little bit more about serial communication and making some tests on my side too.

    I had to use a level converter (MAX232) to make the communication work.

    Looking at some posts, I have understand you connected your PIC directly to the PC's serial port (= without converter)?

    I must be wrong, no?
    Roger

  27. #27
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex
    geckogrotto,

    I'm actually trying to understand a little bit more about serial communication and making some tests on my side too.

    I had to use a level converter (MAX232) to make the communication work.

    Looking at some posts, I have understand you connected your PIC directly to the PC's serial port (= without converter)?

    I must be wrong, no?

    Nope not wrong. I have pic output GPIO.0 connected to a 1K resistor then to serial pin 2 and GPIO.1 directly to serial pin 3. Serial pin 5 to ground.
    Also have a 0.1uF from pin 1 to 8 of the PIC + and ground. Thats it using the last bit of code Mister_e posted and its working fine.

    I should already be in bed now, I'm crashing now but if I can help I will tomorrow.

  28. #28
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default

    Ah!? (which means I'm very surprised!!!)

    I thought it was mandatory to use a level converter to transmit data from a PIC to a PC and vice-versa.

    I will try to connect my 12F675 as you did.

    In fact, my first try was with a 16F88 having an AUSART module and it didn't worked whithout the level converter (but I didn't use a resistor neither - I'll have to try this too). Data where transferred but it was unreadable - fuzzy characters and RX counter on PC never stopped. Is this (module) making a difference?

    Get "regenerated" first...

    Thanks
    Roger

  29. #29
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex
    Ah!? (which means I'm very surprised!!!)

    I thought it was mandatory to use a level converter to transmit data from a PIC to a PC and vice-versa.

    I will try to connect my 12F675 as you did.

    In fact, my first try was with a 16F88 having an AUSART module and it didn't worked whithout the level converter (but I didn't use a resistor neither - I'll have to try this too). Data where transferred but it was unreadable - fuzzy characters and RX counter on PC never stopped. Is this (module) making a difference?

    Get "regenerated" first...

    Thanks

    Let me know how it goes. I was getting weird chars at first but turned out my OSCAL was messed up. I believe you have to have
    DEFINE OSCCAL_1K 1
    ANSEL = 0 'disable ADCs
    CMCON = 7 'disable comparator
    in there for sure too.

  30. #30
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default

    OSCCAL is not valid for 16F88.

    Even with ANSEL and CMCON set, I still get strange characters on the terminal's screen.

    When I connect to my level converter, no problem.

    I'm goint to try with my 12F675...
    Roger

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


    Did you find this post helpful? Yes | No

    Default

    Since the level converter provides inversion, and it works with the level converter, it follows that if you are not using a level converter, you need to send the data inverted.
    Charles Linquist

  32. #32
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default

    I just can't find the setting to "invert" data on Hyperterminal for Windows XP. Same for the Terminal emulator within Micro Code Studio.

    Since I'm always getting these same bizarre characters, it might effectively be because of this missing signal invertion.

    Can someone suggest any terminal emulator I could use?
    Roger

  33. #33
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex
    Can someone suggest any terminal emulator I could use?
    I use Tera Term. I find it much easier to use than hyperterminal. But, and I am speaking in the blind a little hear, I don't know if you can invert the singnals from the terminal software. Either way, you may find you like Tera Term, and it's FREE!

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    I'm not talking about inverting the data on your terminal.

    You have to do it in the PIC. There are two options on SEROUT - one TRUE and one INVERTED. Use the INVERTED option.
    Charles Linquist

  35. #35
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Looking at the code I was given I see

    tx_pin = 0 'inverted mode idle state
    Could maybe try that on RX_pin...
    Are you trying the code and chip I was given?

    I'm using both hyper term and micro code one both work fine with formal settings and im using xp.

  36. #36
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default

    Well,

    It took me a while to find out how to calculate the correct "mode" value for the SEROUT2 command. Finally, it works well (on both PICs 12F675 and 16F88).

    I still don't understand the difference between the SEROUT and the SEROUT2 commands. I read the Micro Code Studio's help files but they are not very clear to me. Or is it only that SEROUT handles "only" 8 bits and SEROUT2 can handle up to 9 bits?

    My previous post sounds now a little stupid but what can be crystal clear for you can be foggy to me... Thank you for your patience.
    Roger

  37. #37
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Glad you got it working

    I am very new to all this as well so I don't understand a lot either... The important thing tho is you have it working and now know how to get another working


    Daniel

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

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