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

Help! PIC18F14K50 UART Problem

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



Joined: 04 Feb 2011
Posts: 5
Location: Japan

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

Help! PIC18F14K50 UART Problem
PostPosted: Fri Feb 04, 2011 4:26 am     Reply with quote

Hello,

I have the problem of UART of PIC18F14K50(at 3.3V).

Data cannot be received though data can be transmitted.

Settings : TX[RB7], RX[RB5], CTS[TB6], RTS[RB4]

Code:

#include <18F14K50.h>
#device ICD=TRUE
#device adc=8

#FUSES HS
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //Code not protected from reading

#use delay(clock=12000000, crystal)

#use rs232(baud=9600, parity=E, STOP=1, xmit=PIN_B7, rcv=PIN_B5, bits=8, restart_wdt, stream=RFMODULE, UART, ERRORS)
#use fast_io(C)
#use fast_io(B)

#define ACTIVE     1
#define INACTIVE   0

void vRfSend(char *cBuff,int iLen);

void main
{
   set_tris_b(0x5F);    // B7,B4 output
                        // B6,B5 input
                        // B3-B0 none
   set_tris_c(0xFF);    // C7,C5,C4,C3,C2,C0 output
                        // C6,C1 input

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   unsigned char cSend[5]
   cSend[0] = 0x01;
   cSend[1] = 0x02;
   cSend[2] = 0x03;
   cSend[3] = 0x04;
   cSend[4] = 0x05;

   while(1)
   {
      vRfSend(cSend, 5);
      delay_ms(1000);
  }
}

void vRfSend(char *cBuff,int iLen)
{
   int iCnt;
   unsigned char buf[10];
   int itemp = 0;
   
   itemp = iLen;
   memcpy(buf,cBuff,itemp);
   
   iCnt = 0;
   
   while(INACTIVE == input(RF_CTS))
   {
      ;
   }
   // RTS INACTIVE
   output_bit(PIN_B4, INACTIVE);

   for(iCnt=0 ; iCnt < iLen ; iCnt++)
   {
      fputc(cBuff[iCnt],RFMODULE);
   }
   // RTS ACTIVE
   output_bit(PIN_B4, ACTIVE);
}

#int_RDA
void  RDA_isr(void)
{
   unsigned char c;

   c = 0x00;
   c = fgetc(RFMODULE);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 04, 2011 2:34 pm     Reply with quote

Quote:

void main
{
#use rs232(baud=9600, parity=E, STOP=1, xmit=PIN_B7, rcv=PIN_B5, bits=8, restart_wdt, stream=RFMODULE, UART, ERRORS)

#use fast_io(C)
#use fast_io(B)


set_tris_b(0x5F); // B7,B4 output
// B6,B5 input
// B3-B0 none

set_tris_c(0xFF); // C7,C5,C4,C3,C2,C0 output
// C6,C1 input


output_bit(PIN_B4, INACTIVE);



0x5F = 0101 1111 in binary. A '1' means the Port bit is an input. So you
have set Port B to all inputs, except for B5 and B7, which are outputs.

This means the UART Rx pin (B5) won't work, because you have set it
to be an output.

Also, pin B4 won't work as an output, because you have set it to be an input.

Your comments don't match your TRIS settings for Port C.


It's best to let the compiler set the TRIS. Unlike other C compilers, CCS
will set the TRIS for you. Delete the two #fast_io statements and delete
the set_tris_x() statements and let the compiler handle it.

If it still doesn't work, there may be bugs in your version. In that case,
post your compiler version. It's a 4-digit number in this format: x.xxx
and its given at the top of your .LST file.
Masaya Tanaka



Joined: 04 Feb 2011
Posts: 5
Location: Japan

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

PostPosted: Sat Feb 05, 2011 12:06 am     Reply with quote

Thank you for your support.

When [set_tris_b(0x5F);] was changed to [set_tris_b(0x60);], the problem was solved.

However, the problem occurs when [#use fast_io] and [set_tris_x] are deleted.
Compiler Version is PCH 4.112.
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