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

USB + UART(RS232) Interrupt

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



Joined: 12 Dec 2005
Posts: 50
Location: Curitiba - Brazil

View user's profile Send private message Send e-mail

USB + UART(RS232) Interrupt
PostPosted: Tue Dec 05, 2006 7:11 pm     Reply with quote

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
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Dec 05, 2006 8:39 pm     Reply with quote

Just quick off the top of my head I would say its this line right here.
Code:
   if(flag)
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