CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#INT_RDA on PIC18F27K40

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

#INT_RDA on PIC18F27K40
PostPosted: Thu Feb 16, 2017 2:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 3:10 am     Reply with quote

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: 1358

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 9:41 am     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 9:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 2:36 pm     Reply with quote

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).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group