PDA

View Full Version : serin string question



Sam
- 29th November 2006, 03:10
Hi,

I'm trying to learn how to have serin wait for a string and then output a reply.
This is actually a continuation of my previous thread, I think I did have it working at one point then changed everything and now I'm lost. I've read the manual and re read it and searched and tried many different ways but I can't seem to get it right. Please point me in the right direction. Please tell me what I'm doing wrong.

Here is a test routine I'm trying to learn from:


'12F675
_CONFIG
_INTRC
_OSC
_NOCLKOUT
_WDT_ON
_PWRTE_ON
_MCLRE_OFF
_BODEN_ON
DEFINE OSCCAL_1K 1

INCLUDE "modedefs.bas"
TX_Pin VAR GPIO.0 'To DB9 RX pin 2
RX_Pin VAR GPIO.1 'To DB9 TX pin 3

TRISIO.0 = 0 'Set GPIO.0 to output.
TRISIO.1 = 1 'Set GPIO.1 to input

ANSEL = 0 'disable ADCs
CMCON = 7 'disable comparator



MyText VAR BYTE [5]
tx_pin = 0 'inverted mode idle state

MyText[0]="H"
MyText[1]="E"
MyText[2]="L"
MyText[3]="L"
MyText[4]="O"





Pause 100 'OSC settle time...

loop:
SerOut tx_pin,N9600,["Waiting for ",MyText,13,10]
SerIn rx_pin,N9600,[STR MyText]
SerOut tx_pin,N9600,["I GOT IT...",10,13]
GoTo loop


Thanks for any help

Archangel
- 29th November 2006, 07:33
Hi,

I'm trying to learn how to have serin wait for a string and then output a reply.
This is actually a continuation of my previous thread, I think I did have it working at one point then changed everything and now I'm lost. I've read the manual and re read it and searched and tried many different ways but I can't seem to get it right. Please point me in the right direction. Please tell me what I'm doing wrong.

Here is a test routine I'm trying to learn from:


'12F675
_CONFIG
_INTRC
_OSC
_NOCLKOUT
_WDT_ON
_PWRTE_ON
_MCLRE_OFF
_BODEN_ON
DEFINE OSCCAL_1K 1

INCLUDE "modedefs.bas"
TX_Pin VAR GPIO.0 'To DB9 RX pin 2
RX_Pin VAR GPIO.1 'To DB9 TX pin 3

TRISIO.0 = 0 'Set GPIO.0 to output.
TRISIO.1 = 1 'Set GPIO.1 to input

ANSEL = 0 'disable ADCs
CMCON = 7 'disable comparator



MyText VAR BYTE [5]
tx_pin = 0 'inverted mode idle state

MyText[0]="H"
MyText[1]="E"
MyText[2]="L"
MyText[3]="L"
MyText[4]="O"





Pause 100 'OSC settle time...

loop:
SerOut tx_pin,N9600,["Waiting for ",MyText,13,10]
SerIn rx_pin,N9600,[STR MyText]
SerOut tx_pin,N9600,["I GOT IT...",10,13]
GoTo loop


Thanks for any help
Hi Sam, I tried to compile your code and that failed.
Looking at the code posted, and really not all that familiar with arrays,
I think you need to use serin2 as listed below, It compiles anyway.


__CONFIG
_INTRC
_OSC
_NOCLKOUT
_WDT_ON
_PWRTE_ON
_MCLRE_OFF
_BODEN_ON
DEFINE OSCCAL_1K 1

INCLUDE "modedefs.bas"
TX_Pin VAR GPIO.0 'To DB9 RX pin 2
RX_Pin VAR GPIO.1 'To DB9 TX pin 3

TRISIO.0 = 0 'Set GPIO.0 to output.
TRISIO.1 = 1 'Set GPIO.1 to input

ANSEL = 0 'disable ADCs
CMCON = 7 'disable comparator



MyText VAR BYTE [5]
tx_pin = 0 'inverted mode idle state

MyText[0]="H"
MyText[1]="E"
MyText[2]="L"
MyText[3]="L"
MyText[4]="O"





Pause 100 'OSC settle time...

loop:
SerOut2 tx_pin,N9600,["Waiting for ",STR MyText\5,13,10]
SerIn2 rx_pin,N9600,[STR MyText\5]
SerOut2 tx_pin,N9600,["I GOT IT...",10,13]
GoTo loop

That is about all I can do, let me know if it works
JS

Sam
- 30th November 2006, 01:26
Hi Joe,

Thanks for the reply, that does compile ok but it doesn't work,seems to keep sending data in a loop very fast by looking at the rx LED but nothing shows in hyperterminal.

skimask
- 30th November 2006, 03:57
Is there a level converter (MAX232 type) between the PIC and the PC?
If there is, change the N9600's to T9600. If not, your PC might have a problem receiving the 'weak' 5v RS232 coming from the PIC and you might have to use a MAX232 to get the PC to receive it. I know I almost have to use a MAX232 with my laptops and one of my newer desktops. But one of my 'old' desktops will take a 5v RS232 signal without a problem.
JDG

mister_e
- 30th November 2006, 04:32
Bad config fuse setting, 9600 baud, using internal OSC AND with Serout combination??? no big chance that it's going to work.

At least fix your config fuse setting, try with a lower baudrate first and use DEBUG.

Sure it's compile OK probably you're using PM to compile AND those


_CONFIG
_INTRC
_OSC
_NOCLKOUT
_WDT_ON
_PWRTE_ON
_MCLRE_OFF
_BODEN_ON
are considered as Label... not much!

Archangel
- 30th November 2006, 06:15
Bad config fuse setting, 9600 baud, using internal OSC AND with Serout combination??? no big chance that it's going to work.

At least fix your config fuse setting, try with a lower baudrate first and use DEBUG.

Sure it's compile OK probably you're using PM to compile AND those

Hello mister_e,
I compiled with MPASM, and didn't mess with his fuses except to add _ to config.
I tend to agree good luck getting any serout to work with internal osc, but as you see I missed that! Too busy fighting bad internet connection ;) also not familiar with 12F series, look like PIA to me. Glad you are helping him. MY question is, did I do the changes in the serin2 correctly?
JS

Archangel
- 30th November 2006, 06:25
Hi Joe,

Thanks for the reply, that does compile ok but it doesn't work,seems to keep sending data in a loop very fast by looking at the rx LED but nothing shows in hyperterminal.
Hi Sam
I can send data out from my keyboard using hyperterminal, but to save my butt I cannot receive any using it. Can you configure this with a resonator or a crystal instead of int osc, as mister_e pointed out?

no big chance that it's going to work.
JS

Sam
- 30th November 2006, 17:17
Thanks for the help so far,
I can send from pc to pic and rx from pic using the code below with the settings I first posted and the pic does reply "got it" when I enter an "f".

CODE:

loop:
SerOut tx_pin,N9600,["waiting for f ",10,13]
SerIn rx_pin,N9600,["f"]
SerOut tx_pin,N9600,["got it",13,10]
GoTo loop


This works most of the time. But yes, I will change to a external osc and I don't have to use a 12F675, I have some 16F628A's and some F84's.

I really need to have an example,any example of the correct syntax to recognize and reply to a defined string of char's.

Thanks again,I'm trying to get my brain around working with serial.

Sam

Archangel
- 30th November 2006, 23:51
Hi Sam,
check out this link. JS
http://www.picbasic.co.uk/forum/showthread.php?t=717&highlight=PARSE+STRING

skimask
- 1st December 2006, 03:51
Thanks for the help so far,
I can send from pc to pic and rx from pic using the code below with the settings I first posted and the pic does reply "got it" when I enter an "f".

CODE:

loop:
SerOut tx_pin,N9600,["waiting for f ",10,13]
SerIn rx_pin,N9600,["f"]
SerOut tx_pin,N9600,["got it",13,10]
GoTo loop


This works most of the time. But yes, I will change to a external osc and I don't have to use a 12F675, I have some 16F628A's and some F84's.

I really need to have an example,any example of the correct syntax to recognize and reply to a defined string of char's.

Thanks again,I'm trying to get my brain around working with serial.

Sam


If you're using the internal oscillator and it's messing up some of the time, switch to a lower baud rate. That might cure most of the problem. Also, try adjusting your OSC_CAL value. If you don't want to do that, use SEROUT2 instead of SEROUT. With that command, you can 'fine adjust' your baud to compensate for your oscillator being a bit out of whack.
I forget which-is-which, but I think if you get overrun errors, you're clock might be running fast, framing errors mean the clock is a bit slow (on the PIC that is).

JDG

Sam
- 2nd December 2006, 21:25
Thank you all for the advice you've given me!

I did switch from intrc to XT ceramic 4mhz and that did it! I've been able to do allot of the things that just wasn't working before changing to XT. I also did start at lower baud rates as advised here and increased them as I made sure things were working correctly.



Thanks and best regards,
Sam

mister_e
- 2nd December 2006, 22:29
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=881&d=1148640458">