CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

UART 2 on PIC 24FJ not receiving data
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

UART 2 on PIC 24FJ not receiving data
PostPosted: Wed Oct 23, 2019 2:58 pm     Reply with quote

Device: PIC24FJ1024GB606
CCS: v5.078
MPLAB X IDE: v5.15

I have a working program with two UARTs, on UART 1 I receive GPRS data and is working ok at 115200bps.

UART 2 same configuration different pins not receiving at all.
The data is present on PIN RG9; I already check it with an oscilloscope and have the same shape as UART 1 RX.

This is a summary of the code used to setup the UART2

Code:
#pin_select U2TX=PIN_D5
#pin_select U2RX=PIN_G9
#use rs232(UART2,stream=GPS,NOINIT)

#INT_RDA2
void RX2_ISR()
{

}

void main()
{

   set_tris_d(0b111100000011);
   set_tris_g(0b11001000000);
   
   setup_uart(115200,GPS);
   enable_interrupts(INT_RDA2);
   enable_interrupts(GLOBAL);
}


Am I forgetting something?
_________________
Electric Blue


Last edited by E_Blue on Wed Oct 23, 2019 3:09 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 3:06 pm     Reply with quote

You're missing the fgetc(GPS) statement in the isr.
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 3:11 pm     Reply with quote

No, I do have code inside the UART 2 ISR, I just don't show it to make more clear how I set it up UART 2.
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9104
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 4:33 pm     Reply with quote

You should always post a small, complete compilable program , that way we can 'cut/paste/compile/test'....and report back fast, maybe in minutes. Leave 'something', anything out and well, it's a guessing game as to why it doesn't work.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 12:27 am     Reply with quote

Disable the comparator.

Generally analog functions have higher priority than RP functions, and these
then have higher priority than normal I/O. You have to ensure the higher
priority uses are disabled on pins. The compiler (on reasonably recent versions)
automatically disables the ADC I/O, but the comparator normally requires
explicit turning off. Pin G9 has comparator inputs on it by default.
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 7:51 am     Reply with quote

I just added at main start

Code:
setup_comparator(1,NC_NC);
setup_comparator(2,NC_NC);
setup_comparator(3,NC_NC);

And also a 16bit variable to count the times that RG9 is in 1 every 33mS and doesn't change from zero.
Is like the inside logic doesn't notice the external pin level.
Now I'm checking Parallel Master/Slave Port and Output Compare registers; I'm getting out of options.
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9104
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 8:50 am     Reply with quote

hmm.. this...
Quote:
set_tris_d(0b111100000011);
set_tris_g(0b11001000000);

while I don't use that PIC, does PORT G really have 11 bits and PORTD 12 bits ??
again, please show use ALL your code, the complete program.

Jay
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 9:07 am     Reply with quote

As far I know 0b00001100 = 0b1100

The complete program have more than 12K lines and some minor .h files.
Now I'm writing a smaller program to only use the USARTs and some pins to turn up the Modem & GPS.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 11:26 am     Reply with quote

Try explicitly setting ANSG.
I remember an issue a few versions ago, where the compiler was not
correctly setting the bits for this.

#WORD ANSG=getenv("SFR:ANSG")

ANSG=0;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 12:03 pm     Reply with quote

Try making a test program without the 12K lines. Maybe something in those
12K lines is clobbering the Rx pin. Make a short program that only talks
to UART2. Don't include UART1 in the program. See if you can make that
work. Also, it would be short and you could post the whole thing.
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Fri Oct 25, 2019 7:24 am     Reply with quote

I made a program to send a text every 500mS on UART2 and made a short circuit with a 220ohm resistor and works ok.

The GPS and Modem are 1.8V logic and the PIC is 3.3V logic so I'm using this to both, the modem and the GPS TX UART interface.



Here the GPS data on RG9


Here the Modem data on RB6


Although both signals seems the same levels and rise times the modem is running ok on RB6(RX1) but the same doesn't work for RG9(RX2).
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9104
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 25, 2019 7:39 am     Reply with quote

You really need proper 'logic level translators' ! Those are TERRIBLE 'squarewaves'.....A risetime of 50-70% is totally unacceptable.
Now you _might_ get better results at a slower baud rate, say 300 or 600, but really, you need to havve sharp, crisp edges.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Fri Oct 25, 2019 7:48 am     Reply with quote

The big reason with the circuit, is the use of 10K for the pullups.
At 3.3v, just 0.33mA and falling as the voltage rises. Something like 3mA
is a much more sensible current to slew the rail at a reasonable rate....
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Fri Oct 25, 2019 2:59 pm     Reply with quote

Ttelmah wrote:
Try explicitly setting ANSG.
I remember an issue a few versions ago, where the compiler was not
correctly setting the bits for this.

#WORD ANSG=getenv("SFR:ANSG")

ANSG=0;


Guess what...was the stupid ANSG. Confused Embarassed

I know it! It had to be something very stupid, damn! Mad

Two days and half because this stupid thing, unbelievable. Rolling Eyes
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9104
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 25, 2019 3:32 pm     Reply with quote

Some days you have to read the datasheet.... whatever you need is usually BURIED in the 'fine print' 2-3 HUNDRED pages in......
The real 'gotcha' is when 'they' change the default values to some bits or some registers for some reason...
also

Never, EVER trust a 'Wizard'...they were programmed by someone else who's idea of 'defaults' are never yours !

Look on the bright side, you only lost 2.5 days.......BUT you got it 'up and running' !

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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