pasini
Joined: 12 Dec 2005 Posts: 50 Location: Curitiba - Brazil
|
USB + UART(RS232) Interrupt |
Posted: Tue Dec 05, 2006 7:11 pm |
|
|
Hi All,
MPLAB 7.41 CCS 4.005
PIC18F2550
I am trying to read a character from the UART (RS232 with MAX232) that comes from my equipo and send it to the USB. USB is working fine and data is reaching the pins of the microcontroller. Using polling with kbhit() I receive data but not with the serial interrupt.
The problem is that the serial interrupt is not being fired. Why is it ? What am I doing wrong ? I prefer using interrupts to using polling.
Thanks for any help.
Pasini
My codes are:
WORKING (POLLING)
Code: | #define __USB_PIC_PERIF__ 1
#include <18F2550.h>
#device *=16
#device ADC=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,CPUDIV1,VREGEN,PLL5
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=MODEM)
#include <usb_cdc.h>
#include <STDLIB>
#define OK 1
#define NOK 0
int1 flag=0;
char bufrx[100];
int8 pointer=0;
int8 status=NOK;
void main(void)
{
char carac_usb;
char carac_rs232;
int8 c=0;
usb_init();
while(!usb_cdc_connected());
printf(usb_cdc_putc,"Usb READY\n\r",c++);
while(1)
{
if(kbhit(MODEM))
{ carac_rs232 = getc(MODEM);
usb_cdc_putc(carac);
}
if(usb_cdc_kbhit())
{
carac_usb = usb_cdc_getc();
putc(carac_usb);
}
}// End While
}// End Main
|
NOT WORKING (INTERRUPT)
Code: |
#define __USB_PIC_PERIF__ 1
#include <18F2550.h>
#device *=16
#device ADC=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,CPUDIV1,VREGEN,PLL5
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=MODEM)
#include <usb_cdc.h>
#include <STDLIB>
#define OK 1
#define NOK 0
int1 flag=0;
char bufrx[100];
int8 pointer=0;
int8 status=NOK;
#INT_RDA
void RDA_isr(void)
{
if(flag)
{ bufrx[pointer] = fgetc(MODEM);
if( (bufrx[pointer] == '\n') || (bufrx[pointer]=='\r'))
status = OK;
pointer++;
}
}
void main(void)
{
char carac_usb;
char carac_rs232;
int8 c=0;
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
usb_init();
while(!usb_cdc_connected());
printf(usb_cdc_putc,"Usb READY\n\r",c++);
while(1)
{
if(status==OK) // PARSE DATA
{ printf(usb_cdc_putc,"%s",bufrx);
memset(bufrx,0,100);
pointer=0;
}
}// End While
}// End Main |
|
|