View previous topic :: View next topic |
Author |
Message |
altanonat
Joined: 07 Feb 2011 Posts: 21 Location: Turkey
|
Problem in uart of pic16F877A! |
Posted: Thu Mar 03, 2011 3:04 am |
|
|
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
|
|
Posted: Thu Mar 03, 2011 6:27 am |
|
|
any ideas? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 03, 2011 5:19 pm |
|
|
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
|
|
Posted: Mon Mar 07, 2011 1:31 am |
|
|
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
|
|
Posted: Tue Mar 15, 2011 9:08 am |
|
|
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!!! |
|
|
|