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

Problem with PIC24FJ128GA010
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
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

Problem with PIC24FJ128GA010
PostPosted: Sun Dec 20, 2009 11:06 pm     Reply with quote

hi
I am unable to program UART of PIC24FJ128GA010.

I want to transmit data from hyperterminal to PIC and then receive it

Please help me in this case and what is diff in software and hardware UART.
I was given following code:
Code:

#pin_select U1TX = PIN_R3
#pin_select U1RX = PIN_R2
#use rs232(UART1, baud=9600, errors)
printf("Hello world\r\n");

But it gives error in first 2 lines.

Please give me full code for my question.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Dec 20, 2009 11:46 pm     Reply with quote

You can't do #PIN_SELECT for that part. The PIC24FJxxxGA010 doesn't have pin mapping.

U1TX = PIN_RF3
U1RX = PIN_RF2

So you have to use those pins for your UART.

(U2TX = RF5, U2RX=RF4)


Regards,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 21, 2009 1:21 am     Reply with quote

i still cant program uart for my pic

i am using 24 bit project wizard.

i write the following code
U1RX=PIN_B9
U1TX=PIN_B8
#use rs232(UART1,baud=9600,parity=N,bits=8)

void main()
{
while(1)
{
c = getc();
put(c);
}
first of all it is giving error in first 2 lines.
when i replace it with software uart so that i give IO pins in @ use definition it gives no error but dont show anything when i run it via MPLAB on my PIC.

plz help
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Dec 21, 2009 1:30 am     Reply with quote

You can't do this:

U1RX=PIN_B9
U1TX=PIN_B8


You need to delete those lines.

You have to use the pins as shown on the datasheet for UART1's TX and RX.

They are not re-assignable.

Just do the following:

Code:

(put in your fuses and device up here)


#use rs232(UART1,baud=9600,parity=N,bits=8)

void main() {
   char c;

   while(1) {
      if (kbhit()) {
         c = getc();
         put(c);
     }
   }
}

_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 21, 2009 1:46 am     Reply with quote

I erroneously suggested the pin select statements. As bkamen clarified, the PIC24xxGA010 don't need or understand it.
It has fixed pins for UART1 and UART2. The shown code is to supposed to work for UART1.

Generally, when starting with a new chip, you should read the datasheet.
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 21, 2009 3:39 am     Reply with quote

well i wrote the code as it is given but still it dont work.
it compiled but when i try to execute it in Proteus or in microcontroller it wont work.
i dont recieve ant data or sent any data.
i have seen that UART1 got F2 and F3 pins as transmitt and recieve.
i have programmed them as output and input for respective functions in startup but still it isnt working.
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

Still Problem, HELP HELP HELP
PostPosted: Mon Dec 21, 2009 8:26 am     Reply with quote

my code is

Code:
#use rs232(UART1,baud=9600,parity=N,bits=8)

void main() {
   char c;

   while(1) {
      if (kbhit()) {
         c = getc();
         put(c);
     }
   }
}

Even this code is not working.
I am setting pin F2 and F3 as input or output depending on function they are serving at startup. As these are transmit and receive pins for UART1 but still no work.
Code compiles successfully but when I test it on PROTEUS or on my microcontroller via MPLAB it won't work.
It neither transmits nor receives whenever I press any key.
HyperTerminal settings are 100% ok...

I select hardware UART from startup also I tried software UART but it won't work.
I select 24 bit project at start.
Where am I going wrong??????

What is the PROBLEM ???
I'm confused
plz help
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 21, 2009 9:46 am     Reply with quote

put() is no known CCS built-in function, so I wonder which text has been compiled?

Using putc() and a meaningful #use delay() statement, the code is working correctly according to MPLAB SIM,
both with an "old" V4.084 and recent V4.103 PCD. You may want to start with checking your oscillator frequency and
hardware connections with a simple "send only" test.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Dec 21, 2009 10:03 am     Reply with quote

Do you know for sure the processor is even running?

Try this in Main():

Code:

void main() {
char c;

   output_low(PIN _NUMBER); // <== put in desired pin number
   delay_ms(500);
   output_high(PIN _NUMBER); // <== put in desired pin number
   delay_ms(200);

while(1)
{

   if (kbhit())
     {
        c = getc();
         putc(c);
    }
   output_toggle(PIN_NUMBER); // <== use same pin number as above
   delay_ms(100);
}



Insert same the desired pin # in all the output_ statements added above.
Run the program and see if that pin initially goes low then high after 500ms.

If the pin initially goes low then high after 500ms it means the processor is at least running.

If the pin initially goes low then high after 500ms and continues to toggles high and low every 100ms it means the processor is running the entire program and you likely have UART connection issues.

If the pin never changes it means the processor is likely not working and you need to deal with that first.

Once you prove the entire program is running you can comment out the output_toggle and delay_ms(100) statements in the While() loop to keep it from interfering with the UART functions.
_________________
Google and Forum Search are some of your best tools!!!!
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

@ dyeatman
PostPosted: Mon Dec 21, 2009 11:27 pm     Reply with quote

I wrote the following code as per your instructions:
Code:

#use rs232(UART1,baud=9600,parity=N,bits=8)

void main() {
   char c;

   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);


   setup_wdt(WDT_OFF);
   setup_timer1(TMR_DISABLED);

   output_low(PIN_A0); // <== put in desired pin number
   delay_ms(500);
   output_high(PIN_A0); // <== put in desired pin number
   delay_ms(200);

while(1)
{

   if (kbhit())
     {
        c = getc();
         putc(c);
    }
   output_toggle(PIN_A0); // <== use same pin number as above
   delay_ms(100);
}

The pins are toggling in the right way as they should be but still I am not able to transmitt or receive anything.
At startup I select 24 bit wizard project.
Also I make pin F2 as input and F3 as output because F2 is receiver for uart and F3 in transmitter.
Also serial connections are correct, I am using PC Hyperterminal on other side.

Now where the problem lies????
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Dec 22, 2009 1:00 am     Reply with quote

are you using all this on an Explorer16 board?

-ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Dec 22, 2009 1:20 am     Reply with quote

Still missing:
- Compiler version
- #fuses configuration
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

@bkaman
PostPosted: Tue Dec 22, 2009 1:31 am     Reply with quote

@ bkaman
Yes I am doing it on Explorer 16 board.

Also now when I change from UART1 to UART2, the communication starts but the character I send is not received. It is receiving garbage.

Baud rates are same on both sides and all other settings are also same.

What's the problem in this case?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Dec 22, 2009 2:02 am     Reply with quote

Possibly incorrect #fuses or #use delay, see above.
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 22, 2009 3:24 am     Reply with quote

Yes I am doing it on Explorer 16 board.

Also now when I change from UART1 to UART2, the communication starts but the character I send is not received. It is receiving garbage.

Baud rates are same on both sides and all other settings are also same.

What's the problem in this case?

in main file the fuses and delay are created as below
#include <24FJ128GA010.h>
#device ICD=TRUE

#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES DEBUG //Debug mode for use with ICD
#FUSES NOCOE //Device will reset into operational mode
#FUSES ICS1 //ICD communication channel 1
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FRC_PS //Fast RC Oscillator with Post Scaler
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is general purpose output
#FUSES NOPR //Pimary oscillaotr disabled

#use delay(clock=8000000)

I have included this main file in project. now the problem is of recieving of garbage data.
where is the fault??
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