PDA

View Full Version : Why is this so hard? HSEROUT problems.



groston
- 6th November 2006, 05:16
I have been working with PIC and PBP for several weeks now. Thus far, it has been a continual exercise in frustration. (FYI - I have been developing real-time control systems for 20 years, i.e., I am not a neophyte.)

Enough griping. (Well, the PBP documentation sucks - OK, griping done.)

My application, built using a PIC 16F88 with PBP V2.47, is not working. So, I figured I'd use the debugging capability in microCode Studio (V 2.3.0.0) to try to figure things out. (I have the meLabs U2 USB programmer.) Couldn't get it to work. So, I built a simple circuit to test serial communications. This also doesn't work.

I have attached a zip file with some further information:
1: commCircuit.gif: this shows the as-built schematic. Much of this was copied from the schematic for the meLabs X18 board.
2: serTst.pbp: he exciting source code, all 41 lines of it
3: config.jpg: screen shot of the configuration option for the meLabs Programmer (V4.20)
4: output.txt: data acquired using the built-in serial communication tool

What I have observed:
1: The LED should flash with a period of one second on, one second off. It does not. It turns one and off, typically more than once per second, with the time period seemingly random.
2: The serial message received are garbage. (see output.txt)
3: Changing the baud rate from 9600 to 300 had no impact.

I think the hardware is configured properly, but this just isn't working. (In fact, at one point, I had forgotten to hook pin 15 of the MAX232 to ground, and with this pin floating and with the HSERIN line commented out, the system performed mostly as expected... weird.)

I can really use your help. I am already behind schedule and due to familial obligations, am likely to fall even further behind without help.

Thank you!

sayzer
- 6th November 2006, 06:13
Hi Groston,

Let me post your code here first.



'************************************************* ***************
OSCCON = $60 ' set the internal clock to 4 MHz
define OSC 4 ' set osc to 4 MHz

TRISB.0 = 0 ' Set RB0 to output

' Initialize USART
define HSER_TXSTA 24h ' Enable transmit and asynchronous mode
define HSER_RCSTA 90h ' Enable serial port and continuous receive
define HSER_BAUD 9600 ' Set baud rate to 9600

recv var byte
cntr var word
recv = 0
cntr = 0

ADC_loop:
if recv = 0 then
hserout ["message ", dec cntr, 13]
else
hserout ["Other", 13]
endif

if cntr = 255 then
cntr = 0
else
cntr = cntr + 1
endif

PORTB.0 = 0
pause 1000 ' 1 sec delay

PORTB.0 = 1
pause 1000 ' 1 sec delay

hserin 1, missed, [recv]

goto ADC_loop

missed:
recv = 0
goto ADC_loop






What was your idea in the red part?

Could you give details as to understand what you wanted to do there? Currently, as it is now, it can not work.


--------------------------

HenrikOlsson
- 6th November 2006, 10:28
Hi Groston,
The PIC is obviously sending the data out. You are running with the internal oscillator and it may be that it's not precise enough for the baud rate generator to produce the correct timing. Can you try it with a external crystal instead. (I think it should've worked when you tested at 300baud though, but you'll never know).

Try to get the PIC to send data correctly first. (I know that's what your doing) but perhaps something even more simple, like:


i var byte
Loop:
i = i + 1
HSEROUT [#i, 13]
Toggle PortB.0
Pause 1000
Goto Loop


Let us know.

/Henrik Olsson.

groston
- 6th November 2006, 13:01
Henrik,

I will try your suggested code a bit later today.

As for the intent of the section in red:
I was simply looking to see if the program would recognize incoming serial data. By using the built-in serial communications window, my plan was to send a character every so often to see if the alternate message was outputted.