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

16f877 and rs232... pic will not receive data

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



Joined: 16 Dec 2005
Posts: 2
Location: Switzerland

View user's profile Send private message Visit poster's website

16f877 and rs232... pic will not receive data
PostPosted: Fri Dec 16, 2005 1:56 pm     Reply with quote

hi there

i'm absolutly pic beginner and have a big problem with the pic to receive datas from the pc.
i used the pic16f877 with a max232 driver, the serial port of pc pins (dtr- dsr, rts-cts) are shorted.
to show the tx-signal, i used a led with resistor and i see datas go trough the max232 driver from the pc to the pic.

a simple testprogram like

Code:

while(1)
{
    sign=getc();
    output_high(PIN_B0);
    delay_ms(500);
    output_low(PIN_B0);
    delay_ms(500);
}


fail.
the pic does'nt receive data.

data send from pic to pc will work...

i've read in this board that a lot of users have problems ( *smile* i'm not alone with rs232 problems) with the rs232, but have not found the resolution for my problem.

to make sure that the pic and the rs232 driver are'nt the problem, i've changed them with another, but the pic does'nt receive datas again Twisted Evil

here is the source code of my little program was updated when i've read a possible resolution (but does'nt work)

Code:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N, ERRORS)

#define BUFFER_SIZE 15

#bit C7TRIS=0x87.7 //set the RX bit correct

char rxdata[BUFFER_SIZE];
int index         = 0;
int idata_valid      = 0;
int istreamcomplete   = 0;
int switchy = 1;

void blinky(int delayms) //delayms make a delay in milliseconds
{
   if( switchy==0 )
   {
      output_high(PIN_B0);
      switchy = 1;
   }
   else
   {
      output_low(PIN_B0);
      switchy = 0;
   }
   delay_ms(delayms);
}

//ser. interrupt routine
#int_RDA
RDA_isr()
{
   blinky(0);   //call blinky without delay

   if( index<BUFFER_SIZE )         // buffer overflow ?
   {
      char rcvd = 0;
      rcvd = getc();            // get sign from RS232
      
      if( rcvd==91 )            // if sign=="[", begin record
      {
         index = 0;
         idata_valid = 1;
      }

      if( idata_valid==1 )      // if data valid
      {
         rxdata[index]=rcvd;      //push sign into buffer
         index++;
         if( rcvd==93 )         // if sign=="]", stop record
         {
            idata_valid = 0;
         }
         if( index>BUFFER_SIZE )
         {
            idata_valid = 0;
         }
         if( !idata_valid )
         {
            istreamcomplete = 1;//   buffer has stored data
            index   = 0;
         }
      }
   }
}

void startup()                  // set all devices
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   
   set_tris_a(0);
   set_tris_b(0);
   
   C7TRIS = 1;
}

void deletebuffer()               // delete buffer
{
   int n = 0;
   istreamcomplete = 0;
   for( n=0; n<15;n++ )         // why does'nt with BUFFER_SIZE ?
   {
      rxdata[n] = 0;
   }
}

void main()
{
   startup();

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   while (1)
   {
      int n = 0;
      
      blinky(75); // let led blink all 75ms

      if( istreamcomplete==1 )         // if buffer has data stored
      {   
         disable_interrupts(INT_RDA);   // disable serial interrupt
         
         blinky(1000);               //give a optical signal for stored data
         blinky(500);
         
         if( rxdata[0]=91 )            // first sign must be a "["]
         {
            for( n=0; n<15;n++ )      // send stored buffer data back to pc
            {
               putc(rxdata[n]);
            }   
         }
         
         deletebuffer();               // delete buffer

         enable_interrupts(INT_RDA);      // enable serial interrupt
      }
   }
}



have any here suggestions or ideas why the pic does'nt receive datas ?

with best regards from snowy switzerland
rené
_________________
I'm pic beginner... don't beat me about my questions ;-)
and
sorry for my bad english!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 16, 2005 2:14 pm     Reply with quote

Quote:
a simple test program like

while(1)
{
sign=getc();
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
delay_ms(500);
}
fail. The pic doesn't receive data.


Does your test program look like the one shown below ?
If it fails, the problem could be:
1. The PIC is not programmed properly. What is your programmer ?
(Example: Microchip ICD2, or PicStart-Plus, etc.)
2. Your terminal program which runs on your PIC, must be set for
4800 baud, with 8 bits and no parity. Is it set properly ?
3. It's possible that your RS-232 connections are not correct.
For DB-9 connectors, you need these 3 connections:
Code:

PIC      PC
DB9      DB9
pin      pin
 2   to   3
 3   to   2
 5   to   5   (this is the common ground connection)


Here is your test program. The LED should turn on for 500 ms when
a character is received.
Code:
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N, ERRORS)

void main()

char sign;

while(1)
{
    sign=getc();
    output_high(PIN_B0);
    delay_ms(500);
    output_low(PIN_B0);
    delay_ms(500);
}
René



Joined: 16 Dec 2005
Posts: 2
Location: Switzerland

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 16, 2005 4:16 pm     Reply with quote

hi pcm-programmer

Quote:

Does your test program look like the one shown below ?


yes

Quote:

If it fails, the problem could be:
1. The PIC is not programmed properly. What is your programmer ?
(Example: Microchip ICD2, or PicStart-Plus, etc.)


i use the warp13 programmer from here

Quote:

2. Your terminal program which runs on your PIC, must be set for
4800 baud, with 8 bits and no parity. Is it set properly ?


yes.

Quote:

3. It's possible that your RS-232 connections are not correct.
For DB-9 connectors, you need these 3 connections:


the connections are set correct.

i've found the mistake, why the pic does'nt receive datas Embarassed

the resistor (240ohm) on the (pc) tx-signal (you remember... show the tx signal with a led) was a tad small... now i take a resistor with 480ohm and... it work. with your code turn the led on and off Very Happy

i'm very happy that's work.

thanks a lot for your help

regards
rené
_________________
I'm pic beginner... don't beat me about my questions ;-)
and
sorry for my bad english!
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