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

uart reception issue on PIC16LF88

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



Joined: 28 Apr 2013
Posts: 2

View user's profile Send private message

uart reception issue on PIC16LF88
PostPosted: Sun Apr 28, 2013 10:09 am     Reply with quote

Hello Guys,

I m having trouble using the PIC16LF88.
Sending is working perfectly fine.
Reception is working only using SW UART (let me think that my board is good). However i want to use the HW uart to use the RDA interrupt.

Reception does not work (kbhit or interrupt).

My compiler is version 4.068.

I have read many think about UART problem, but i did not find the good tips to fix my problem.
Thanks in advance for your help Smile

Here is my code:
Code:

#include <16F88.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO
#FUSES NOBROWNOUT
#use delay(clock=8000000)
#use standard_io(A)

#use rs232(baud=1200, xmit=PIN_B5, rcv=PIN_B2, STREAM=XBEE, ERRORS)//, FORCE_SW)//, DISABLE_INTS)

char receivedChar;
char receivedCharOld;
#INT_RDA
void rda_isr()
{
 receivedChar =fgetc(XBEE);
 fputc(receivedChar,XBEE);
}

void main()
{
   int test;
   int c;
   char RCSTAValude;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_2(T2_DIV_BY_1,0,1);

   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1);

   setup_counters(RTCC_INTERNAL,RTCC_8_BIT|RTCC_DIV_256); // 50hz with preload

   set_tris_a(0b00000000);
   set_tris_b(0b00000000);

   setup_timer_2(T2_DIV_BY_1, 125, 1);

   delay_ms(2000);
   test=0;
   fprintf(XBEE,"Ready");

   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_RDA);

   do
   {

void main()
{
   int test;
   int c;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_2(T2_DIV_BY_1,0,1);

   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1);

   setup_counters(RTCC_INTERNAL,RTCC_8_BIT|RTCC_DIV_256); // 50hz with preload
   setup_vref(FALSE);
   set_tris_a(0b00000000);
   set_tris_b(0b00000000);
    setup_timer_2(T2_DIV_BY_1, 125, 1);


   delay_ms(2000);
   fprintf(XBEE,"Ready");
   //setup_uart(1200, XBEE);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   do
   {
      //if(kbhit(XBEE))
      //{
      //   receivedChar=fgetc(XBEE);
      if(receivedChar!=receivedCharOld)
      {
         receivedCharOld=receivedChar;
//********
//Processing
//********
      }
   }while(1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sun Apr 28, 2013 1:40 pm     Reply with quote

Start by posting a small compilable program.
What you have posted is half each of two separate programs, and hasn't got a hope of compiling, let alone working.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Apr 28, 2013 2:53 pm     Reply with quote

Also, You are using Standard I/O so you don't need to set TRIS.

The below two lines are setting all the pins to outputs.
Get rid of these lines..

Quote:
set_tris_a(0b00000000);
set_tris_b(0b00000000);


You also enabled Interrupts for Timer 2 with no interrupt handler defined.
Never enable interrupts without an Interrupt handler.
_________________
Google and Forum Search are some of your best tools!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 28, 2013 9:56 pm     Reply with quote

Also your program has many unnecessary lines which turn off modules
which are already off when the PIC is reset. Normally adding all these
extra lines doesn't cause a problem, but in this case it does:
Quote:

char RCSTAValude;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_2(T2_DIV_BY_1,0,1);

See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=29830
backb0ne86



Joined: 28 Apr 2013
Posts: 2

View user's profile Send private message

PostPosted: Thu May 02, 2013 9:30 am     Reply with quote

Thanks PCM programmer. You are a genius!
I have also corrected my set_tris_b line which was wrong too.

Thanks again all for your usefull replies!
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