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

PCD: How can I fire #int_rda by PIN_C4?

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







PCD: How can I fire #int_rda by PIN_C4?
PostPosted: Sun Sep 27, 2009 10:26 pm     Reply with quote

Dear all:

From some topics I surveyed, I know that the INT_RDA is accessed by PIN_C6, PIN_C7. Could we change to PIN_C4 and PIN_C5 by setting registers?

Below is the code I tried, but could not work.
(MCU:PIC24FJ64GA004A, compiler version: 4.084)
Code:

#pin_select U1TX = PIN_C5
#pin_select U1RX = PIN_C4

#use rs232(baud=9600, UART1, PARITY=N, BITS=8, STOP=1)

#int_rda
void rda_isr(void)
{

putc(getc());

}   

#bit IOLOCK  = 0x742.6
#byte OSCCONL = 0x742

#byte RPINR18L = 0x6A4
#byte RPINR19L = 0x6A6
#byte RPOR2L = 0x6C4

//========================
void main()
{
OSCCONL = 0x46; // enabling the IOLOCK access
OSCCONL = 0x57;
IOLOCK = 0; // enable preipheral pin programming
RPINR18L = 20; // RX2 = RP20
RPOR2L = 21; // RP4 = TX2
OSCCONL = 0x46;
OSCCONL = 0x57;
IOLOCK = 1;

enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);

while(1);
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Sep 28, 2009 2:17 am     Reply with quote

Quote:
I know that the INT_RDA is accessed by PIN_C6, PIN_C7

No. On processors with peripheral pin select function, UART1 isn't assigned to any pin by default. The #pin_select statement in your code does the assignment. No explicite assignment to pin select SFRs is required.

I see two cases, where it's necessary to write the pin select registers in your code:
- When the pin assignment has to be changed during runtime
- When the PCD built in assignment is incorrect

In your code, the RPINRxx assignment is correct, but the ROPRxx isn't. The operation of ROPRxx has to be the other way round:
The register selects the pin and the assigned value the function.
The correct code is this
Code:
RPOR10H = 3; // RP21 = U1TX


Curiously, the iolock/unlock code doesn't work at all, because W0L is reloaded between the two writes to OSCONL. (I wasn't aware of this issue up to now)
Code:
.................... OSCCONL = 0x46; // enabling the IOLOCK access 
024A:  MOV.B   #46,W0L
024C:  MOV.B   W0L,742
.................... OSCCONL = 0x57; 
024E:  MOV.B   #57,W0L
0250:  MOV.B   W0L,742
.................... IOLOCK = 0; // enable preipheral pin programming 
0252:  BCLR.B  742.6


But no problem! Because it uses the same sequence, the PCD built-in code also doesn't work. IOLOCK remains unset all the time. See the PIC24 manual for a correct assembler coded sequence. If both codes would be correct, the IOL1way fuse must be also disabled, by the way.
PhenixLin
Guest







PostPosted: Wed Sep 30, 2009 3:21 am     Reply with quote

Hi, FvM:
Thanks for youe response.

Quote:
On processors with peripheral pin select function, UART1 isn't assigned to any pin by default.

Do you mean that we can assign PIN to UART1 and trigger INT_RDA by setting SFR? If yes, could you show me a simple example?

Thanks for your help. Wink

~ Phenix
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 3:25 am     Reply with quote

Quote:
assign PIN to UART1 and trigger INT_RDA
I don't understand the and in this case. INT_RDA1 is triggered by U1RX, whatever pin it's assigned to.

The #pin_select statements in your code already do the intended pin assignment.
PhenixLin
Guest







PostPosted: Wed Sep 30, 2009 4:34 am     Reply with quote

I create below code:
Code:

#pin_select U1TX=PIN_B15
#pin_select U1RX=PIN_B14
#use rs232(UART1, baud=9600, stream=COM2, PARITY=N, BITS=8, STOP=1, ERRORS)

#int_RDA
void  RDA_isr(void)
{
   fputc(fgetc(COM2), COM2);
}

void main()
{
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);

   setup_wdt(WDT_OFF);
   setup_timer1(TMR_DISABLED);

   enable_interrupts(INT_RDA);
   enable_interrupts(INTR_GLOBAL);

   while(1)
   {
      fputc('.', COM2);
      delay_ms(1000);
   }
}


The code works well. But if I add another C file which is an empty file and only include main.h into the project and select "Multiple Compilation Units" and "Link Separately" in the project options dialog, the code could not work.
Could you me how could I fire the INT_RDA with "Multiple Compilation Units" and "Link Separately"?
Thanks.

~ Phenix
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 5:10 am     Reply with quote

From what's written in the CCS manual and has been reported in the forum, Multiple Compilation Units seems like a kind of unsupported feature to me. I'm spending sufficient time to get the PCD supported features working, so I'm not actually motivated to evaluate it.

Generally, it's easy to check the list file, if PCD is implementing the correct pin_select code, if the UART functions are accessing the right UART registers and if the ISR is setup correctly.
PhenixLin
Guest







PostPosted: Wed Sep 30, 2009 8:29 pm     Reply with quote

The difference between 2 list files are listed at below:

=====================================
Single link file (Code could work)
<Nothing>

Multiple link file (Code could not work)
026C: CLR 800
026E: MOV #2780,W15
0270: MOV #27FF,W0
0272: MOV W0,20
0274: NOP

-------------------------------------------------------------
Single link file (Code could work)
.................... void main()
.................... {
*
0246: MOV #4444,W0
0248: MOV W0,A8
024A: MOV #10E,W0
024C: MOV W0,6A4
024E: MOV #300,W0
0250: MOV W0,6CE
0252: MOV #46,W0
0254: MOV.B W0L,742
0256: MOV #57,W0
0258: MOV.B W0L,742
025A: BSET.B 742.6

025C: MOV #8000,W4
025E: MOV W4,220
0260: MOV #400,W4
0262: MOV W4,222
0264: BCLR.B 220.3
0266: MOV #19,W4
0268: MOV W4,228
026A: SETM 32C
026C: SETM 32A
026E: MOV #2780,W15
0270: MOV #27FF,W0
0272: MOV W0,20
0274: NOP
Multiple link file (Code could not work)
.................... void main()
.................... {
*
0246: MOV #4444,W0
0248: MOV W0,A8
024A: MOV #8000,W4
024C: MOV W4,220
024E: MOV #400,W4
0250: MOV W4,222
0252: BCLR.B 220.3
0254: MOV #19,W4
0256: MOV W4,228
0258: SETM 32C
025A: SETM 32A
025C: MOV #2780,W15
025E: MOV #27FF,W0
0260: MOV W0,20
0262: NOP
0264: MOV #2780,W15
0266: MOV #27FF,W0
0268: MOV W0,20

026A: NOP
==========================================

Does anybody could show me why the difference make the code could not work?
Thanks.

~ Phenix
PhenixLin
Guest







PostPosted: Wed Sep 30, 2009 9:21 pm     Reply with quote

After checking the OP code table of PIC24FJ64 series, I found that following code execute the #pin select action:
Code:

024A:  MOV     #10E,W0
024C:  MOV     W0,6A4
024E:  MOV     #300,W0
0250:  MOV     W0,6CE
0252:  MOV     #46,W0
0254:  MOV.B   W0L,742
0256:  MOV     #57,W0
0258:  MOV.B   W0L,742
025A:  BSET.B  742.6


The complier did not generate these codes while the multiple link is enable. I tried to add following codes in my program:
Code:

//*************************************
// Unlock Registers
//*************************************
#asm
MOV #0x0742, w1
MOV #0x46, w2
MOV #0x57, w3
MOV.b w2, [w1]
MOV.b w3, [w1]
BCLR 0x0742,#6
#endasm

RPINR18 = 0x010e;
RPOR7 = 0x0300;

//*************************************
// Lock Registers
//*************************************
#asm
MOV #0x0742, w1
MOV #0x46, w2
MOV #0x57, w3
MOV.b w2, [w1]
MOV.b w3, [w1]
BSET 0x0742, #6
#endasm


Then the code works. Razz

I think I have got the solution I need.
Thanks help from FvM.

~ Phenix
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 11:36 pm     Reply with quote

The fact, that the #pin-select code isn't generated with multiple compilations units may be due to a unsuitable placement of this statement in your code.

Please consider, that CCS C has no explicite crt_startup module as other compilers. It's placing the (usually small) startup code at the begin of main(), before the user code. This is also the case with #pin_select code. Because the compiler can't be aware of the code in other modules, all statements that should take effect in the startup code, must be placed in the module containing main(). I don't know if it works with PCD now, but it's the only feasible way. How about your code?

I don't understand, why you marked the stack initialization red? It's basically correct, although the default PCD stack size of 128 is dangerously low, as discussed in another thread.

In my opinion, the discussion illustrates well, why I said, the multiple compilation units option is like an "unsupported feature".
PhenixLin
Guest







PostPosted: Thu Oct 01, 2009 11:50 pm     Reply with quote

Quote:

why you marked the stack initialization red?


I marked the stack initialization code red because I want to show the difference between two files.
Thanks for you help.

~ Phenix
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 02, 2009 4:19 am     Reply with quote

Quote:
I marked the stack initialization code red because I want to show the difference between two files.
I see.

Did you check, if the #pin_select statements are functional in the compilation unit containing main()?
PhenixLin
Guest







PostPosted: Sun Oct 04, 2009 9:25 pm     Reply with quote

Yes, the #pin_select statements are functional in the compilation unit containing main().
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