DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 11
.... and mode 97 should give 9600 baud with SEROUT2. However, you would probably do yourself a favour by switching to a 20MHz crystal since PBP likes that better, all timings will be correct. 115200 baud works quite well with 20MHz and HSEROUT.
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 10
.... will give you 115200 with 20MHz.
Well, at last I have success! Thanks to all who pitched in to make this happen. I adjusted the values in the define statements as suggested.
I am still using 22.1184 XTAL. Here is the test code below.
Thanks again.......
Scott
DEFINE OSC 20 ' 20MHz oscillator (22.1184MHz)
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 115200
DEFINE HSER_SPBRG 11
TRISA = 0
TRISB = 0
TRISC = 0
START:
HSerout ["HELLO"]
Pause 500
GoTo START
End
Well, interesting. Now I am trying to take in the character at 9600 and resend at 115200. When I do this code below, my results are not what I want!
For example when I send the number 1, I receive an "a", send 2, I get an "f"
3 a "g", ect till I send 6, the sequence jumps to "n", "o".. Really strange.
I don't know if it is a timing issue or not???? Puzzled.
It was mentioned above that I could change the baud rate on the fly, How is that done? Could the issue be I have different baud rates on different pins, seems it should not matter. I'm lost..
ScottC
DEFINE OSC 20 ' 20MHz oscillator
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 115200 '115200 Baud Out
DEFINE HSER_SPBRG 11
DEFINE DEBUGIN_REG PORTB ' 9600,8,N,1 Serial In
DEFINE DEBUGIN_BIT 7
DEFINE DEBUG_BAUD 9600
DEFINE DEBUGIN_MODE 1
B7 VAR BYTE
'**********************************************
TRISA = 0
TRISB = %00000001
TRISC = 0
'********************************* READ SERIAL PORT
loop: While PORTB.7 = 1 'Wait for start bit
Wend
DebugIn [B7] ' B0 = input character
Pause 500
print: HSerout [B7]
GoTo loop ' Forever
Are you're still using the 22.1184MHz crystal?
DEBUGIN bit timing is calculated for 20MHz with DEFINE OSC 20.
yes,
I am still using 22.1184 XTAL. I undersatand what you are saying, from what info I gathered, this or 11.something, 1/2 of 22.1184, or an 18.432 xtal is what you want for error free reception. I am still new at this so I'm still in the learnig curve. But it makes sense what you are saying. I am going to try changing the SPBRG later in the program using DEFINE HSER_BAUD 9600, and DEFINE HSER_SPBRG 143 to change the valuse. I compiled it, have not tested yet, I'll get to in a bit see if that works. What do you think?
Scott
With HSERIN/HSEROUT you can change the data-rate by writing directly to SPBRG.
You can't change DEFINEs at run time, so just write to SPBRG directly if you want to change data-rates with HSEROUT/HSERIN.Code:Here: SPBRG = 129 ' 9600 @20MHz HSEROUT ["TEST AT 9600",13,10] PAUSE 10 SPBRG = 64 ' 19200 @20MHz PAUSE 5000 ' Time to switch terminal program from 9600 to 19200 HSEROUT ["TEST AT 19200",13,10] PAUSE 5000 GOTO Here
With DEBUG/DEBUGIN the data-rate & pins used are fixed, you can't change data-rates on the fly, and you'll want your osc frequency as close as possible to whatever you have it DEFINEed as.
Bookmarks