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

18F4550 dual uart interrupt problem

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



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

18F4550 dual uart interrupt problem
PostPosted: Mon Nov 14, 2011 3:25 pm     Reply with quote

Hi to all.
I have a 18F4550 internal osc 8MHZ , CCS ver 4.108. with dual serial, I can send data in both serial ports but I can only receive in one of them (the hardware one)
the led blinks when I uncomment the 4 lines in main.
I tried but no success so far.
Thanks a lot


here is the code
Code:


#include <18F4550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#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)
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV1                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES ICPRT                    //ICPRT enabled

#use delay(int=8000000)

#use rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors,stream=sensor)
#use rs232(baud=38400,parity=N,xmit=PIN_D6,rcv=PIN_D7,bits=8,errors,stream=zigbee)

int1 init (void);

int1 init (void){

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   //setup_psp(PsP_DISABLED);
   //setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,1,10); // Interrupt every 10us
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   enable_interrupts(INT_RDA);
   //enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);

   return 0;
}

////////////////////////////////////////////////////////////////////////////////


#ZERO_RAM
#define LED PIN_C2

char c;

#int_RDA
void RDA_isr(void){ 
   c=getc();
         
}

void RDA0_isr(void) {
   if (kbhit(zigbee))
   c=getc();
   putc (c);
   output_toggle (LED);
     
}


void main(){
   
   init();
   output_low (LED);

   while (TRUE) {
   
     
      //output_high (LED);
      //delay_ms (50);
      //output_low (LED);
      //delay_ms (250);
      //output_toggle (LED);
   }
 
}

ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Nov 14, 2011 3:36 pm     Reply with quote

Hi,

Interrupts only fire on the hardware serial port. You'll need to 'poll' the software serial port to determine when data is present. Alternatively, you can connect the Tx line of Zigbee to the 'External Interrupt' pin of the PIC and use the 'Int_Ext' interrupt handler. It's not quite the same as the Int_RDA interrupt (it has no character buffering), but it may do what you want. Another option is to use a PIC with two hardware serial ports!

John
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Mon Nov 14, 2011 6:27 pm     Reply with quote

thanks a lot, good tip.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Nov 14, 2011 7:18 pm     Reply with quote

I have working code that can use the int on change B port lines for software EUSuart - BUT- you are always at severe risk of character distortion if there are ANY other interrupts enabled. You might want to think of those DUAL hardware serial PICs if this is going to be a real product.

Code:

#include <16f818.h>
#include <stdlib.h>
#Fuses EC_IO,NOWDT,PUT,
#fuses MCLR,BROWNOUT,NOLVP,CPD,NOCPD,
#fuses WRT,NODEBUG,CCPB3,NOPROTECT
#use delay( clock=4915200)
#use rs232(baud=9600 , xmit=PIN_B1, rcv=PIN_B0, sample_early)
#use fast_io(A)
#use fast_io(B)

#bit  T0IF    = 0x0B.2  // flag in INTCON reg
#define BUFFER_SIZE 16
BYTE RISR_out;      // global background newchar from ISR BACKGND buffer
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#define bkbhit (next_in!=next_out)

void bgetc(void) {
   RISR_out=buffer[next_out];    // NOTE : using GLObal return char variable
  ++next_out;
  if (BUFFER_SIZE==next_out) next_out=0;
}

void SIsr_INIT(void){
    clear_interrupt( int_ext );
    EXT_INT_EDGE(H_TO_L);
    enable_interrupts(int_ext);
    enable_interrupts(global);
}

#int_ext
   void serial_isr() {
   int t;
   buffer[next_in]=getc(); t=next_in;
   ++next_in
   if (BUFFER_SIZE==next_in) next_in=0;
   if(next_in==next_out)  next_in=t;           // Buffer full !!

}

//***********************************
void InitHDW ( void ) {
//***********************************
     output_a (0); output_b (0);  set_tris_a (0xFF);  //  - all INPUT
     setup_timer_0( RTCC_DIV_64);  // set for rollovers ~12 ms
      set_tris_b (0b00000001);  output_b (0);
}
//===================================
void main()
{
    char v;  char t;  unsigned int8 a;   unsigned int8 b;
    InitHDW();
    SIsr_INIT();
    printf ("*Hello*\r");  // just check output
    delay_ms(10000);  // delay to let me send a packet in
 
    while (1) {           // now get AND send at same time
      a=next_in;          // get mark of buffer position
      T0IF = 0; b=3;      // clear t0if and do 3x12 MS  +/-
      while(b){           // TIMER0 just rolls over endlessly
             if (  T0IF  )  {   // not using INTS - just watching timer
                --b;  T0IF=0;
                if (!b && a==next_in ){ // unload IF no NU chars R caught
                   //              your (safer) xmit routine here
                   while (bkbhit){ bgetc(); putc(RISR_out);}  //simple test

                }  // Implied ELSE - keep waiting
             } // END : IF t0if
       } //       END : WHILE B
    }  //         END : while  1
}
//******
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Mon Nov 14, 2011 7:22 pm     Reply with quote

GREAT!!! and after I made my board I received today PIC with dual uart so.. I Will go for the hardware option, thanks a lot and I will try anyway the soft method so I get familiar with the option.... long learning curve hahhahhah
thanks so much for the concern, very kind
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