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 support@ccsinfo.com

18F25K22 UART problem

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



Joined: 23 Apr 2009
Posts: 42

View user's profile Send private message

18F25K22 UART problem
PostPosted: Wed Oct 03, 2012 3:27 am     Reply with quote

hi

Interrupt does not work on both serial ports.
I never get an interrupt.

Tips are welcome

thanks

Code:

#use rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,DISABLE_INTS,STREAM=RFNETWERK)
#use rs232(baud=38400,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,DISABLE_INTS,STREAM=PC)

//----------------------------------------------------------------
#INT_RDA
void SerialDataAvailable()
{
     if(kbhit(RFNETWERK))
     {
      nGroeneLedsLevel++;
      bFlagUpdatePanelLeds = TRUE;
      ReadSerialData();
    }
     if(kbhit(PC))
     {
      nGroeneLedsLevel++;
      bFlagUpdatePanelLeds = TRUE;
      ReadSerialData();
    }
}
//----------------------------------------------------------------
//------------------------------------------------------------------------------
void main()
{
   //setup_oscillator (osc_8MHZ | OSC_PLL_ON);

   setup_uart(1);
   setup_uart(2);
   delay_ms(300);
   
   
   //-----------------------------------------------------------------------------------------------------------------------------------------------------
   set_tris_a (0xE3);
   set_tris_b (0x80);
   set_tris_c (0x80);
   set_tris_e (0XFF);   
   //-----------------------------------------------------------------------------------------------------------------------------------------------------
   disable_interrupts(INT_EXT);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_RDA2);
   disable_interrupts(INT_EEPROM);
   enable_interrupts(global);
   while (1)
   {
      for(lX=0;lX<=500;lX++)
      {
         set_pwm1_duty(lX);   
         delay_ms(10);         
      }
      output_bit(PIN_A2,input(PIN_A5)); // KNOP 1 RODE LED
      output_bit(PIN_A3,input(PIN_A7)); // KNOP 2 GELE LED
      output_bit(PIN_A4,input(PIN_A6)); // KNOP 3 GROENE LED
      delay_ms(20);

      output_bit(PIN_C0,input(PIN_A5)); // KNOP 1 RODE LED
      output_bit(PIN_C1,input(PIN_A6)); // KNOP 1 RODE LED

      delay_ms(500);
      PrintInfoToPC(123,456.789);

   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Wed Oct 03, 2012 3:40 am     Reply with quote

Er. Of course it won't. There are two separate interrupts for the two UARTs.

INT_RDA triggers to say a character is available/waiting on UART1. No point in testing kbhit, the character _is_ there.

For UART2, INT_RDA2 triggers. You are enabling this, but have no handler for it. Will crash the chip.

Get rid of 'DISABLE_INTS' in the RS232 definitions. This is to prevent interrupts from interfering with _software_ UARTs. You _want_ interrupts to occur.

Add 'ERRORS' to both RS232 definitions. This is _required_ when using the hardware UARTs, unless _you_ add error handling code to your handler.

You don't show your 'ReadSerialData' routine, but you'd not normally want the same routine for the two UARTs. The routine should read just _one_ character (this is all that is waiting for you), and exit ASAP, or it risks loosing data.

Best Wishes
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Oct 03, 2012 3:48 am     Reply with quote

Serial receive interrupts will only work with hardware UARTS. You don't say which PIC you are using: many have only one hardware UART. So we cannot tell whether both your UARTS are goign to be implemented in hardware or not.

If both UARTS are hardware, then they will have different interrupts, int_rda is for the first or only (hardware) UART. #int_rda1 and #int_rda2 are for both, in PICs that have two or more hardware UARTS.

Don't use kbhit() in serial receive (i.e. int_rda) ISRs. The interrupt TELLS you a character is available, there is no point in testing to see if there's one. Also, even if you don't need it (for example your buffer is full and you are ignoring the character) you must always read the character from the UART.

Only use set_tris if you are using fast IO on that port. CCS C handles port direction automatically for you by default. HOWEVER some PICs (generally lower pin count ones which share functions between pins) may need some pin allocation and in a very few specific cases *may* need a set_tris to get the ports to work correctly. Then again, low pin count PICs don't have two hardware UARTS...

All interrupts are disabled by hardware at reset, Therefore you only need to enablee the ones you intend to use. ONLY enable interrupts if you have a valid ISR to handle them, otherwise your code will crash.

Please use the code tags, using the Code button on the messge page, to preserve formatting in code.

RF Developer

PS: It appears I posted at much the same time as Ttelmah.
koenbielen



Joined: 23 Apr 2009
Posts: 42

View user's profile Send private message

Solved
PostPosted: Wed Oct 03, 2012 5:19 am     Reply with quote

Thanks for the info

tried it and it worked.
And also solved another problem with the getc, it had to be fgetc()

Thanks

PS : RF_Developer look at the topic, you see the PIC used
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