PDA

View Full Version : SEROUT Just Garbage!



Kman
- 31st January 2005, 14:49
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

mister_e
- 31st January 2005, 15:55
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.




@ __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

Kman
- 31st January 2005, 17:22
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

mister_e
- 31st January 2005, 17:45
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 ;)

Dwayne
- 31st January 2005, 19:48
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

geckogrotto
- 2nd September 2006, 17:53
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.




@ __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.

Kman
- 2nd September 2006, 19:49
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

geckogrotto
- 2nd September 2006, 20:24
Tried that but still nothing

Kman
- 3rd September 2006, 01:09
Can you post youre code!

geckogrotto
- 3rd September 2006, 01:35
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.



'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

Kman
- 3rd September 2006, 15:41
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

geckogrotto
- 3rd September 2006, 15:52
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.

geckogrotto
- 3rd September 2006, 15:57
Also I should be using pin 2 on serial as the input? and pin 5 to ground?

Kman
- 3rd September 2006, 17:03
The Gpio.0 ---->1k resistor---->pin 2 on a DB9 "rxpin" --->computer

geckogrotto
- 4th September 2006, 01:09
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.

geckogrotto
- 4th September 2006, 06:18
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

mister_e
- 4th September 2006, 16:48
SerOut Inputsig............
Serin InputSig............

must be a copy/paste error...

geckogrotto
- 4th September 2006, 19:31
SerOut Inputsig............
Serin InputSig............

must be a copy/paste error...


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

mister_e
- 4th September 2006, 19:33
you send on the same pin you receive?

geckogrotto
- 4th September 2006, 19:40
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

mister_e
- 4th September 2006, 20:47
how about something like


'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

geckogrotto
- 4th September 2006, 20:53
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 :)

mister_e
- 4th September 2006, 20:58
You're welcome. Great to hear it help you.

Have fun!

geckogrotto
- 4th September 2006, 21:18
Mister_e Mind if I email you or ask a non related question here?

mister_e
- 4th September 2006, 22:15
No problem.

flotulopex
- 5th September 2006, 05:37
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?

geckogrotto
- 5th September 2006, 06:02
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.

flotulopex
- 5th September 2006, 10:29
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

geckogrotto
- 5th September 2006, 16:43
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.

flotulopex
- 5th September 2006, 20:31
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...

Charles Linquis
- 5th September 2006, 23:57
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.

flotulopex
- 6th September 2006, 14:18
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?

SteveB
- 6th September 2006, 15:04
Can someone suggest any terminal emulator I could use?

I use Tera Term (http://www.ayera.com/teraterm/). 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

Charles Linquis
- 6th September 2006, 17:52
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.

geckogrotto
- 6th September 2006, 18:10
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.

flotulopex
- 6th September 2006, 19:40
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.

geckogrotto
- 6th September 2006, 19:42
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