PDA

View Full Version : Serial comm - are 2 wires for TX only enough?



flotulopex
- 27th August 2006, 17:56
Hello,

I use the BASIC-STAMP prof dev board equipped with a RS232DCE chip and have my PIC connected with 2 wires (GND and RA1 with RS232's "TX" pin).

Then I send some text data by pressing a button (I use the INT on RB0). The Led lets me know when the transmission starts and stops so I can double-check on the terminal's screen.

The terminal is set to 9600 Bauds, no parity, 8 bits and 1 stop bit.

I can see bytes received (the counter increments) in the terminal screen but I cannot see any caracter apearing on the screen.

Since I'm new to PICs, I don't use the USART features of the 16F88 at that time.

What am I doing wrong?

This is the code.

MAIN:

IF INTCON.1 = 1 then 'If INT happens, then...
INTCON.1 = 0 'Clear INTERRUPT
HIGH Portb.4 'Switch on Led - start transmission
SEROUT2 Porta.1, 84, ["TEST", 10, 13] 'Print this text in the terminal screen
LOW Portb.4 'Switch off Led - stop transmission
ENDIF

GOTO MAIN

END

Dave
- 27th August 2006, 19:29
flotulopex, What terminal emulator program are you using? Assuming you are using a 4Mhz. oscillator and some kind of inverting RS-232 driver you should be seeing the string being sent. I would first make sure the terminal emulator program is set for the correct baud rate. If the terminal emulator program is receiving any characters, even at the wrong baudrate you will be detecting some kind of count.

Dave Purola,
N8NTA

flotulopex
- 27th August 2006, 20:49
Hi Dave,

I use de Micro Code Studio's terminal.

Changing the baudrate will sometimes make strange symbols apear (like @#%&/...).

In any case, the received bytes count is 22 when sending the "TEST" message.

I set the PIC to work with the internal RC (don't know if I have to set something else) in the CONFIG word (=IntRC).

Isn't it necessary to have some kind of clock to synchronise the PIC with the terminal?

Is there something wrong with my code?

Would you know a different and maybe "better" way to check the program?

Dave
- 28th August 2006, 11:49
flotulopex, It sounds like your baudrate is off frequency. You should have at least a 4 Mhz. osc. for reliable serial communications. Does the processor you are using have an internal 4 Mhz. osc? If not I would suggest using a 4 Mhz. resonator with the caps internal.

Dave Purola,

flotulopex
- 28th August 2006, 13:27
Okay.

I'll try and come back later.

mister_e
- 28th August 2006, 15:57
Be sure you're using the right mode (inverted or not)
Be sure your PORTA have not multiplexed analog stuff (like adc, comparator and such). If so you must disable it.

On the F88 place those llines at the top of your code.
ANSEL=0
CMCON=7

Another thing.. if you use the internal OSC, be sure you set it correctly.
OSCCON=%01100000 ' 4MHZ

by default, this pic run @32khz :eek:
a+

flotulopex
- 28th August 2006, 21:23
Great,

I added both ANSEL and CMCON settings as you suggested and it works fine now (I can see "TEST" in the terminal screen).

I'm going back to the data sheet and try to understand what these settings change to my prog.

I'll also try to "play" with the oscillator settings since this is not absolutely clear to me at that time.

Thanx a lot for your help.

flotulopex
- 29th August 2006, 18:43
After a few more tests, ANSEL and CMCON don't affect the PIC's behaviour.

The key seems to be the oscillator OSCON setting.

Before I got your help, I was using an external 20Mhz ceramic resonator. Nothing worked.

I changed to the internal oscillator with default settings = 31,25kHz. Nothing worked either.

To make it work, I set the oscillator to 4MHz as suggested by Mister_e.

I also tried all the other possible internal oscillator (IRCF) settings; apparently, only 4MHz is working.

I read the PBP help file under the SEROUT2 command. Nothing specifies that serial communication is working only with 4MHz.

I'm not using the USART functionality of this PIC. Is there any info I'm missing somewhere else?

Sphere
- 29th August 2006, 19:14
Make shure your fuse settings are correct before you program the pic and if you are going to use a 20Mhz oscillator remember to add the line DEFINE OSC 20

Hope it helps
Sphere.

mister_e
- 30th August 2006, 03:23
Sure the DEFINE OSC 20 have to be inserted... but you have to modify the config fuse too... case not, it will neever ever work

Look at http://www.picbasic.co.uk/forum/showthread.php?t=543

you must set the OSC fuse to HS