PDA

View Full Version : serout



mychangl
- 18th March 2007, 17:50
Hi,
Anyone out there can help me solve this problem ? i have been trying to get my pic 16F84 to control an external 33.6k serial modem.
The modem work fine with hyperterminal. But it doesn't work with PIC.

PortB.1 is connected to pin10 of MAX232 ( TTL in ) and MAX232 pin7 ( 232 out ) is connected to pin 3 of modem DB9.
Pin 4 & 6 of DB9 is shorted ( DTR & DSR ).
Pin7 & 8 of DB9 also shorted ( RTS & CTS )

CODE SAMPLE :

TRISB=%00000000 'PortB.0 & PortB.1 = output
Dialing VAR PORTB.0 'Set PortB.0 as Dialing indicator
Tx VAR PORTB.1 'Set PortB.1 as Transmit signal to modem
PORTB=%00000000

Pause 1000
MAIN :

High Dialing
SerOut Tx,t300,[65,84,72,49] ' Off Hook ATH1
Low Dialing
End


What is the catch ????

rhino
- 18th March 2007, 18:03
Try...
Include “modedefs.bas”


The Mode names (e.g. T2400) are defined in the file MODEDEFS.BAS.
To use them, add the line:
Include “modedefs.bas”
to the top of the PicBasic Pro program. BS1DEFS.BAS and
BS2DEFS.BAS already includes MODEDEFS.BAS. Do not include it again
if one of these files is already included. The Mode numbers may be used
without including this file.

mychangl
- 19th March 2007, 13:51
modedefs.bas is included but still doesn't work...

i also tried :
1. inverted TTL N300 to N2400
2. change Define Char_pacing 1000 to 10000

however it still not working...

HenrikOlsson
- 19th March 2007, 14:20
Hi,
What is the clock frequency and what do you use as the clock source? For serial communication to be reliable you really should use a X-tal. What baudrate did you set Hyperterminal to when testing the modem? 300baud?

/Henrik Olsson.

mychangl
- 20th March 2007, 11:15
I use 4MHz resonator. i did use the same type of resonator before when i did a serial comm project between 2 remote PIC 16F84 at 1200baud.

In Hyperterminal, i tried 300 baud, 1200 baud and 2400 baud. All working fine. The only difference i noticed with this baud rates is the speed and it is obvious when i type AT&V.
A modem should detect the baud rate automatical isn't ?

mychangl

HenrikOlsson
- 20th March 2007, 13:48
Hi,
Generally you should be fine with the resonator. Are you sure that the PIC is running? Blink a LED a few times at the beginning of the program to make sure. And if you can, try with a X-tal just to be sure.

You do have the PIC's ground and the modems ground connected don't you? The modem ground should be on PIN 5 in the DB9 but you didn't mention that in your original post.
I have no knowledge of AT commands so I can't help with that but assuming it's correct have you tried:


SerOut Tx,t300,["ATH1"] ' Off Hook ATH1

Also, is it possible that the modem needs a linefeed and/or carrage return at the end of the command?

/Henrik Olsson.

mychangl
- 20th March 2007, 14:55
the LED is blinking. i even put LED to monitor the serial output, it is flickering. Modem ground is connected to PIC gnd.

neither
SerOut Tx,t300,["ATH1"]
SerOut Tx,t300,["ATH0"]
SerOut Tx,t1200,["ATH1"]
SerOut Tx,t2400,["ATH1"]
SerOut Tx,t9600,["ATH1"]

work, i not sure about line feed or carriage.There is no information about linefeed and carriage found in any modem articles, even hyperterminal doue not require that..

Anyway, let me try

paul borgmeier
- 20th March 2007, 16:05
Something to try - see if you can get your pic to talk to hyperterminal (using your max232 setup as is). This might help you determine if the problem is closer to the PIC side or closer to the modem side.

mychangl
- 21st March 2007, 16:19
Thanks guys. i got the code....

it should has carriage return ( 13 ) after the command.

SerOut Tx,t9600,[65,84,72,49] ' Off Hook ATH1'
SerOut Tx,t9600,[13]

now i am looking into more functions eg connect to other modem...

Thx a lot !
Cheeeeers

HenrikOlsson
- 21st March 2007, 16:54
Hi,
Glad to hear you got it going!
A little tip: Put the carriage return on the same line as the 'command'


SerOut Tx,t9600,[65,84,72,49,13] ' Off Hook ATH1, CR

Should work the same and you'll save a couple of bytes for each instance. Also Serout....["ATH1",13] should work the same but makes the code easier to understand, to me atleast....YMMV.

Good luck with the project!

/Henrik Olsson.

mychangl
- 25th March 2007, 05:32
That is just the beginning...
["ATH1",13] work fine ! Thanks for all your suggestion.