|
|
View previous topic :: View next topic |
Author |
Message |
kiewic
Joined: 24 Apr 2010 Posts: 10
|
Can I enable INT_RDA interruption without XMIT option? |
Posted: Sun May 16, 2010 7:37 pm |
|
|
Hi. I apologize for bothering you so much. But as you can see, I'm new with this.
I have an RFID reader connected to my pic. It only sends data and don't receive data. So, I have only set the RCV pin. It also uses an ENABLE pin. I'm using the follwing program.
I'm trying to use the INT_RDA interruption. but it isn't working. Can you see any problem?
Code: |
#include <18F2550.h>
#device adc=8
#FUSES NOWDT //WDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL //HS //HSPLL //Internal RC Osc RC
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //No brownout reset NOBROWNOUT
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //No Power Up Timer NOPUT
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) NOXINST
#FUSES PLL5 //Divide By 12(48MHz oscillator input) PLL12
#FUSES CPUDIV1 //System Clock by 4 CPUDIV4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=48000000)
#include "lcd.c"
#use rs232(baud=2400, rcv=PIN_C7, ENABLE=PIN_A1)
int yupi;
#INT_RDA
void isr_rda(void) {
yupi = 1;
}
void main()
{
// LCD Screen
lcd_init(); // Always call this first.
lcd_putc("\fWelcome!\n");
delay_ms(500);
// Interrupts
yupi = 0;
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(yupi == 0) delay_ms(5000);
// LED
lcd_putc("\fYeah!\n");
output_high(PIN_C1);
while(1);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 16, 2010 7:51 pm |
|
|
If you don't specify both 'xmit' and 'rcv' pins in the #use rs232()
statement, the compiler will create a software UART. It is doing that
in your program. That's why #int_rda doesn't work.
Also, in the #int_rda, you must put in a getc() or fgetc() statement
to get the incoming characters. If you don't, the #int_rda interrupt
will continuously occur and your program will lock up. |
|
|
kiewic
Joined: 24 Apr 2010 Posts: 10
|
Thank you very much! |
Posted: Mon May 17, 2010 1:20 am |
|
|
Thank you very much!
I set the XMIT pin to PIN_C6, although physically there's nothing connected to that pin.
Code: | #use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7, ENABLE=PIN_A1) |
And also I get the incoming character.
Code: | #INT_RDA
void isr_rda(void) {
char c;
c = getc();
yupi = 1;
} |
Thanks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon May 17, 2010 2:39 am |
|
|
You can actually use the XMIT pin, even though it is 'in' the #USE RS232 line.
Two different 'ways'.
First is that you can use the pin as an input. If you do, when the TRIS goes to '1', it overrides what the UART is doing, and the pin will behave as normal.
Second is that you can turn off the transmit component of the UART, with:
Code: |
#byte TXSTA=(0xFAC)
#bit TXEN=TXSTA.5
#define UART_TX_ON TXEN=1
#define UART_TX_OFF TXEN=0
#USE RS232(baud=2400, xmit=PIN_C6, rcv=PIN_C7, ENABLE=PIN_A1)
//Then in your code
UART_TX_OFF;
//Now you can use C6 as normal
|
If you don't 'need' the pin, then this doesn't matter, but if you want the extra pin, turning off the transmit component, is easy.
When you add the #use RS232, the compiler adds the initialisation bytes to the registers to set this up, but nothing else. The actual 'transmit' code, doesn't get loaded, untill you use a putc. So once you turn off the transmit enable bit (as shown above), everything should be 'hunky dory'.
Best Wishes |
|
|
kiewic
Joined: 24 Apr 2010 Posts: 10
|
Thanks Ttelmah |
Posted: Sun May 23, 2010 9:24 pm |
|
|
Thanks Ttelmah, perfect tip, it's very useful. |
|
|
|
|
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
|