|
|
View previous topic :: View next topic |
Author |
Message |
smkul13
Joined: 04 Dec 2008 Posts: 8
|
PIC24HJ128xxx and RS232 help !!!!!!! |
Posted: Thu Dec 04, 2008 7:57 am |
|
|
Guys,
I need your help desperately. I am trying to read and write back to hyperterminal from pic24. But it's not happening. I am not sure what the problem is. Here is the code.
Code: |
#fuses XT,NOWDT,NODEBUG,FRC, NOWRT, NOPROTECT
#use delay(clock=8000000)
#use rs232(UART1, baud=9600, rcv=PIN_B5, xmit=PIN_B4, parity=N,errors, bits=8)
main()
{
enable_interrupts(INT_RDA) ;
enable_interrupts(INTR_GLOBAL);
TRISB = 0x27; //bits 2 n 5 as input (Is it correct)..After execution
TRISB is taking only value 7
while(1)
{
char c;
if(kbhit())
{ c = getc();
putc(c);
}
else
putc('A');
}
} |
I really don't understand whats the problem. When I debug I found that U1TXREG, U1RXREG are not getting updated. I was expecting U1MODE.15 to be set(indicating TX is enabled) after using #use rs232, but thats not happening either.
I even tried writing directly to U1TXREG hoping I would get something at the terminal but everything in vain.
Please tell me what I am missing. I intend to use hard UART.
I am posting only after extensive search through other posts of this forum.
Thanks in advance.
smkul13
Last edited by smkul13 on Tue Dec 09, 2008 1:49 am; edited 1 time in total |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: PIC and RS232 help !!!!!!! |
Posted: Thu Dec 04, 2008 10:35 am |
|
|
smkul13 wrote: | Guys,
I need your help desperately. I am trying to read and write back to hyperterminal from pic24. But it's not happening. I am not sure what the problem is. Here is the code.
Code: |
#fuses XT,NOWDT,NODEBUG,FRC, NOWRT, NOPROTECT
#use delay(clock=8000000)
#use rs232(UART1, baud=9600, rcv=PIN_B5, xmit=PIN_B4, parity=N,errors, bits=8)
main()
{
enable_interrupts(INT_RDA) ;
enable_interrupts(INTR_GLOBAL);
TRISB = 0x27; //bits 2 n 5 as input (Is it correct)..After execution
TRISB is taking only value 7
while(1)
{
char c;
if(kbhit())
{ c = getc();
putc(c);
}
else
putc('A');
}
} |
I really don't understand whats the problem. When I debug I found that U1TXREG, U1RXREG are not getting updated. I was expecting U1MODE.15 to be set(indicating TX is enabled) after using #use rs232, but thats not happening either.
I even tried writing directly to U1TXREG hoping I would get something at the terminal but everything in vain.
Please tell me what I am missing. I intend to use hard UART.
I am posting only after extensive search through other posts of this forum.
Thanks in advance.
smkul13 |
I have not used the PCD compiler so some of my comments might be meaningless. You have enabled interrupts but you do not have an interrupt handler. You have not enabled peripheral interrupts (unless the compiler does this automatically for reasons not obvious) which is why the PIC is not crashing with a trap violation. This pic family has postscalars on the clock. Where do you tell the compiler the post scalar to use.
Are you using LVP? If not then you should add the NOVLP fuse.
Does the #use RS232 automatically perform the peripheral pin mapping? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Guest
|
|
Posted: Fri Dec 05, 2008 12:35 am |
|
|
putc puts a character on the xmit pin, so you have to receive something even if its garbage. Check your connections, if you are using a max232 chip with your pic it is possible that you must manually change pin 2 (receive) on your xmit pin and pin 3 (transmit) on your rcv pin, and then have common ground. I also recommend using Terminal 1.9b for testing. |
|
|
smkul13
Joined: 04 Dec 2008 Posts: 8
|
Re: PIC and RS232 help !!!!!!! |
Posted: Fri Dec 05, 2008 4:56 am |
|
|
asmallri wrote: | smkul13 wrote: | Guys,
}
}[/code]
I really don't understand whats the problem. When I debug I found that U1TXREG, U1RXREG are not getting updated. I was expecting U1MODE.15 to be set(indicating TX is enabled) after using #use rs232, but thats not happening either.
I even tried writing directly to U1TXREG hoping I would get something at the terminal but everything in vain.
Please tell me what I am missing. I intend to use hard UART.
I am posting only after extensive search through other posts of this forum.
Thanks in advance.
smkul13 |
Are you using LVP? If not then you should add the NOVLP fuse.
Does the #use RS232 automatically perform the peripheral pin mapping? |
->
LVP ?? PIC24H generated no fuse for LVP or NOLVP... .. So i think its not using it. Regarding RS232 automatically performs the peripheral pin mapping, i thought it would .. now i have doubts.
I thought TRISB.x would be set by RS232 when we configure particular pin x as input but thats not happening.
In my earlier code i did not paste #int_RDA but again no output.
I am still fighting. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 05, 2008 11:30 am |
|
|
Post the #include statement for your PIC. You should always put that in
the posted code. Also post your compiler version. |
|
|
smkul13
Joined: 04 Dec 2008 Posts: 8
|
|
Posted: Mon Dec 08, 2008 4:49 am |
|
|
PCM programmer wrote: | Post the #include statement for your PIC. You should always put that in
the posted code. Also post your compiler version. |
Well thx..I have put the #include, Fuses and rs232 in the main file. But when I do that, the control does not come to main() but just starts looping in rs232. I am confused. Why this looping is happening in rs232?
More info: I am not working on any pic24 starter kit. This circuit is designed inhouse as per certain needs.
We are using an external crystal and it is connected across OSC1 & 2 pins. How do I ensure that clock signals are coming at those terminals? Should I do any mapping? If yes how? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 08, 2008 11:07 am |
|
|
You still have not told us what PIC you are using. |
|
|
smkul13
Joined: 04 Dec 2008 Posts: 8
|
|
Posted: Mon Dec 08, 2008 9:53 pm |
|
|
PCM programmer wrote: | You still have not told us what PIC you are using. |
I am using 24HJ128502 and the compiler is PCD oscillator is 8MHz crystal.
#use delay(clock=32MHz, oscillator = 8MHz) //Fcy = 32mhz
//set_tris_b(0x20);
set_tris_c(0x00);
TRISB = 0x20; // #byte TRISB = 0x2c6
The above 3 statements are not serving the purpose. TRISB is 0 and port c is varies.
The assembly code generated for rs232 mentioned below is
#use rs232( baud=9600,rcv=PIN_B5, xmit=PIN_B4 )//, parity=N,errors, bits=8)
-------------------
00200: BTSC.B 2C8.5
00202: BRA 200
00204: MOV #8,W3
00206: CLR W2
00208: REPEAT #89
0020A: NOP
0020C: REPEAT #198
0020E: NOP
00210: BCLR.B 42.0
00212: BTSC.B 2C8.5
00214: BSET.B 42.0
00216: RRC.B W2L,W2L
00218: DEC W3,W3
0021A: BRA NZ,20C
0021C: REPEAT #19F
0021E: NOP
00220: MOV W2,W0
00222: RETURN
*
0029A: BCLR.B 2CA.4
0029C: MOV #8,W3
0029E: REPEAT #19C
002A0: NOP
002A2: RRC.B 880
002A4: BTSC.B 42.0
002A6: BSET.B 2CA.4 //0x2CA is the addr of LATB but TRISC is
002A8: BTSS.B 42.0 //varying. TRISC addr is 0x2CC
002AA: BCLR.B 2CA.4
002AC: REPEAT #197
002AE: NOP
002B0: DEC W3,W3
002B2: BRA NZ,2A2
002B4: BSET.B 2CA.4
002B6: REPEAT #19E
002B8: NOP
002BA: RETURN
----------------------------
Can u let me know if theres any link which can throw more light on PCD compiler. I have CCS compiler manual but it doesnt say much about PCD and it is relevant only to PIC18 series.
Thx
smkul13
Last edited by smkul13 on Mon Dec 08, 2008 11:19 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 08, 2008 10:04 pm |
|
|
I don't have the compiler for your PIC. But, I suggest that you
make a simple test program as shown in this thread. Get rid of
the interrupts, and get rid of kbhit(). Make it simple, like this:
http://www.ccsinfo.com/forum/viewtopic.php?t=37010&start=14
Quote: |
I have CCS compiler manual but it doesn't say much about PCD and it is
relevant to PIC18 series. |
This page shows a separate manual for the PCD compiler:
http://www.ccsinfo.com/downloads.php |
|
|
smkul13
Joined: 04 Dec 2008 Posts: 8
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Dec 09, 2008 12:48 am |
|
|
If I understand your post right, the wrong TRIS register access is with built-in function UART pin setup? It's not surprising to me, cause there have been various bugs of this kind with PCD, at least regarding PIC24FJ. It's generally advisable to check the code and perform an optional register setup in user code.
By the way, I suggest to use a PIC24 keyword in the title, otherwise the post may be overlooked among the usual "hello world" problems. |
|
|
smkul13
Joined: 04 Dec 2008 Posts: 8
|
|
Posted: Tue Dec 09, 2008 2:38 am |
|
|
FvM wrote: | If I understand your post right, the wrong TRIS register access is with built-in function UART pin setup? It's not surprising to me, cause there have been various bugs of this kind with PCD, at least regarding PIC24FJ. It's generally advisable to check the code and perform an optional register setup in user code.
By the way, I suggest to use a PIC24 keyword in the title, otherwise the post may be overlooked among the usual "hello world" problems. |
The wrong TRIS register access is not only with built in function set_tris_x() but also when I try to write directly with #byte. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Dec 09, 2008 6:06 am |
|
|
That sounds unlikely, it may be a problem of wrong register display in debugger as well.
I just realized, that your chip is using peripheral pin select registers as the PIC24FJ chips, I'm used too. But I can't see any code configuring peripheral select for the UART pins. I doubt, if it's set from #use rs232 correctly, I'm not even sure, if this action is said to be performed by PCD automaticly.
There are no 6xx SFR addresses implied with the shown RS232 initialization, thus the UART isn't yet connected to any pin. The TRIS registers in contrast are unused with pins routed through peripheral pin select, they are only valid for general IO port accesses.
I suggest to read the PIC24HJ manual thoroughly to understand the concept of peripheral pin select and related register programming. |
|
|
karthik
Joined: 27 Nov 2008 Posts: 7
|
|
Posted: Tue Dec 09, 2008 6:27 am |
|
|
I have been thru lots of such problems. I am using PIC24FJ128GA010 with PCD.
I would strongly suggest using direct registers to configure the peripherals instead of using the in-built functions. I don't use any in-built function and always rely on user defined register configuration.
For instance u can directly configure the uart mode register instead of using the #rs232 directive. This way u can be sure about the code underneath. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Dec 09, 2008 6:53 am |
|
|
I understood now, that the present #use rs232 cmd instantiates a software UART. So the things I said regarding peripheral chip select aren't applicable in this case. I think, a software UART doesn't make sense, and it obviously can't work with an interrupt, as intended.
By omitting the pin statements in #use rs232, a hardware UART is instantiated instead. But it needs setting of peripheral pin selects, to connect it to the pins. A high performance UART with FIFO is waiting to serve you then.
I didn't yet try to understand, why the software UART doesn't work for you, but it seems less interesting to me.
P.S.: I'm not able to force the compiler to use a hardware UART by modifying the present code. I know, that it generally works, but the compiler behaviour seems strange in this regard. O.K., I see, that an UART1 is missing. |
|
|
|
|
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
|