PDA

View Full Version : Interrupt Driven Serial Input using DT_Ints?



circuitpro
- 10th August 2010, 01:37
Can someone please point me to a link or example of how to make an interrupt-driven serial input buffer (hserin) for use with DT_Ints? I have had an interrupt jump to and receive an entire string of characters, but I've got too much going on for that, and will have to receive the string one character at a time, and put the command together when there's time. Any example would get me started. Thanks

Darrel Taylor
- 10th August 2010, 02:07
Here's one where I modified Joe's serial backback program for use with DT_INTS.

http://www.picbasic.co.uk/forum/showthread.php?t=4972&p=28336#post28336

circuitpro
- 10th August 2010, 03:07
Thanks very much, Darrel!

circuitpro
- 11th August 2010, 21:17
I am having some kind of issue getting these two uarts set up right. I'm using a PIC18F6722 running at 40MHz. UART1 runs perfectly fine at 115K, but UART2 just can't hack it. (If I lower the baudrate to 57600, it works fine). Besides setting the pin directions, I am using the setup resulting from the PIC Multicalc as follows:


'EUSART 1 (RS422 LINK)
DEFINE HSER1_RCSTA 90h
DEFINE HSER1_TXSTA 24h
DEFINE HSER1_CLROERR 1
DEFINE HSER1_SPBRG 86
SPBRGH1 = 0
BAUDCON1.3 = 1

'EUSART 2 (RS485 LINK)
DEFINE HSER2_RCSTA 90h
DEFINE HSER2_TXSTA 24h
DEFINE HSER2_CLROERR 1
DEFINE HSER2_SPBRG 86
SPBRGH2 = 0
BAUDCON2.3 = 1


I am not doing anything fancy, just trying to get both ports to transmit and receive at 115k - one at a time. No interrupts, nothing fancy.

Can anyone tell me why HSERIN2 fails to work when HSERIN1 works at this baudrate?

Darrel Taylor
- 11th August 2010, 21:59
I'm not sure how you got EUSART1 working.

There are no HSER1_ defines.
They are just HSER_ for the first EUSART, and HSER2_ for the second.

circuitpro
- 11th August 2010, 22:13
The datasheet for the pic just refers to TCSTAx, and at first I was setting them up with HSER_RCSTA and HSER2_RCSTA, but out of mass frustration, thought I would see if it should really be HSER1 & HSER2. (Once again, it's logical, but wrong!)

Do you see any reason uart2 isn't working at 115k?

Darrel Taylor
- 12th August 2010, 01:51
Do you see any reason uart2 isn't working at 115k?

From a software point of view, no.
PBP does exactly the same thing with both USARTS, which looks like this ...
Blue is EUSART1.
Green is EUSART2.

000000 01183 ORG RESET_ORG ; Reset vector at 0
000000 EF13 F000 01193 goto INIT ; Finish initialization
02343 HSEROUT CLRWDT? ; Keep Watchdog clear
000004 0004 M clrwdt
000006 A89E 02344 btfss PIR, TXIF ; Wait till ready
000008 D7FD 02345 bra HSEROUT
00000A 6EAD 02369 movwf TXREG ; Send the char
00000C 80D8 02370 bsf STATUS, C ; Set no timeout for Serout2mod
00000E EF10 F000 02371 goto DUNN ; That's it
02567 HSEROUT2 CLRWDT? ; Keep Watchdog clear
000012 0004 M clrwdt
000014 A8A4 02568 btfss PIR3, TX2IF ; Wait till ready
000016 D7FD 02569 bra HSEROUT2
000018 6E6D 02593 movwf TXREG2 ; Send the char
00001A 80D8 02594 bsf STATUS, C ; Set no timeout for Serout2mod
00001C EF10 F000 02595 goto DUNN ; That's it
000020 0100 07799 DUNN movlb 0 ; 1 Reset banks to 0
000022 0004 M clrwdt
000024 0012 07801 return ; 2 Done
000026 07815 INIT
000026 0E56 M movlw low (86)
000028 6EAF M movwf SPBRG
00002A 0E24 M movlw low (24h)
00002C 6EAC M movwf TXSTA
00002E 0E90 M movlw low (90h)
000030 6EAB M movwf RCSTA
000032 0E56 M movlw low (86)
000034 6E6F M movwf SPBRG2
000036 0E24 M movlw low (24h)
000038 6E6C M movwf TXSTA2
00003A 0E90 M movlw low (90h)
00003C 6E6B M movwf RCSTA2
00003E 07852 main
00003E 6A7F M clrf SPBRGH1
000040 867E M bsf BAUDCON1, 003h
000042 6A7D M clrf SPBRGH2
000044 867C M bsf BAUDCON2, 003h
000046 0E00 M movlw 000h
000048 DFDD M rcall HSEROUT
00004A 0E00 M movlw 000h
00004C DFE2 M rcall HSEROUT2


Which leaves hardware.
Something with the 18F6722? (doubtfull). Nothing in the errata sheet.
Extra capacitance on the PCB or serial cable. Bad cable?
<strike>Not enough capacitance on the MAX232?</strike> OOPS, RS422/RS485 ... no MAX232

Hard to tell.

circuitpro
- 12th August 2010, 02:40
That's very helpful - Thanks! It's going directly to a 75ALS180 (RS485), and the signal looks good on a scope, so I'll do some more testing - focusing on hardware now.