PDA

View Full Version : SERIN2 Syntax



Filbert
- 16th April 2008, 14:43
Hello all,

I am very new to microcontroller programing so this is probably a simple question.

I am using an 18F2321 and I want to receive serial data to it using the SERIN2 command. The 18F2321 will receive a number in ASCII format at 1200 baud and I will need to convert it to decimal. I have successfully communicated with a Basic Stamp BS2 using the SERIN command. I just can't figure out why it isn't working in the 18F2321. The code compiles with no errors. My code is below. Thanks for the help.

DEFINE OSC 8
DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 1

Pin15 Con 15
Setting VAR Word
MotorState VAR Word
ValveState VAR Word

Main:
SERIN2 Pin15, 17197, 100, Main, [DEC Setting]
SELECT Case Setting
CASE Is < 255
MotorState = Setting
Case 300
ValveState = 0
Case 400
ValveState = 210
Case 500
ValveState = 255
END SELECT
HPWM 1, MotorState, 16000
HPWM 2, ValveState, 8000
Goto Main

skimask
- 16th April 2008, 14:50
Pin15 Con 15
........................
SERIN2 Pin15, 17197, 100, Main, [DEC Setting]

Pin 15 usage looks a bit suspect.
Try using an actual port value (i.e. porta.5 or whatever).
And 15 looks to be porta.7, which is OSC2. If you're using an external oscillator, this won't work. Even if you're using the internal oscillator, if it's not configured right, the pin won't work as advertised.

Filbert
- 16th April 2008, 15:26
That was a fast reply thank you.

According to the data sheet, pin 15 is PORTC.4 and my handy dandy cheat sheet said the same. I removed the "Pin15 Con 15" line and inserted PORTC.4 in the SERIN2 command line and it still didn't work. I am using the internal oscillator. Could that be the problem?

skimask
- 16th April 2008, 15:41
According to the data sheet, pin 15 is PORTC.4 and my handy dandy cheat sheet said the same. I removed the "Pin15 Con 15" line and inserted PORTC.4 in the SERIN2 command line and it still didn't work. I am using the internal oscillator. Could that be the problem?

Pin 15 may be PortC.4 to the PIC...
Pin 15 isn't PortC.4 to PBP (READ the PBP manual)

Internal oscillator - yep, sure could be the problem. But generally, 1200 baud works even when the osc is out in the weeds a bit.

AND...your SERIN2 line is giving you 100ms to send and fill a DEC variable. Can you type that fast?

Get rid of that motor stuff, plug in an LCD and watch what your inputs are doing, hook up some LEDs, do some troubleshooting. Don't just assume that anything works right.

Filbert
- 16th April 2008, 16:32
Thanks again for your help.

Since it works perfectly with the BS2 and the two languages are similar, I thought it would be an easy transition from one to the other.

skimask
- 16th April 2008, 17:32
Thanks again for your help.
Since it works perfectly with the BS2 and the two languages are similar, I thought it would be an easy transition from one to the other.
I suppose it's all easy...in theory...until you figure out it ain't so easy :)
The main thing is the manual. Most, if not all, of your differences are spelled out there in one way or another.

mister_e
- 16th April 2008, 21:40
When your PIC have an internal USART/EUSART... don't mess with DEBUG/DEBUGIN/SERIN/SERIN2... use HSERIN and that's it.


If you still want to use a specific pin.. use it's PORT name.. not PIN number...it's just unreadable and mix-up everybody for nothing



SERIN2 PORTA.7...........
SERIN PORTA.7............

or better

MySerialInput VAR PORTA.7
'
'
'
'
SERIN MySerialInput..............

Don't forget PIC have more interesting stuff than those stupid useless Stamps.. you MAY need to disable some feature to a specific pin prior to use it as Digital i/o. Few things like ADCs, comparators can cause some strange behaviours.

http://www.picbasic.co.uk/forum/showthread.php?t=561