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

PCD, Serial Port, and PICKit2 oddities

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



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

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

PCD, Serial Port, and PICKit2 oddities
PostPosted: Sat Apr 21, 2012 4:21 pm     Reply with quote

I have a basic breadboard setup with a PIC24. The trouble is that the serial I/O works only if I have the PICkit2 programmer attached.

If I power the board from the PICkit2, it works.
If PICkit2 is powered off but still attached and I use external power, it works.
When I detach the PICkit2 and it does not work.

The heartbeat LED still keeps blinking but there is no serial I/O.

As long as I keep just the ground line to the PICkit2 connected, I get serial I/O.

Does anyone have any suggestions about what might be happening?

Code and connections below: (Device and compiler versions in the code)

Code:
// 24HJtest.c
//
// Initial work with PCD compiler
//
// keyboard i/o testing
//
// Processor:  24HJ128GP202   10MHz XTAL
// Compiler:   PCD 4.130
// IDE:        PCW 4.130
// Programmer: PICKit2
//
//------ 24HJ128GO202 connections
//
//    1  MCLR     10K to + PICKit2
//    2  RA0      LED0
//    3  RA1      LED1
//    4  RB0      PGD      PICKit2
//    5  RB1      PGC      PICKit2
//    6  RB2
//    7  RB3
//    8  Vss      GND
//    9  RA2/OSC1 XTAL  18pf to GND   10Mhz
//   10  RA3/OSC2 XTAL  18PF to GND
//   11  RB4
//   12  RA4
//   13  Vdd      3.3v+  0.1uF bypass to ground
//   14  RB5   
//
//   15  RB6     
//   16  RB7     
//   17  RB8     
//   18  RB9     
//   19  Vss      GND
//   20  Vcap     10uF Tant Cap to GND
//   21  RB10
//   22  RB11
//   23  RB12
//   24  RB13
//   25  RB14     RX1 <- Max3232 to PC Serial Port
//   26  RB15     TX1 -> MAX3232
//   27  Vss      GND
//   28  Vdd      3.3v+ 0.1uF bypass to GND

#include <24HJ128GP202.h>

#fuses PR_PLL, NOIESO, NOWDT
#fuses XT, OSCIO

#use delay(clock=80M)

#pin_select U1TX=PIN_B15
#pin_select U1RX=PIN_B14
#use rs232( baud=38400, UART1, ERRORS )

#define  LED0  PIN_A0
#define  LED1  PIN_A1

#WORD OSCCON = 0x742   
#WORD CLKDIV = 0x744       
#WORD PLLFBD = 0x746     

#define INTS_PER_SECOND 100

BYTE seconds;      // A running seconds counter
BYTE int_count;    // Number of interrupts left before a second has elapsed

#int_timer1                         
void clock_isr()
{
    if(--int_count==0) {           // per second.
      ++seconds;
      int_count=INTS_PER_SECOND;
      output_toggle( LED0 );
    }
}

#int_RDA
void console_isr(void)
{
   printf("int_RDAx");
   getc();
}

void main()
{
   int8 i;
   
   OSCCON = 0x3300;     // 10MHZ Crystal
   PLLFBD = 0x001E;
   CLKDIV = 0x0000;
   
   setup_adc_ports( NO_ANALOGS );

   // send an "I'm alive" LED toggle
   for (i=0; i<3; i++)
   {
      output_high( LED1 );
      delay_ms(300);
      output_low( LED1 );
      delay_ms(300);
   }
   
   setup_timer1(TMR_INTERNAL,50000);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   enable_interrupts(INTR_GLOBAL);

   printf("Hello: %s %s %s\r\n",__filename__, __date__, __time__);

   do {
      printf("Press any key to begin.\n\r");
      getc();
      seconds=0;
      set_timer1(0);
      printf("Press any key to stop.\n\r");
      getc();
      printf("%u seconds.\n\r",seconds);
   } while (TRUE);
}

_________________
Jürgen
www.jgscraft.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 21, 2012 5:54 pm     Reply with quote

Does your serial port cable have a ground wire in it ? Are the connections
good at both ends ?

There are threads in the forum archives about "serial port only works if
debugger is attached" or something like that. I don't remember all the
details at the moment. One of them is the ground wire issue.
Another one is, if you are compiling in "Debug" mode, then certain fuses
are disabled (silently). It's these fuses being disabled, that allow the
programmer to run when in debug mode and not in normal mode.

I don't have the patience right now to go search the archives for all the
examples. It's too hot out here. Signing off.
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

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

PostPosted: Sat Apr 21, 2012 5:58 pm     Reply with quote

Everything helps right now since I'm seriously stuck. This is my first time using PCD after several years of C30 and trying to make life easier (via using CCS) and failing. Will follow up on your suggestions.

Thanks.
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

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

PostPosted: Sat Apr 21, 2012 7:19 pm     Reply with quote

It seems that my USB to Serial cable was the culprit. I still have a legacy laptop with a real 9-pin RS232 port. When I plugged into that it worked fine.

On to the next problem/challenge...
_________________
Jürgen
www.jgscraft.com
temtronic



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

View user's profile Send private message

PostPosted: Sun Apr 22, 2012 5:03 am     Reply with quote

Welcome to the Useless Serial Bus ! I've got 3 of those USB<->RS232 adapters and only ONE works correctly.I'ts really sad when you can waste more time on USB issues like faulty hardware,PC drivers than real PIC code.The 4 laptops I use ALL have real comports as you found out why.
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