View previous topic :: View next topic |
Author |
Message |
chandra
Joined: 19 Mar 2010 Posts: 18
|
PIC24FJ16 Uart1 Problem |
Posted: Sun Mar 21, 2010 12:02 pm |
|
|
I tried to send character "HELLO" To PC. I used PIC uart1. I am getting scrambled characters. I am getting this hex: (A8 A5 AC AC AF)
The code is:
Code: |
#include <24FJ16GA002.h>
#fuses HS,PROTECT,NOWDT
#use delay(crystal=7372800 )
#use rs232(baud=115200, UART1,xmit=PIN_B8, rcv=PIN_B9, bits=8)
void main()
{
while (1) {
delay_ms(500);
printf ("HELLO"); // print to serial port
delay_ms(1000); // do nothing for half a second
while (1);
}
} |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Mar 21, 2010 1:00 pm |
|
|
What's your PCD version? The code doesn't compile with V4.104 or V4.105. These versions expect a #PIN_SELECT
statement for the UART pins. Older versions are apparently generating a software UART with these settings. You should
force a hardware UART, requires #PIN_SELECT, and check again. |
|
|
chandra
Joined: 19 Mar 2010 Posts: 18
|
|
Posted: Mon Mar 22, 2010 12:56 am |
|
|
I am using PCD version 4.084.I need a example program for this chip.where can I find?
Thanks. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Mar 22, 2010 1:25 am |
|
|
The correct #pin_select syntax is this
Code: | #pin_select U1TX=PIN_B8
#pin_select U1RX=PIN_B9
#use rs232(baud=115200, UART1, bits=8) |
It should be mentioned, that #pin_select is still not working correctly up to PCD V4.105 with some PIC24 chips, but it
seems to be understood for your chip with V4.084. Otherwise, you'd need to program peripheral pin select SFRs yourself. |
|
|
chandra
Joined: 19 Mar 2010 Posts: 18
|
|
Posted: Mon Mar 22, 2010 2:02 am |
|
|
I used these lines, but now I am getting scrambled letters. I am getting the hex value is:A8 39 CA 9D. It is likely a baudrate problem. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Mar 22, 2010 4:12 am |
|
|
Also the software UART used in your previous setup should have worked correctly. You should verify, that the
crystal is correct and your processor is actually working at specified frqeuency. |
|
|
monsters_inc
Joined: 18 Jan 2010 Posts: 14
|
|
Posted: Mon Mar 22, 2010 10:05 am |
|
|
Hi. try #fuses XT,PROTECT,NOWDT.
XT - 3mhz to 10 mhz for PCD.
Best Regards. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Mar 22, 2010 11:05 am |
|
|
Quote: | Hi. try #fuses XT,PROTECT,NOWDT. |
Yes, XT rather than HS is correct. But it's used by PCD automaticly due to the low crystal frequency. |
|
|
chandra
Joined: 19 Mar 2010 Posts: 18
|
|
Posted: Wed Mar 24, 2010 12:43 am |
|
|
Code: |
#fuses PR, HS,PROTECT,NOWDT
|
Now ok.
Thanks for all. |
|
|
|