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

PIC18F85K22 UART2

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



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PIC18F85K22 UART2
PostPosted: Fri Apr 08, 2011 9:27 am     Reply with quote

I am having a problem getting UART2 to work on PIC18F85K22. I can see valid characters getting to the RX2 pin (7 / RG2) on the 'scope, but no response or break from from kbhit() or fgetc(). I tried changing the port to a SW UART, but no luck. UART2 transmits OK, but no RX. UART1 works fine. Is there a bug or have I missed something "obvious"? Thanks for reading...

Code:

#include <18F85K22.h>

#define DEBUG_MODE  // comment-out for stand-alone operation

#ifdef DEBUG_MODE
   #device ICD=TRUE
#endif

#ifdef DEBUG_MODE
   #FUSES MCLR
#else
   #FUSES NOMCLR
#endif

#device adc=12

#FUSES NOWDT                    // No Watch Dog Timer
#FUSES WDT128                   // Watch Dog Timer uses 1:128 Postscale

#FUSES SOSC_DIG                 // Enables C0 & C1 as digital I/O
#FUSES NOXINST                  // Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PUT                      // Power Up Timer
#FUSES NOBROWNOUT               // No brownout reset
#FUSES WDT_NOSLEEP           
#FUSES NOEXTADDRSFT         

#FUSES RTCOSC_INT

#FUSES HSM
#FUSES INTRC_HP
#FUSES PLLEN

#use delay(clock=16000000)

#use rs232(UART1, baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=COM_A,errors)
#use rs232(UART2, baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,stream=COM_B,errors)

// RS232
#define MDX_SHDN     PIN_G0
#define MD1_TXEN     PIN_C0
#define MD1_REN      PIN_C1
#define MD2_TXEN     PIN_G3
#define MD2_REN      PIN_G4

char cmd;

void init()
{
   // RS232
   output_high(MDX_SHDN);   // MAX3323 ON
   output_high(MD1_REN);    // Rx enable
   output_high(MD1_TXEN);   // Tx enable
   output_high(MD2_REN);    // Rx enable
   output_high(MD2_TXEN);   // Tx enable
   delay_ms(20);
}

void main()
{
   disable_interrupts(GLOBAL);
   
   setup_adc_ports(ALL_ANALOG|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
   
   setup_wdt(WDT_OFF);
   
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   
   setup_oscillator(OSC_16MHZ);
   
   enable_interrupts(GLOBAL);
   
   init();
   
   fprintf(COM_A, "NYMPH COM_A\r\n");
   fprintf(COM_B, "NYMPH COM_B\r\n");
   
   while (TRUE) {
      if(kbhit(COM_A)){
         cmd=fgetc(COM_A);
         fputc(cmd,COM_A);
      }
      if(kbhit(COM_B)){
         cmd=fgetc(COM_B);
         fputc(cmd,COM_B);
      }
   }
     
   reset_cpu();
}
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 9:35 am     Reply with quote

Compiler V4.119
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 5:01 pm     Reply with quote

Quote:
void main()
{
disable_interrupts(GLOBAL);

setup_adc_ports(ALL_ANALOG|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);

setup_wdt(WDT_OFF);

The UART2 pins are set as analog pins by the line in bold.
They should be configured as digital pins.
You are setting ALL 24 pins that can be analog, as analog pins.
You should change it to select the specific analog pins that you need.
There are 24 analog-configurable pins on this PIC.


Also, in your program you are enabling/disabling Global interrupts.
There is no need for this. You have no interrupt routines.
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 5:17 pm     Reply with quote

Excellent catch. Thank you!

(I plan to have some interrupt routines in the near future).
temtronic



Joined: 01 Jul 2010
Posts: 9173
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 6:31 pm     Reply with quote

Ever since the design guys figured out you could 'multipurpose' a pin, it's been a battle to get the 'correct' configuration.
Things were easier back in the days of 8008s, teletypes and papertape !
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 8:18 am     Reply with quote

That was it PCM programmer. Thanks for your help. Caught-out by the doubled edged sword of multi-purpose pins.
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