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

Problem in uart of pic16F877A!

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



Joined: 07 Feb 2011
Posts: 21
Location: Turkey

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

Problem in uart of pic16F877A!
PostPosted: Thu Mar 03, 2011 3:04 am     Reply with quote

Hello all!

I am trying to communicate two pics via rf. While doing this I am successful with pic18f4550, however when I have change the code to work with pic16f877a it is not working. I am looking at the voltage levels in tx and rx pins of the pics. While using pic18f4550 and while sending data (transmitter side) there is 5 v in tx pin of the pic, and while receiving data (receiver side) 3.3 volt in rx pin of the pic. With this configuration I can send data via rf. However While using pic16f877a and while sending data (transmitter side) there is 2.6 v in tx pin of the pic, and while receiving data (receiver side) 2.5 volt in rx pin of the pic. What can be the problem? Even I can not send data with a cable connected to tx-rx pins of the pics. I suspect it is related with voltage levels. Do I have to use a max232 between pic and rf module to overcome this issue?

Necessary part of the codes:

Transmitter side:
Code:

#include <16f877A.h>
#include <stdlib.h>
#include <string.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=600, xmit=PIN_C6, rcv=PIN_C7, stream=rf) 
                                                                 
#include <flex_lcd.c>                                           
#include <em4095.c>                                     
#include <em4102.c>
#byte portb = 0x06                                                                                                 
#use fast_io(b)

...

void main(){
   setup_adc_ports ( NO_ANALOGS ) ;         
   setup_adc ( ADC_OFF ) ;
   setup_psp ( PSP_DISABLED ) ;
   setup_spi ( FALSE ) ;                   
   setup_timer_1 ( T1_DISABLED ) ;
   setup_timer_2 ( T2_DISABLED, 0, 1 ) ;                 
   enable_interrupts ( INT_RB ) ;
   enable_interrupts ( global ) ;                                                 
   
   lcd_init ( ) ;
   rf_init();    //rfid yüklemesini yap
   rf_powerUp();
                                                             
   port_b_pullups(TRUE);             
   output_b(0xf0);
   set_tris_b (0xf0); // B4 - 7 input B0 - 3 output
   oldBState=portb;
   
   set_tris_a(0b00000010);


receiver side:
Code:

#include <16F877A.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)                                     
#use rs232(baud=600, xmit=PIN_C6, rcv=PIN_C7, stream=rf)                                   

#include <flex_lcd.c>

...

void main(){                                                                                                           setup_adc_ports ( NO_ANALOGS ) ;           
   setup_adc ( ADC_OFF ) ;                             
   setup_psp ( PSP_DISABLED ) ;                         
   setup_spi ( FALSE ) ;         
   setup_timer_1 ( T1_DISABLED ) ;                                                         
   setup_timer_2 ( T2_DISABLED, 0, 1 ) ;                             
   disable_interrupts ( global ) ;                                                 
                                                                 
   lcd_init ( ) ;
   set_tris_a (0x08);
altanonat



Joined: 07 Feb 2011
Posts: 21
Location: Turkey

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

PostPosted: Thu Mar 03, 2011 6:27 am     Reply with quote

any ideas?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 03, 2011 5:19 pm     Reply with quote

Remove the RF modules and connect the two PICs together. See if you
can make the PICs talk to each other without the RF modules.
altanonat



Joined: 07 Feb 2011
Posts: 21
Location: Turkey

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

PostPosted: Mon Mar 07, 2011 1:31 am     Reply with quote

PCM programmer wrote:
Remove the RF modules and connect the two PICs together. See if you
can make the PICs talk to each other without the RF modules.


For the first time pics are communicating but when I try to send other characters receiver side is locked.

The interesting part is with pic18f4550 there is no problem however in pic16f877A problem arises. I have checked the voltage levels in 18f4550 in tx pin there is a 5 volts and in receiver side rx pin there is 3.3 volts. However in pic16f877A both tx and rx pins have 2.5 volts. I think this is caused by the voltage levels. But I can not figure out how this levels can cause such a problem.
altanonat



Joined: 07 Feb 2011
Posts: 21
Location: Turkey

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

PostPosted: Tue Mar 15, 2011 9:08 am     Reply with quote

I have solved the problem. The main reason is that it is necessary to put errors in #use RS232() directive if you are using Pic16f877a. In pic18f4550 I have done it without putting errors into the directive.

Thank you!!!
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