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

PIC16F88 cannot read RS232

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



Joined: 02 Nov 2007
Posts: 26

View user's profile Send private message

PIC16F88 cannot read RS232
PostPosted: Mon Dec 01, 2008 4:20 pm     Reply with quote

Hi...

I have a problem with a PIC16F88 and the #int_RDA interrupt.

I configured the PIC for 9600,8,N and while I can send (without any
problem) data out from the microcontroller, I have no reaction from it
when I send RS232 data into it.

My code:
Code:

//
//               PIC16F88
//
// RA3 = RXD
// RA1 = TXD
//
//                     _________  _________
//                  __|         \/         |__
//  DEL debug      |__|Ra2          41  Ra1|__| 9600 bps --->---
//                  __|                    |__
// --->-- 9600 bps |__|Ra3          40  Ra0|__|
//                  __|                    |__
//                 |__|Ra4            clkin|__| 11,0592 MHz in
//                  __|____                |__
//              +5V|__|MCLR/Vpp      clkout|__|
//                  __|                    |__
//               0V|__|Vss              Vdd|__| +5V
//                  __|                    |__
//                 |__|Rb0/int  Rb7/ICSPDAT|__|
//                  __|                    |__
//                 |__|Rb1          Rb6/PGC|__|
//                  __|                    |__
//                 |__|Rb2              Rb5|__|
//                  __|                    |__
//                 |__|Rb3              Rb4|__|
//                    |____________________|
//
#include <16F88.h>
#device adc=8
//#FUSES XT,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR,NOLVP,NOCPD
//#use fast_io(b)  //On ne veut pas barrer le TRIS (port I2C)
#FUSES EC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR,NOLVP,NOCPD
#FUSES
#use delay(clock=11059200,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A3,bits=8)
  //no master clear a5 (reset) ;cpd barrer eedata;nolvp lo-volt prog

/////////////////////////////////////////
void entree_rs232(void);               //
void rad(void);                        //
void aff_stream(int8);                 //
void ini_pic(void);                    // P R O T O T Y P E S
int1 a_0,a_1,a_2,a_3,a_4,a_5,a_6,a_7;  //
int1 carac_entre;                      //
int8 carac;                            //
int8 message;                          //
/////////////////////////////////////////


//#ZERO_RAM
//#int_RTCC

////////////////////////
#int_RDA              //
void RDA_isr(void)    //
{                     // The (in)famous interrupt that does NOT
   carac=getc();      // work!
   carac_entre=1;     //
}                     //
////////////////////////


///////////////////////////////////////////////////////////
void ini_pic(void)                                       //
{                                                        //
   setup_adc_ports(NO_ANALOGS|VSS_VDD);                  //
   setup_adc(ADC_OFF);                                   //
   setup_spi(FALSE);                                     //
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);              //
   setup_timer_1(T1_DISABLED);                           //
   setup_timer_2(T2_DISABLED,0,1);                       //
   setup_comparator(NC_NC_NC_NC);                        //
   setup_vref(FALSE);                                    //
   enable_interrupts(INT_RDA);                           //
   enable_interrupts(GLOBAL);                            //
   setup_oscillator(False);                              //
   port_b_pullups(true);                                 //
   output_a(0);                                          //
   output_b(0);                                          //
   set_tris_a(0b11111001);  // gauche=bit7, droite=bit0  //
   set_tris_b(0b11111111);  // gauche=bit7, droite=bit0  //
}                                                        //
///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
void aff_stream(int8 message)                                                //
{                                                                            //
   putchar(65);                                                              //
   delay_us(104);  // To add a second stop bit                               //
                                                                             //
   putchar(66);                                                              //
   delay_us(104);                                                            //
                                                                             //
   putchar(67);                                                              //
   delay_us(104);                                                            //
                                                                             //
   putchar(68);                                                              //
   delay_us(104);                                                            //
                                                                             //
   putchar(69);                                                              //
   delay_us(104);                                                            //
                                                                             //
                                                                             //
   if(message==0)                                                            //
   {                                                                         //
      putchar(48);                                                           //
      delay_us(104);                                                         //
   }                                                                         //
   if(message==1)                                                            //
   {                                                                         //
      putchar(49);                                                           //
      delay_us(104);                                                         //
   }                                                                         //
}                                                                            //
///////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
void main()                                                             /////
{                                                                       /////
   /*=-=*//*=-=*//*=-=*//*=-=*//*=-=*//*=-=*//*=-=*//*=-=*//*=-=*/      /////
   ini_pic();                                                           /////
                                                                        /////
   a_0=1; //                                                            /////
   a_1=1; //                                                            /////
   a_2=1; //                                                            /////
   a_3=1; // pour éviter l'envoi de chaînes                             /////
   a_4=1; // à la mise en marche.                                       /////
   a_5=1; //                                                            /////
   a_6=1; //                                                            /////
   a_7=1; //                                                            /////
                                                                        /////
   carac_entre=1;                                                       /////
                                                                        /////
   putchar(0xFF); // Pour initialiser la ligne RS232 à MARK             /////
                                                                        /////
   while(1)                    //                                       /////
   {                           //                                       /////
      if(input_state(PIN_B0))  //                                       /////
      {                        //                                       /////
         if(a_0==0)            //                                       /////
         {                     // Character stream is sent              /////
            aff_stream(0);     // on LO-HI transition                   /////
            a_0=1;             //                                       /////
         }                     //                                       /////
      }                        //                                       /////
      else                     //                                       /////
      {                        //                                       /////
         a_0=0;                //                                       /////
         delay_ms(100);        //                                       /////
      }                        //                                       /////
                                                                        /////
                                                                        /////
      if(carac_entre)            //                                     /////
      {                          //                                     /////
         delay_ms(50);           // Make the LED on pin 1 flash         /////
         output_high(PIN_A2);    // on #int_RDA                         /////
         delay_ms(50);           //                                     /////
         output_low(PIN_A2);     //                                     /////
         delay_ms(50);           //                                     /////
         output_high(PIN_A2);    //                                     /////
         delay_ms(50);           //                                     /////
         output_low(PIN_A2);     //                                     /////
         delay_ms(50);           //                                     /////
         output_high(PIN_A2);    //                                     /////
         delay_ms(50);           //                                     /////
         output_low(PIN_A2);     //                                     /////
         delay_ms(50);           //                                     /////
         output_high(PIN_A2);    //                                     /////
         delay_ms(50);           //                                     /////
         output_low(PIN_A2);     //                                     /////
         delay_ms(50);           //                                     /////
         output_high(PIN_A2);    //                                     /////
         delay_ms(50);           //                                     /////
         output_low(PIN_A2);     //                                     /////
         carac_entre=0;          //                                     /////
      }                          //                                     /////
   }                                                                    /////
}                                                                       /////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////


I checked everything I could see. The crystal is a 11.0592 MHz (9600 * 1152) and I get my data out at a precise frequency (9600 +/- 10 bps) despite my raw way to add a second stop bit! I checked my interrupts (GLOBAL and #int_RDA), I've read the info. about #int_RDA in the manual and tested with both CCS 4.074 and 3.249.

My test circuit does (is supposed to...) flash an LED on pin 1 when an RS232 character is sent to the PIC. I've checked the waveform on pin 2 (RS232 input) and it's okay (idle at MARK (+5V) and levels ok, BTW, it's fed by a MAX232). I also changed the RS232 input pin (along with it's TRIS) w/o any success.

Did anyone ever get that problem ? and how did you solve it ?

Thanks for your attention.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 01, 2008 4:34 pm     Reply with quote

Quote:

#use rs232(baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A3,bits=8)

#int_RDA
void RDA_isr(void)
{ // The (in)famous interrupt that does NOT work!

carac=getc();
carac_entre=1;
}

#int_rda only works with the hardware UART. To use #int_rda, change
your #use rs232() statement to use pins B5 and B2 for Tx and Rx.
Also change your hardware connections to use those pins.
PICman



Joined: 02 Nov 2007
Posts: 26

View user's profile Send private message

PostPosted: Mon Dec 01, 2008 9:38 pm     Reply with quote

Wow!

Thanks a lot !!!!

I'll try that tomorrow ! That completely make sense !

Again, thanks !
Guest








PostPosted: Tue Dec 02, 2008 7:36 am     Reply with quote

IT WORKED !

I just tried it and everything's okay !

Thanks PCM Programmer !
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