Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC24F UART not working properly

Status
Not open for further replies.

pic24fprogrammer

Newbie level 3
Joined
Feb 27, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,353
Hi I am using PIC14FJ64Gb002 and i am trying to communicate with my PC using hyperterminal.

I send a character from PC to the receive Pin with 8 bit data no parity 1 stop bit but the problem is the microcontroller doesn't take all the 8 bits. sometimes 3 sometimes 2 sometimes 5bits and so on.

I have tried all the possible ways. I must be missing something simple to make it accept all 8 bits
Please can someone help me out.

The same thing happen when I transmit a character to PC as well. I send a character "a" and instead of 61 it shows E8. Can someone also explain why it doesn't transmit the exact ascii code?

COde:
#include <main.h>
#include <LCD1.C>
#include <KBD1.C>
#fuses HS, PR_PLL, NOWDT, NOPROTECT, NODEBUG, SOSC_IO,OSCIO ,PLL96MHZ, PLLDIV5,

#use fast_io(A)
#use fast_io(B)

#use rs232(UART1A, baud=4800,xmit =PIN_B13, rcv=PIN_B11,BITS=8,PARITY=N,STOP=1) //for serial communication

char k;
//Main function
void main()
{
printf(lcd_putc,"\fSerial");
delay_ms(2000);
printf(lcd_putc,"\f");

while(true)
{
if(kbhit())
{
k = getc();
putc('k');

}
else
printf(lcd_putc,"\f%c",k);
delay_ms(500);
}
}
 

might be different bit rate configured in both sides: PC and PIC
 
Some directive I usually practice in my designs with PIC, an may be the reason of the problem :

> Remove Delay functions, or minimize its amount.
> Try to manage receiving, managed by interruption, instead polling.

+++
 

1- The baud rate at the PIC side may not enough accurate. it is depending on clock frequancy of PIC and the baud rate you are select.
check the baud rate generator at the PIC and calculate the error of baud rate. if it was a big error then change baud rate to have minimum error.

2- Make sure the baud rate of PC & uC are same.
 
...baud rate at the PIC side may not enough accurate...

Good point.

The 8-bits Timer modules in wich baud is calculated may add significative error, depending up of crystal frequency selection.
Microchip datasheets provide some simulated examples.

+++
 
Last edited:

PIC24 has 16-Bit baud rate generator and can generate at least lower baud rates rather exactly. I have however a problem with the posted code, that doesn't show the clock settings for CCS PCD. So it's impossible to check, if the settings are correct. The reported behaviour may be also caused by incorrect RS232 hardware.
 
...PIC24 has 16-Bit baud rate generator and can generate at least lower baud rates rather exactly...

Sorry about mistake.
I refered incorrectly to 8-bit register SPBRG from PIC16 familly.

+++
 

I refered incorrectly to 8-bit register SPBRG from PIC16 familly.
No problem. I'm aware of the fact, that PIC24 isn't that widely used as PIC16 and PIC18 yet. But it's a powerful processor. CCS PCD however still has some problems. If a code isn't working with PCD, we should ask for the compiler version as well.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top