|
|
View previous topic :: View next topic |
Author |
Message |
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
PIC24FJ32GU205 2nd UART will not receive |
Posted: Fri Jan 19, 2024 11:10 am |
|
|
Hi All,
I am implementing two HW UARTs on my PIC24FJ32GU205. The first UART (UART1) assigned to pins A10/B13(TX/RX) works fine in both directions but the second one (UART2) assigned to pins B9/B8(TX/RX) works only on TX but will not receive.
I checked that TTL incoming RX waveforms (using oscilloscope) are good on B8 pin when I press keys on my Teraterm console. As an experiment, I repurposed B8 as an input pin (to check HW is ok internally), and it can see toggling of the line (when pressing key on my TeraTerm console) so I know the input buffer is working. So now it's a question of why the second RX line is not clocking in characters.
I can see that somehow the UART2 RX buffer is tricked into thinking a byte or start of byte transfer has begun even when I'm not pressing any keys on my teraTerm console because if I add an "output_high(outPINA2);" line after the "fputc(selection, PORT2);" code, it will drive outPINA2 high, which means the UART2 RX buffer thinks a character did come in but I can clearly see on the scope that pin B8(UART2 RX) is high - never toggles low. However, if I press "p" nothing happens in my switch statement - so it's not receiving characters sent from my console.
Here are some snippets of the source and include files pertinent to the UARTS. I did not add any UART1 code because I'm testing one at a time. Would you kindly point out what I'm doing wrong.
I am not doing anything with USB - later I plan on working on that after I resolve this UART2 RX issue.
Main C code:
Code: |
#include <twoUARTS.h>
#include <stdio.h>
void displayMenu();
void main()
{
char selection;
//PORT A PULL-DOWNS
set_pulldown(TRUE, PIN_A2);
set_pulldown(TRUE, PIN_A3);
set_pulldown(TRUE, PIN_A9);
set_pulldown(TRUE, PIN_A11);
set_pulldown(TRUE, PIN_A12);
set_pulldown(TRUE, PIN_A13);
set_pulldown(TRUE, PIN_A14);
//PORT B PULL-UP/DOWNS
set_pulldown(TRUE, PIN_B5);
set_pulldown(TRUE, PIN_B7);
set_pulldown(TRUE, PIN_B14);
set_pullup(TRUE, PIN_B15);
//PORT C PULL-DOWNS
set_pulldown(TRUE, PIN_C0);
set_pulldown(TRUE, PIN_C1);
set_pulldown(TRUE, PIN_C4);
set_pulldown(TRUE, PIN_C5);
set_pulldown(TRUE, PIN_C6);
set_pulldown(TRUE, PIN_C7);
set_pulldown(TRUE, PIN_C8);
set_pulldown(TRUE, PIN_C9);
setup_wdt(WDT_1S);
displayMenu();
do{
do{
restart_wdt();
selection = fgetc(PORT2);
fputc(selection, PORT2);
}
while((selection!='p') && (selection!='c') && (selection!='v') && (selection!='P') &&
(selection!='U') && (selection!='t') && (selection!='i') && (selection!='e') &&
(selection!='g') && (selection!='o') && (selection!='d') && (selection!='u') &&
(selection!='D') && (selection!='L') && (selection!='I') && (selection!='?'));
if(selection == 'p')
{
fprintf(PORT2,"\r\n");
fprintf(PORT2, "Enter resistor value (1=1K, 2=2K, 3=3K, 4=4K, 5=5K 6=OFF: \r\n");
.
.
***More switch statements here but not including them as they are not pertinent***
.
.
void displayMenu(){
restart_wdt();
fprintf(PORT2, "\r\n");
fprintf(PORT2, " ______________________________________________ \r\n");
fprintf(PORT2, "| ***Control Menu*** |\r\n");
fprintf(PORT2, "|----------------------------------------------|\r\n");
fprintf(PORT2, "|p. Enter resistor value |\r\n");
restart_wdt();
fprintf(PORT2 "Enter Selection>");
return;
}
|
Here's the "twoUARTS.h" include file code:
Code: |
#include <24FJ32GU205.h>
#device ADC=12
#device ICD=TRUE
#device ICSP=1
#use delay(clock=32MHz,int=8000000, USB_FULL,restart_wdt)
#FUSES WDT //Watch Dog Timer
//#FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
//#FUSES WPOSTS11 //Watch Dog Timer PostScalar 1:1024
//#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
//#FUSES BROWNOUT //Brownout reset
#use FIXED_IO( A_outputs=PIN_A2,PIN_A3,PIN_A9,PIN_A11,PIN_A12,PIN_A13,PIN_A14)
#use FIXED_IO( B_outputs=PIN_B5,PIN_B7,PIN_B14,PIN_B15)
#use FIXED_IO( C_outputs=PIN_C0,PIN_C1,PIN_C4,PIN_C5,PIN_C6,PIN_C7,PIN_C8,PIN_C9)
//I/O Port A Definitions
#define outPinA2 PIN_A2
#define outPinA3 PIN_A3
#define outPinA9 PIN_A9
#define outPinA11 PIN_A11
#define outPinA12 PIN_A12
#define outPinA13 PIN_A13
#define outPinA14 PIN_A14
//I/O Port B Definitions
#define outPinB5 PIN_B5
#define outPinB7 PIN_B7
#define outPinB14 PIN_B14
#define outPinB15 PIN_B15
//I/O Port C Definitions
#define outPinC0 PIN_C0
#define outPinC1 PIN_C1
#define outPinC4 PIN_C4
#define outPinC5 PIN_C5
#define outPinC6 PIN_C6
#define outPinC7 PIN_C7
#define outPinC8 PIN_C8
#define outPinC9 PIN_C9
#pin_select U1TX=PIN_A10
#pin_select U1RX=PIN_B13
#use rs232(UART1, baud=115200, errors, parity=N, bits=8, stream=PORT1, restart_wdt)
#pin_select U2TX=PIN_B9
#pin_select U2RX=PIN_B8
#use rs232(UART2, baud=115200, errors, parity=N, bits=8, stream=PORT2, restart_wdt)
#bit U1OTGSTAT_SESVD=getenv("BIT:SESVD")
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_SESVD)
#define USB_CONFIG_VID 0x04D8
#define USB_CONFIG_PID 0x000A
#define USB_CONFIG_BUS_POWER 500
#include <usb_cdc.h>
#build(stack=1024)
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jan 19, 2024 11:58 am |
|
|
While I don't use that PIC ...
I'd....
1) get RID of the WDT. NOT needed.
2) cut a simple 'loopback' program.. press key on PC ,goes to PIC, PIC sends it back to PC, PC displays on screen. Nothing 'fancy', a simple basic program.
If that doesn't work, post it |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Fri Jan 19, 2024 12:41 pm |
|
|
Get rid of #use FIXED_IO until you have things working.
Post your complier version. |
|
|
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
|
Posted: Fri Jan 19, 2024 12:52 pm |
|
|
Hi Temtronic,
Thank you for your prompt response.
I simplified the code and removed the WDT.
I still can not see characters looped back to console.
I also tested with the same code below on UART1 and I can see characters on that port bouncing back to console.
Here's the new code:
Code: |
#include <twoUARTS.h>
#include <stdio.h>
void displayMenu();
void main()
{
char selection;
do{
fprintf(PORT2, "Press Key>");
selection = fgetc(PORT2);
fputc(selection, PORT2);
}
while(TRUE);
} |
|
|
|
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
|
Posted: Fri Jan 19, 2024 12:55 pm |
|
|
Hi gaugeguy,
I've used fixedio for years without issues. I don't think that is contributing to this issue as I have tested it out on UART1 and it's working fine. The issue is with UART2 RX pin B8.
For s***s and giggles I removed the #use fixedio lines but still, no RX characters are appearing on B8. |
|
|
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
|
Posted: Fri Jan 19, 2024 1:10 pm |
|
|
I tried posting this twice and it's not appearing on the forum. Wonder if server's down or I had something on my post that was flagged.
Lets try it one more time.
Temtronic:
I noticed on pin list (page 16 of spec) that RP8 is not in bold text. Note 1 says RPn and RPIN represent mappable pins for PPS functions. Could it be that I chose a non mappable PPS pin and this is why RX on UART2 is not working? |
|
|
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
|
Posted: Fri Jan 19, 2024 1:41 pm |
|
|
Problem Resolved!!
RB8 was not a mappable PPS pin so I couldn't route UART2 RX internally to that pin.
I just swapped pins with RB7 and now I see characters rolling up into UART2.
You can close this ticket now.
Thanks. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jan 19, 2024 1:57 pm |
|
|
NICE, it works.....
I've seen it before... the 'illusion' that PPS means ANY peripheral can be mapped to ANY pin...
..sometimes it does pay to read some of the 700-800 pages of the 'datasheet'. |
|
|
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
|
Posted: Fri Jan 19, 2024 2:01 pm |
|
|
I try to get away without reading the spec as much as possible but it's always those mundane details like PPS assignments that get me.
One of these days when I can't go to sleep I'm going to read up on a few chapters of the PIC24FJ data sheet... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jan 19, 2024 3:05 pm |
|
|
by page 33, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Fri Jan 19, 2024 11:12 pm |
|
|
I would point this out to CCS. Normally the compiler will give a warning
if you try to use a pin that is not supported,
Classically annoying!... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Jan 21, 2024 8:35 am |
|
|
re: Classically annoying!...
gee, anyone remember waiting 15 MINUTES to erase PICs ??? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun Jan 21, 2024 8:41 am |
|
|
Remember it more with other processors. Still have an eraser somewhere.
Even with half a dozen chips, you always seemed to be waiting for one
to erase. |
|
|
robleso7473
Joined: 25 Mar 2009 Posts: 47
|
|
Posted: Tue Feb 06, 2024 2:43 pm |
|
|
I remember those days where you had to whip out the UV eraser.... How far we've come yet we still want it faster and are never really satisfied. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Feb 06, 2024 6:39 pm |
|
|
I'd rather go BACK to say WIN98 days. the last version of OS that gave YOU control over the REAL comports and had true interrupts on them.
I'd also like to meet the 'genius' that decided that pins 2 and 3 of the 25 pin comports were reversed when the 9 pin came out....grrrrrrrrrrrrrrrrrrrrrrrrr!
Also like to know why I can't run my QB45 programs on my PC,sniff,sniff
guess I'm a 'grumpysaurus'........
Jay |
|
|
|
|
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
|