View previous topic :: View next topic |
Author |
Message |
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
PCD, Serial Port, and PICKit2 oddities |
Posted: Sat Apr 21, 2012 4:21 pm |
|
|
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
|
|
Posted: Sat Apr 21, 2012 5:54 pm |
|
|
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
|
|
Posted: Sat Apr 21, 2012 5:58 pm |
|
|
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
|
|
Posted: Sat Apr 21, 2012 7:19 pm |
|
|
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
|
|
Posted: Sun Apr 22, 2012 5:03 am |
|
|
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. |
|
|
|