View previous topic :: View next topic |
Author |
Message |
Momboz
Joined: 03 Jun 2009 Posts: 29
|
#INT_RDA on PIC18F27K40 |
Posted: Thu Feb 16, 2017 2:34 am |
|
|
Trying to react on keystrokes from a serial terminal without any success.
No success means in my context that pin_A0 doesn't toggle.
I am using the latest compiler version 5.069 and my code is:
Code: | #include <18F27K40.h>
#device ADC=10
#use delay(internal=64MHz)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#INT_RDA
void RDA_isr(void) {
getc();
output_toggle(pin_A0);
}
void main() {
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE) { /* Do nothing */ }
} |
To be noted: sending strings to this serial terminal works fine. Reading strings from it does work as well. I assume my problem is with the interrupt settings. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 16, 2017 3:10 am |
|
|
You are generating a software UART. Look at the .LST file.
When you see MOVLW 08 near the start of a lengthy block of rs-232 code
you are looking at a loop for 8 data bits of a software (bit-banged) UART.
Software UARTs don't generate an #int_rda interrupt. Example:
Quote: | ....... #use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
000C0: BSF TRISC.7
000C2: BTFSC PORTC.7
000C4: BRA 00C2
000C6: MOVLW 08 // Means this is a software UART
000C8: MOVWF @00
000CA: CLRF @@1B |
You don't want that. You want a hardware UART. You have to tell the
compiler to use the hardware uart. For more modern PICs, this is done
with #pin_select.
Look how #pin_select is used in the following post for another K series PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=55786
Note the placement is above the #use rs232() line. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Thu Feb 16, 2017 9:41 am |
|
|
I would like to toss in that a good convention to handle HW vs SW UARTS is for HW uarts use:
Code: | #use rs232(UART1, stream=PORT1, baud=115200, ERRORS) |
and for SW uarts use
Code: | #use rs232(xmit=PIN_C6, rcv=PIN_C7, stream=PORT1, baud=115200, DISABLE_INTS) |
If the HW uart has multiple pin choices, then as PCM programmer says:
Code: |
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(UART1, stream=PORT1, baud=115200, ERRORS)
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Feb 16, 2017 9:53 am |
|
|
If you look at the little entry about #PIN SELECT at the top of the forum, you will see this being suggested.
The key 'good thing' about using the 'UART1' syntax, is it forces the code to connect to the physical hardware UART. If the pins of this are _not_ connected (so are selectable, and have not been selected), this will then generate a warning to use #PIN_SELECT. Helps to ensure you are talking to the hardware when you want to. Unfortunately the 'automated' operation of #USE RS232, to generate a software UART if it is not talking to the hardware, can be a little 'too smart' here. It's almost a pity that this doesn't generate an 'information' line in the compile, to say 'software UART being used'.... |
|
|
Momboz
Joined: 03 Jun 2009 Posts: 29
|
|
Posted: Thu Feb 16, 2017 2:36 pm |
|
|
Many many thanks to all of you guys.
I've learned about #pin_select (which I didn't know before) and my piece of software works fine now.
I would greatly support the view of making programmers aware about this by adding a note or remark when using #use rs232 directive (as suggested by Ttelmah). |
|
|
|