Log in

View Full Version : PIC hanging on Serin



onioni
- 29th July 2011, 16:07
Hi, I am new to the forums(and to Pic's) and have been trying to learn about serial communications between different chips. I have a PIC16f688 and am trying to communicate with a 3.3V device and a Hyperterminal over RS232. I have been successful communicating with the Hyperterminal so far, but receiving communications form the 3.3V chip to the PIC have not been so successful. I have used an inverter chip to adjust voltage levels coming from the 3.3V chip to the PIC to 0-5V logic. I also have a monitor that came with the 3.3V device that allows me to see what the chip is responding in HEX format. I have even used a scope to see the waveforms being output from the 3.3V device. I am stumped as I see the reply from the 3.3V chip in the provided monitor and on my scope, but the PIC is hanging on the Serin call. Here is the code that I am using:

Include "modedefs.bas" 'includes Serial functionality
Define OSC 4 'use the 4 MHz internal oscilitor

HTO var PORTC.4 'make RC4 output hyperterm
HTI var PORTC.5 'make RC5 input hyperterm

XBI var PORTC.1 'make RC1 input XBEE
XBO var PORTC.2 'Make RC2 output XBEE

TRISC = %101010 'Sets the directions of the bits on portc
ANSEL = $11 'port c digital io
b0 var byte 'the variable to store the input into
b1 var byte
b2 var byte
b3 var byte
b4 var byte
b5 var byte
b6 var byte
b7 var byte
'byteArr var BYTE[8]
i var byte
start:
'using inverted baudrate to communicate with the
'HT through a 440 ohm on the TX and a
'22K ohm on the RX Pins

'let it warm up .1sec
Pause 100
Serout XBO,N9600,["Starting UART.....",10,13]
loop:
Serout XBO,N9600,["Query the xbee module....",10,13]
Serout HTO,T2400,[$05,$01,$05,$02,$08,$04 ]



Serin HTI,T2400,[b0,b1,b2,b3,b4,b5,b6,b7]
'Hangs here........

Serout XBO,N9600,["Retry"]

Serout XBO,N9600,["Reply from XBEE...",10,13]

Serout XBO,N9600,[#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7]


Serout XBO,N9600,[10,13]

Serout XBO,N9600,["That is all folks",10,13]

Pause 1000 'pause 1 sec
Goto loop ''endless loop

End

I am stumped.... any help would be greatly appreciated.

Thank you,

oni

Dave
- 29th July 2011, 19:02
onioni, using your scope, what is the level at the PIC rx pin when the system is in an idle mode (no data being sent)

onioni
- 30th July 2011, 16:27
Hi Dave,

I am running the 3.3V TX output through 2 inverters then to the RX pin of the PIC, so the PIC RX pin is seeing +5V when nothing is being sent.

onioni

Dave
- 30th July 2011, 23:16
onioni, That sounds good to me. Looking at the scope, is the timing correct for the baudrate? Try sending repeatedly the character "w" I beleive which should what looks a square wave. See if the time interval for the HIGH and the LOW are the same. If there is a difference this may be due to a slewrate problem with the inverters.

onioni
- 1st August 2011, 17:29
I checked the waveforms on the scope and the are identical except the one from the inverter is 5V instead of 3.3V. No differences due to slew rate to speak of. I have read on this forum that it is important to read the PIC datasheet, well I just learned a hard lesson. By properly setting the CMCON0 register to allow digital I/O, the program worked like a charm. I found this out after switching the 3.3V input-output with those of the hyperterminal. The HT was then hanging instead of the 3.3V chip. I will read the datasheet more closely next time. I appreciate you taking the time to troubleshoot with me.

onioni