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 CCS Technical Support

How to configure peripheral pin selection on PIC24[resolved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sysc



Joined: 26 Oct 2007
Posts: 8

View user's profile Send private message

How to configure peripheral pin selection on PIC24[resolved]
PostPosted: Wed Mar 09, 2011 8:19 am     Reply with quote

Hi, I'm trying to configure the peripheral pin selection for UART1 on PIC24.

I tried:
Code:

#pin_select U1RX=PIN_G8
#pin_select U1TX=PIN_G6
#use rs232(UART1,baud=9600,parity=N,bits=8)

And put a break point at main loop,
I opened the Watch to see the registers RPINR18=0x3f3f and RPOR1 = 0x0000.

It's look like that the "#pin_select" isn't been configured properly.


Last edited by sysc on Thu Mar 10, 2011 2:53 pm; edited 2 times in total
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 1:05 pm     Reply with quote

It would be nice to see a small, complete, test program that we can compile and run. It also helps if you post both the compiler version you are using and the particular PIC24 you are using.

The only guess off the top of my head given so little information is that you could be calling #pin_select on the same RP pin more than once somewhere else in your program and haven't enabled writing to that register multiple times. That is only a guess though. We need more info to really evaluate the problem
sysc



Joined: 26 Oct 2007
Posts: 8

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 2:21 pm     Reply with quote

The PIC that I'm using is PIC24FJ256GA110.
MPLABIDE vs8.63
PCWHD Compiler vs4.084

It's a start of program, so doesn't have any function call only a main with some initialization port.

Code:
#include <24FG256GA110.h>

//Do some configuration "#fuse"

#pin_select U1RX=PIN_G8
#pin_select U1TX=PIN_G6
#use rs232(UART1,baud=9600,parity=N,bits=8)

void main(){
 /* some configuration port
  set_trisx()
  output_x()
*/

 for(;;){
  delay_cycles(1);
 }
}
sysc



Joined: 26 Oct 2007
Posts: 8

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 2:43 pm     Reply with quote

other information:

at the "Output Window" - "MPLAB SIM"

is showing this error:

UART-W0005: Uart is enabled but no output destination has been assigned (File or Output Window)
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 3:27 pm     Reply with quote

Interestingly enough, I am running the PIC24FJ256GA106, which happens to be in the same family as the 110 (they even use the same datasheet).

I took one of my old test programs and ran it:

Code:

/*******************************************************************************
* FILENAME:  wf.c
* DESC:      This is the definition file for main program.  It contains the
*            main() entry point and interrupt routinse (as well as some utility
*            functions.
* COMPILER:  CCS PCWHD Revision 4.114
*
* REVISION:
*    2010/09/23 - JHB - Revision 1.0.0.0
*   
*******************************************************************************/
#case
#include <24FJ256GA106.h>

//16 bit pointers
#device *=16

//Fuses for this project
#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 NODEBUG                  //No Debug mode for ICD
#FUSES ICSP1                    //ICD uses PGC1/PGD1 pins
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES WDT128                   //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO                   //Internal External Switch Over mode enabled
#FUSES PR                       //Pimary oscillaotr enabled
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES HS   

//Pin selects for reprogrammable pins
#pin_select U1TX = PIN_B6   //output serial 
#pin_select U1RX = PIN_B7                   

//#use statements for uart
#use delay(clock=22118400)
#use rs232(UART1,baud=9600,parity=N,bits=8,DISABLE_INTS,ERRORS)

////////////////////////////////////////////////////////////////////////////////
// NAME:  main()
// DESC:  The entry point into this program.  Devices and interrupts are setup.
// IN:    NONE
// OUT:   NONE
////////////////////////////////////////////////////////////////////////////////
void main(){

   rs232_errors = 0;  //removes warning
   
   //Power up and see reason for power up
   printf("\r\n ******** START ******** \r\n");
   printf("SYS:\t");
   switch(restart_cause()){
      case RESTART_POWER_UP:      printf("RESTART_POWER_UP\r\n");      break;
      case RESTART_BROWNOUT:      printf("RESTART_BROWNOUT\r\n");      break;
      case RESTART_WATCHDOG:      printf("RESTART_WATCHDOG\r\n");      break;
      case RESTART_SOFTWARE:      printf("RESTART_SOFTWARE\r\n");      break;
      case RESTART_MCLR:          printf("RESTART_MCLR\r\n");          break;
      case RESTART_ILLEGAL_OP:    printf("RESTART_ILLEGAL_OP\r\n");    break;
      case RESTART_TRAP_CONFLICT: printf("RESTART_TRAP_CONFLICT\r\n"); break;
      default:                    printf("UNKNOWN RESTART\r\n");       break;
   }
   
   while(TRUE){}

}



I don't run MPLAB, so I can't say anything about how the watch variable will react, but that program will run on my PIC and print data out the serial port (just tested it).

Try taking that program and change:

1. The include to the 110 chip .h file
2. The pin_select statements to match your pins
3. The #use delay() statement to your clock speed
4. The fuses to what your typically use.

After you compile it, check your .lst file. This is what mine had in the pertinent section:
Code:

.................... void main(){
0033C:  BSET.B  81.7
0033E:  MOV     #1F07,W0
00340:  MOV     W0,6A4
00342:  MOV     #3,W0
00344:  MOV     W0,6C6
00346:  MOV     #46,W0
00348:  MOV.B   W0L,742
0034A:  MOV     #57,W0
0034C:  MOV.B   W0L,742
0034E:  BSET.B  742.6
00350:  CLR     800
00352:  MOV     #8000,W4
00354:  MOV     W4,220
00356:  MOV     #400,W4
00358:  MOV     W4,222
0035A:  BCLR.B  220.3
0035C:  MOV     #47,W4
0035E:  MOV     W4,228
00360:  SETM    32C
00362:  MOV     #4780,W15
00364:  MOV     #47FF,W0
00366:  MOV     W0,20
00368:  NOP     


The first few instructions correctly set the RP registers for me. See if your .lst file does as well (should be right where main() starts).

I'll try out a variant of your code tomorrow. I just got back to my desk and have to leave soon.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 5:03 pm     Reply with quote

Quote:
PCWHD Compiler vs4.084

As far as I remember, #pin_select isn't implemented correctly with this version
sysc



Joined: 26 Oct 2007
Posts: 8

View user's profile Send private message

PostPosted: Thu Mar 10, 2011 7:56 am     Reply with quote

Hi,

I did the modifications and i saw the .lst file.

It showed:

Code:
....................................void main (void){
0036E:  MOV  #113,W0
00370:  MOV  W0,698
00372:  MOV  #300,W0
00374:  MOV  W0,6D4
.....


So for the tx option for the PIN_G6 (#pin_select U1TX=PIN_G6) is ok!
00372: MOV #300,W0
00374: MOV W0,6D4
The address "6D4" = RPOR2, with the value = 0x0300 = U1TX

but for the rx option for the PIN_G8 (#pin_select U1RX=PIN_G8) it isn't ok!
0036E: MOV #113,W0
00370: MOV W0,698
The address "698" = restricted memory.

So I have two doubts
1) - I don't understand why "0036E: MOV #113,W0", Byte Hi = 1?
Byte Lo = is ok because 13h = 19d = PIN_G6 = RP19.
2) - And "00370: MOV W0,698" with the wrong address of memory.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Mar 10, 2011 9:31 am     Reply with quote

At least since PCD V4.098 you get this result
Code:
00202:  MOV     #113,W0
00204:  MOV     W0,6A4
00206:  MOV     #300,W0
00208:  MOV     W0,6D4


Recent compilers (V4.112 ..) have
Code:
00202:  MOV     #F113,W0
00204:  MOV     W0,6A4
00206:  MOV     #300,W0
00208:  MOV     W0,6D4
sysc



Joined: 26 Oct 2007
Posts: 8

View user's profile Send private message

PostPosted: Thu Mar 10, 2011 10:42 am     Reply with quote

Hello FvM.

It means that the PCD V4.084 that i'm using won't work?

What are the options to i correct this and work properly?

Thanks.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Mar 10, 2011 11:16 am     Reply with quote

Quote:
It means that the PCD V4.084 that i'm using won't work?

Yes, that's what I told you before. You can write the peripheral select SFRs directly in your code. I'm doing this generally in projects that have been started with buggy PCD versions.

Code:
#byte RPOR4L = 0x6C8
RPOR4L = 3;    // UART1 Transmit
sysc



Joined: 26 Oct 2007
Posts: 8

View user's profile Send private message

PostPosted: Thu Mar 10, 2011 11:40 am     Reply with quote

Ok.

Thank you!
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Fri Mar 11, 2011 7:44 am     Reply with quote

Maybe one of the more experienced users here could comment, but I *think* you can also modify the chip database somehow and have it point to the correct address, but I have never messed with that, so I am not 100% on that.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Mar 11, 2011 11:25 am     Reply with quote

As far as I understand, #pin_select code isn't derived from the device file, or at least not from a part that can be modified with the Device Editor Tool.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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