UART Issue with PICDEM PlUS 2 board

Thread Starter

Neyolight

Joined Dec 13, 2011
54
Hi Everyone

I have a PICDEM 2 Plus board with a PIC18F4620 on it. My UART code is given. The code worked perfectly fine the first time i programmed my chip but stopped working after that.

With Hyperterminal the error is : "Unable to open COMPORT 1. Please check your port setting"

With RealTer , the error is : Break condition received

With Putty : Nothing happens

I performed a loopback test on the board ( by taking our the PIC ) and Serial-to USAB adaptor and both works fine. The comport on my laptop works fine with other UART. Please guide me..I AM SUPER LOST ! :confused:

Heres the code



#include <p18f4620.h>
#include <stdio.h>
#include <delays.h>
#include <usart.h>

// INTIO67 configures internal oscillator
#pragma config OSC=INTIO67, LVP=OFF, MCLRE=ON , WDT=OFF

void setup(void)
{
/* Clock Setup*/
OSCCON = 0b01110010; //select 8 MHz clock

/* Port Set Up*/
ADCON1 = 0b00001111; //set all pins to digital mode
TRISD = 0x00;
TRISA = 0x00;
TRISB = 0b00000000;
TRISC = 0b10000000; // RX is an input, TX is output

// PORTBbits.RB0=1; //Turn on the 4 LEDs
// PORTBbits.RB1=1;
// PORTBbits.RB2=1;
// PORTBbits.RB3=1;

// Turn on the 4 LEDs
// Microchip recommends writing to the PORT Latch rather than the PORT Pins
LATBbits.LATB0=1;
LATBbits.LATB1=1;
LATBbits.LATB2=1;
LATBbits.LATB3=1;


/* Interrupt Setup */
INTCON = 0x00; /* Clear Registers */
PIR1 = 0x00;
PIE1 = 0x00;
TMR1L = 0x00;
TMR1H = 0x00;
T1CON = 0x00;
RCON = 0x00;



/* RS232 Enable */
// OpenUSART Configures The Next Three Lines
//RCSTA = 0b10000000;
//TXSTA = 0b00100000;
//BAUDCON = 0b01000000;

// USART 9600 8-N-1
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 12);

}


#pragma code
void main(void)
{
setup();

while (1)
{
putrsUSART(" Hello World! ");
// while(BusyUSART());
Delay10KTCYx(100);

}
}
 

spinnaker

Joined Oct 29, 2009
7,835
I see so the board has the RS232.

Do you have a null modem cable? Are you certain the board TX is connected to the PC RX and the board RX is connected to the PC TX?
 

thatoneguy

Joined Feb 19, 2009
6,359
I see so the board has the RS232.

Do you have a null modem cable? Are you certain the board TX is connected to the PC RX and the board RX is connected to the PC TX?
Not needed, I have one of these, they work handy when trying something out quick.

A.4 RS-232 SERIAL PORT
An RS-232, level-shifting IC has been provided with all the necessary hardware to support
connection of an RS-232 host through the DB9 connector. The port is configured
as DCE and can be connected to a PC using a straight-through cable.
The PIC16/PIC18 RX and TX pins are tied to the RX and TX lines of the MAX232A.
Maybe the problem is the OP accidentally plugged in a Null Modem Cable?
 

ErnieM

Joined Apr 24, 2011
8,046
The problem may be more likely inside Hyperterminal then inside your PIC. If your program stopped while transmitting a serial byte then Hyperterminal scored a serial error and stopped looking at your serial stream. Just try disconnecting and reconnecting on it.

The problem gets reported a lot when doing debugging that stops the serial unit inside the PIC, so code that runs fine doesn't work in the debugger.

I don't use Hyperterminal for various reasons. I prefer a program called "Terminal by Br@y" which is a free download. Not pretty but good price!
 

Thread Starter

Neyolight

Joined Dec 13, 2011
54
The exact code worked fine the first few times i tried on hyperterminal and then it stopped working for unknown reason! Im stuck on this for a month now- not sure how to get my project rolling!
 

spinnaker

Joined Oct 29, 2009
7,835
What does this mean? :confused:
Do you know what a null modem cable is? It swaps TX and RX wires from one device to the other. Apparently you do not need it.

And I will ask for a third time. For some reason you refuse to answer. Do you have an oscilloscope or logic analyzer?
 

Thread Starter

Neyolight

Joined Dec 13, 2011
54
Oh and if i take the PIC out of the board and connect the board to PC using the same serial-to-usb adaptor, IT CONNECTS!

Does that suggest the code is at fault?
 

spinnaker

Joined Oct 29, 2009
7,835
How? As in what should I expect from what pin?
No offense but if you don't know that then borrowing the scope is not going to do you much good. You will have a harder time learning to use it than testing your circuit.

You should consider studying basic electronics trouble shooting if you want to participate in this hobby.

Can your fiend help you use the scope?
 

Thread Starter

Neyolight

Joined Dec 13, 2011
54
well thanks man--- i use to think these forums are there to support and motivate beginners - thanks for clearing that misconception!

I know how to use the scope and if I were such an expert with these PICs and Demo Boards I wouldn't be posting questions up here!
 

spinnaker

Joined Oct 29, 2009
7,835
Sorry but you made it sound like you have no idea what you are working with.

Look at your datasheet for the Pic and see if you can identify the SDO pin. Place your scope probe on that pin and start your program. You should see a square wave from the SDO pin.

Next place the probe on pin 14 of U3. You should see a square wave there.

If that works then your MCU and software is working and it is your connection to the PC that is the problem.
 

spinnaker

Joined Oct 29, 2009
7,835
Nothing will replace reading the documentation or checking your work but when that fails that is were test equipment comes in handy to verify your work.

If you can't afford a scope or a logic analyzer then at least get or build a logic probe.
Also the PicKit II comes with a simple logic analyzer and may have helped you with this issue.

You didn't even have to use the UART functions to help trouble shoot. You could have written a some code to toggle the pin used by the UART port and trace with your logic probe.

I have a Zero Plus Logic Analyzer.

http://www.zeroplus.com.tw/logic-analyzer_en/

It is not the best analyzer on the market but is fairly inexpensive.

It comes with protocol analyzers that will let you decode things like the UART protocol.

A very useful tool.
 

Thread Starter

Neyolight

Joined Dec 13, 2011
54
Allright will check it out!

When im at uni, I have all these equipments in the lab I am in. But working outside lab is difficult with lack of such equipment to help me troubleshoot!

Atleast I have a multimeter with me :D
 
Top