PDA

View Full Version : Serial comunication problem



synsyn
- 30th September 2011, 09:38
Hi,

I have a very silly problem with a my very simply
prog in PBP.

I got a easy circuit with a 16f676 PIC and a IC Maxim 232
all fitted on a breadboard, where I simply send data(string, variables, ecc)
to COM1: on my PC, with Debug instruction at 2400B and using Hyperterminal
on Win-XP.

The problem is the I get back just a lot of garbage on my
screen(unreadable chars) and I can't visualizy any ASCII
code!

I have checked a very lot of times my circuit, changed
the IC, verified the voltage, the pins on RS-232, change
the serial port, the prog in PBP, but it seems is correctly
and all is too simply to be wrong.
I have checked with a LCD if PIC/Prog work and yes it's
work perfectly, but I can't send anything on my PC's
serial port.

Maybe I need to set the RS-232 DTR, DCD, ecc in anyway ?

So please help my to solve it because I think to forget
to do some elementar thing.

Thanks in adavance.

PS:
Forget my english.

HenrikOlsson
- 30th September 2011, 10:34
Hi,
Have you tried changing mode for DEBUG, true vs inverted?

DEFINE DEBUG_MODE 0 'or 1 (I can't remember which one at the moment)
/Henrik.

kannonballer
- 30th September 2011, 10:56
A couple of other things to check are the charge pump capacitors that you are using with your RS-232 chip and your circuit grounds.

Charlie
- 30th September 2011, 10:56
Based on your description, the data is either inverted, or being sent at the wrong speed. Verify setting match in both your code and on the PC, (for example 9600,8,N,1) and then check your clock on the PIC is correct. The speeds specified in PBP are only valid with a certain clock (4 MHz off the top of my head). You should not need to set DTR, or DCD. Final thing to check is that the RS232 cable is connected properly. If you have not crossed TX to RX, sometimes noise with give screens of garbage.

Charles Linquis
- 30th September 2011, 13:39
Also, make certain that Hyperterm is set for Flow Control = None

ardhuru
- 30th September 2011, 16:19
Are you adding the '#' before the variable?

And if you are using the built-in oscillator on the 16F676, are you sure your OSCCAL value is correct?

Regards,

Anand

synsyn
- 30th September 2011, 20:53
Firs one thanks to all for fast answer.
Yes I have checked all things posted and a lot of times.
But nothing work.

Maybe is a problem with a Breadboard thet collect noise ?

I know it hard to say what check, but all seem fine and at
same time nothing work!:(

I am very confused because I have made a lot o circuit
with PIC in assembler and basic, with motor, with display,
with PWN dimmed ligght, and ever have worked fine,
but now with a silly serial debugging purpose nothing
work.
I am very frustated!

mackrackit
- 30th September 2011, 22:03
Post you code and configs along with a schematic.
Everyone is guessing as is.

synsyn
- 6th October 2011, 14:07
Hello,
Thank for reply and sorry for the late to answer but I was away for job.

I don't have much to to make experiment but I have try to change the
cable and the main circuit.
All is same I will get back the same garbage but...

Now i try to send the word "Hello" and now I get back on screen PC the
exact number of chars but with non ascii format like '¨µ¼´¿".

Yesterday I don't know how, maybe some change to prog or same hack
on circuit, for a short time I have get back the correct string on screen!;)
"hello"hello"hello"...

After that I have made some change and now all is come back in the
same garbage!:(

In anyway this is the source:
------------------------------------------------------------------------------
ANSEL=0
CMCON=7



TRISA = %11110000 ' Set PORTA to all input
TRISC = %00000000 ' Set PORTA to all input


Include "modedefs.bas"

DEFINE OSC 4

DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 1
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0

DEFINE DEBUG_PACING 1000

Clear
Pause 1000

Cont var Byte

Cont = 0
Mainloop
PAUSE 1000
Cont = Cont + 1
Debug "Hello"
PORTC.2 = 1
PAUSE 1000
PORTC.2 = 0
goto Mainloop
------------------------------------------------------------------------------
And this the circuit:

6034

cncmachineguy
- 6th October 2011, 15:04
I see you have a LED set to blink on for 1 sec, then off for 1 sec. Is the LED blinking and at the correct speed?

synsyn
- 6th October 2011, 15:37
Hi Bert,

I have fogot to say, it is only a luminose control to see if all work well(I don't have put it on the scheme).
And yes it seem blink 1 sec and 1 sec no. It's hard to say just lookin at it
but the time seem correct yes.

cncmachineguy
- 6th October 2011, 15:58
Well that would seem to rule out any OSC issues. The Pic is running and running at 4Mhz as you have programmed for. At this point, I think I would just have it run and start touching stuff. Maybe there is a breadboard problem or something like that. If it worked yesterday, even just for a few times, it seems like the code is good. So the only thing left is hardware.

Wiggle the caps while watching the PC to see if "hello" magically appears. also all the wires. Do this 1 at a time to try and isolate the problem.

Maybe even try a different output pin, Or move the parts around on the BB. I have had BB's fail on a pin here and there from the socket not making good contact.

synsyn
- 6th October 2011, 16:33
Well that would seem to rule out any OSC issue


Yes I think the problem is there, but maybe in the code or maybe I dont' sent
some registry of 16f676 IC.

I say this because I have change the PIC circuit in a 1000hole board and I get
the same garbage.
I think to have change something in the code about OSC define or something
aroud and the serial work.
I anyway I can wrong, but the only thing ever same is the MAX232 circuit,
but there is only some condensator so I can see any thing wrong.

Maybe some one have made the same circuit with PIC 16f676 and Max232
and he can check if the code, expeccialy the Oscillator define, is correct ?

ardhuru
- 6th October 2011, 18:12
Why dont you try bypassing the Max232 and use Debug Mode 1 to rule that out?

And I just noticed you're using the 16F676; are you sure your OSCCAL value is intact?

Check this outhttp://www.picbasic.co.uk/forum/showthread.php?t=15268

Regards,

Anand Dhuru

Charles Linquis
- 6th October 2011, 20:49
You can do a pretty good "no equipment" check of your oscillator by turning ON a LED, issuing a PAUSE 60000 and then turning it off. Even with human error, if it is ON for a minute, you should be within 2%, which is close enough for communications at 9600 baud. If you want to get even closer, issue the PAUSE 60000 10 times in a row. Turn your LED on at the beginning and off at the end. It takes 10 minutes, but you can easily get much better than .5% accuracy that way. The PBP PAUSE command is *VERY* accurate.

Also, I highly recommend Bray's terminal program
https://sites.google.com/site/terminalbpp/

It works with high-numbered COM ports (useful if you are using USB <-> 232 devices). It works with
Windows 7 (which does NOT have Hyperterminal), and best of all
It lets you choose non-standard baud rates. If your PIC is running 5% fast, you can choose 1080 baud if
you like (not all baud rates may be attainable with all hardware, but the software does a great job).

Charles Linquis
- 6th October 2011, 20:51
Oh, and QUIT using those 16F chips! 18Fs are so much better and don't cost any more.

Normnet
- 6th October 2011, 21:40
Oh, and QUIT using those 16F chips! 18Fs are so much better and don't cost any more.
I second that.

Norm

cncmachineguy
- 6th October 2011, 22:11
Not to continue hi-jacking this thread, but I have to a little. What is so bad about the 16F's? They are easier to configure if you are new to datasheets, work just as well (both 8 bit). OK, less memory, but who needs it for starting out stuff? I have a couple of products running 16f676 that have been going strong now for 8 years I think. Work fine!

I am starting to play with the 18's, but really just because.

Charles Linquis
- 6th October 2011, 23:24
Yes they work, but the forum would run a little smoother if most everyone was using the same series of chip. I'm sure MELabs thinks that way also.
The fact that you can easily get parts with large codespace is such a bonus. You can add features over the years without
changing much.
90% of Microchip's really neat parts in the 8-bit realm are in the 18F family (18FxxKxx, 18FxxJxx).
If you write some routines in ASM, it is much nicer to not have to deal with endless bank switching.
You can use LONGs and 2000 element arrays.
Even if you don't need all the neat stuff now, why not get a chip that has the peripherals and codespace now so that you can learn to use the extra features in your spare time?

And they don't cost more. Easy decision for me. I'll be quiet now.

synsyn
- 7th October 2011, 09:52
All Solved!!!

I know that the issue was on Clock, or better, in wrong clock serial syncronization.
So I have change the Internal Oscillator with a External quarze and made the code
changing to use it. Now all work very good and without any problem.
I have take a look on 16f676 Datasheet where is writted than internal clock have a
little tollerance about on some kilohert. But in other forum discussion I have found
than the internal clock is barely enought in use on serial asyncronous comunications.
This is my case.
Maybe if I work on OSCCAL calibration I will use the Internal clock.
But if I put OSSCAL issue on Picbasic source the PBP give a error, like if OSSCAL is
not avaible on 16f676.
I have lost a week on this problem but now all is over and in anyway I have get more
experience about use and expecially the "non-use" of internal oscillator for some specified
task like comunications, where is very important have a good timing.
Thank to all friends to have spend their time on this post and for goods solution proposed
to me.
This forum is a very good mine of competent and friendly people. I will hope to give some
contribution in future.
Thanks again.
:)

synsyn
- 7th October 2011, 20:23
And I just noticed you're using the 16F676; are you sure your OSCCAL value is intact?

Check this outhttp://www.picbasic.co.uk/forum/showthread.php?t=15268

Regards,

Anand Dhuru

Hi Anand,
I have tried today your example and I did some experiment,
and of corse it works very good!!!
It's a easy way to use the PIC with internal oscillator
in serial comunications, or other critical tasks where timing
is crucial, without the use of an external quartz.
Thanks a lot for your advice.
Regards,
Gabriele

ardhuru
- 8th October 2011, 07:11
Glad it helped, Gabriele. Now that you have the calibrated OSCCAL, you could fairly safely ramp up the baud to 9600.

Regards,

Anand

synsyn
- 8th October 2011, 11:00
Oh Yes now I can Burd the Sky!!!:)
Thanks again to have helped me and for knowing on forum.