PDA

View Full Version : Serin2 pass through to Serout2



scottl
- 14th November 2007, 23:49
I am trying to get the following code to work but get garbage on the other side.



serin2 GPIO.1,84,5000,mainloop,[str command\4\13] ' This could be Acr, E'dc1'cr or E'dc3'cr

If (command[1] == 19) then ' 19 = DEC for 'dc3' char
goto IButton
else
SEROUT2 GPIO.4,84,[str command,13] ' Cannot get the same on the output
serin2 GPIO.5,84,5000,mainloop,[str command\31\13] ' Then get response
SEROUT2 GPIO.0,84,[str command,13 ' Then send back to PC
endif



Any ideas? Should I wait a few ms between sending back out the other port? Should I be using something other than STR to send back to the pc?

Thanks in advance,

Scott

mister_e
- 15th November 2007, 02:09
Please, when you post a question, give us all details such as PIC #, Using internal OSC or not, String format or Bin or Dec format. Same thing on PC side, which software, setting etc etc.

First thing to try, send a text string to the PC, if everything is correct, send a text string + 1 byte of data from your PC to the PIC and use WAIT modifier + 1 variable. if the content of the variable match everything should be correct... at very least the hardware.

scottl
- 15th November 2007, 13:31
Here are the details:

PIC12F675
Internal OSC 4 mhz

It only gets garbage when I enable the second 232 port on GPIO.4! When I reroute the data how should it be formatted? Everything from the PC is ASCII format.

Thanks,

Scott

mister_e
- 15th November 2007, 14:42
I may think of few things here
1) 9600 baud with internal osc is a bit dangerous, try at lower baudrate
2) internal OSC calibration is screwed up.
3) all multiplexed analog stuff are not disabled
4) there's no max-232 (or else inverter) between the PIC and the PC
5) noisy supply line
6) maybe something else

i'm doing a little something here, i'll post it later so you could try on your side as well

mister_e
- 15th November 2007, 15:27
try this



'
' PIC Configuration
' =================
@ __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 ' load internal osc calibration

'
' Hardware configuration
' ======================
TRISIO = %00101010 ' set GP3, GP4, GP5 input
' others to output
ANSEL = 0 ' disable adc
CMCON = 7 ' disable comparators

'
' Hardware assignment
' ===================
S_In1 var GPIO.1 ' Serial input #1
S_In2 VAR GPIO.5 ' Serial input #2
S_Out VAR GPIO.4 ' Serial output


'
' Variables definition
' ===================
Command VAR BYTE[10]
Baud var word

'
' Constants definition
' ====================
T2400 CON 396
T4800 CON 188
T9600 CON 84
N2400 CON 16780
N4800 CON 16572
N9600 CON 16468

'
' Software/Hardware initialisation
' ================================
'
' select baudrate
' ---------------
baud = t9600
'
' Set serial output pin idle level
' --------------------------------
if baud<400 then
high s_out
else
low s_out
endif

pause 50 ' settle time
serout2 s_out,baud,["Hello, this is a test!!!",13,10]

'
' Program Start
' ============
Start:
serout2 s_out,baud,["i'm waiting for incoming data on GPIO.1",13,10]
serin2 s_in1,baud,[str command\10\13]

Serout2 s_out,baud,["i got...", str command,13,10,13,10,_
"waiting for some data on GPIO.5",13,10]

serin2 s_in1,baud,[str command\10\13]
Serout2 s_out,baud,["i got...", str command,13,10,13,10]
goto start

scottl
- 15th November 2007, 19:17
Steve,

Thanks for your time! I will try this when I get home this evening.

4) there's no max-232 (or else inverter) between the PIC and the PC
Sorry forgot to mention the PIC connects to a Bluetooth radio then to the PC. This has been a stable product of ours for the last 1 1/2 years. This is a test for our customer adding the IButton. Both sides are direct connect!

Thanks,

Scott