PDA

View Full Version : SERIN2 Question



eoasap
- 30th December 2005, 01:43
I am using a 14.7456 MHz crystal, defined as 16 in PBP and am having problems using SERIN2 command. could this be due to the difference in crystal?

DynamoBen
- 30th December 2005, 02:09
We will need a couple of pieces of information.

What baud rate are you using? What is not working about it?

Yes the define being different than the actual crystal speed could play a large part.

Charles Linquis
- 30th December 2005, 03:15
Because your frequency isn't 16Mhz, your baud rate will be not what you expect. Look at the data sheet for your chip. You will have to use the formula provided in the datasheet to set the SPBRG register yourself. Don't forget to add 16384 to the number if you are using INVERTED mode.

Charles Linquis
- 30th December 2005, 05:37
I apologize - I am so used to HARDWARE serial ports that I forgot that SPBRG has nothing to do with SERIN2/SEROUT2.

You will have to go to the PBP manual and choose the right value for your new XTAL frequency. Page 137 of the PBP manual states that you should use the value (1000000/baud)-20 as the value to use for MODE.


Since your Xtal is lower in frequency than your DEFINE, your baud rate will be too low. You will have to configure the MODE to give you a higher baud rate than nominal. For example: If you are running 9600 baud, the formula would indicate that MODE should be 84, but since you are actually running at 14.7456Mhz, which is 92.2% of 16, then you should set your baud rate to be 1/92.2% = 1.0844 X 9600 Baud = 10410 baud. Instead of setting the MODE to 84, you would set it to 76. The actual baud rate will be 9600.

eoasap
- 30th December 2005, 14:05
Charles, that did the trick! i found the formula, but i mistakenly did it the other way and got 93 instead of 74. i think that fixed the problem. thank you!
still not sure if it's right, but i'm getting ascii numbers back like i believe i'm supposed to. Also each time through the program i get the same values returned, which also should happen. (more in post below this)

eoasap
- 30th December 2005, 14:12
DynamoBen, rate is 9600 baud. i'm communication (or trying to) with a FAT16 chip that for now, is supposed to simply reset and send back a string. this chip comes pre-programmed and transmits at 9600 baud.

here is the relevent code i have:

'PIC18F8722
DEFINE OSC 16 'when actually its 14.7456mhz
ASM
__CONFIG _CONFIG1H, _OSC_HS_1H
ENDASM

gosub alfat_reset
.... main code ....


ALFAT_RESET:
LCDOUT CMD, CLR 'Clear LCD Screen
SEROUT2 ALFAT_RX,76, ["RS OK",13]
; SEND ALFAT RESET STRING
READ2:
LCDOUT CMD, CLR
SERIN2 ALFAT_TX , 76, [BUFCHAR]
LCDOUT BUFCHAR
PAUSE 1000

RETURN

eoasap
- 1st January 2006, 15:26
after the first initial send "RS OK" and receive "BL" (both work fine), it seems like any command after that the first character is dropped and prints the 2nd char. I've tried speeding up the baud rate, but that doesn't work. any ideas ?

eoasap
- 2nd January 2006, 15:43
the baud rate is accurate according to the formula also (assuming the xtal is reported speed, haven't been able to check on a scope). could this be solved by adding a pullup resistor on the transmit lines ?