|
|
View previous topic :: View next topic |
Author |
Message |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 23, 2010 4:05 pm |
|
|
Quote: | "1. Disable any fixed digital peripherals on the pins to be used."
You need to turn the UART 'off', before trying to remap. |
In my view, fixed digital peripherals is meant in contrast to PPS mapped ones, and doesn't apply to the UART in this case. But you can try.
Regarding IOLOCK bit, at least with present PCD versions, the PPS registers are unlocked by default, so you don't need any unlock/lock code. |
|
|
rsappia
Joined: 22 Dec 2010 Posts: 12
|
|
Posted: Thu Dec 23, 2010 4:13 pm |
|
|
Hi!
I guess its a good suggestion...
setup_uart(FALSE); I tried with this... but still the same result :( |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 23, 2010 4:54 pm |
|
|
Quote: | Doing RPOR0 = 0x0000; wouldn't make RB0/RB1 to get disconnected from UART1?... |
It's not clear to me, where you mean to see the code to fail. UART1 is initially connected to RB15 by
#pin_select statement accoprding to the posted code, it won't be disconnected from RB0. |
|
|
rsappia
Joined: 22 Dec 2010 Posts: 12
|
|
Posted: Thu Dec 23, 2010 5:09 pm |
|
|
I'll comment the piece of code so we understand each other ;)
Code: |
//in the .h:
#use delay(clock=20000000)
#pin_select U1TX =PIN_B15 // I set B15 as first output. Later, I'll need to change this output to RB0 (to use UART1 for other purposes with other RS232 receptor)
#pin_select U1RX=PIN_B1
While(1) //infinite loop, just for testing purposes
{
unlockIO();// Ok, it can be ommited because as you said, IOLOCK is unlocked by default.
RPOR0 = 0x0000; // Doing this, I ask UART1 not use RB0/1 as output
RPOR7 = 0x0300; // Here, I ask UART1 TXD1 to be RP15 RB15
lockIO();// can be ommited also
printf ("\n \r Now I use RB15"); //If it was well configured, I expect to get this msg coming out from RB15. Im expecting RB0 to be mute... but RB0 will also transmit this msg :(!!
delay_ms(50);
unlockIO();// Ok, it can be ommited because as you said, IOLOCK is unlocked by default.
RPOR7 = 0x0000;// Doing this, I ask UART1 not use RB14/15 as output
RPOR0 = 0x0003; //Here, I ask UART1 TXD1 to be RP0 RB0
lockIO() ;// can be ommited also
delay_ms(1);
printf ("\n \r Now I use RB0"); If it was well configured, I expect to get this msg coming out from RB0. Im expecting RB15 to be mute...but RB15 will also transmit this msg :(!!
}
|
And thats it! I hope I was clear enough!! This is only for test purposes. Later, I will connect different RX to RPx pins, so I will change the output of UART1 in order to send the necessary messages to the different devices, otherwise, I would need to use a pic with... several uarts (probably more than 4...). |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Dec 24, 2010 1:49 am |
|
|
According to your observation, the problem is, that both outputs are transmitting the data?
But how do you see it? You're executing the code in an infinite loop.
I didn't notice the loop before, so my question was simply about the fact, that RB15 is selected initially and thus not changed in the first switch action. |
|
|
rsappia
Joined: 22 Dec 2010 Posts: 12
|
|
Posted: Tue Dec 28, 2010 5:22 pm |
|
|
Quote: | FvM
PostPosted: Fri Dec 24, 2010 1:49 am Post subject:
According to your observation, the problem is, that both outputs are transmitting the data?
But how do you see it? You're executing the code in an infinite loop.
I didn't notice the loop before, so my question was simply about the fact, that RB15 is selected initially and thus not changed in the first switch action. |
Hi! I guess I'm not getting what is your question about... What do you mean when you ask me how do I see it?
I have connected one virtual terminal per each port, infinite loop will just repeat infinitely this writing process (this is just for debugging purposes).
I wish everybody a Merry Christmas and happy New year! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Dec 29, 2010 2:02 am |
|
|
O.K., the different print text identifies the two print statements. But what happens initially, before RPORx has been written by your code? If the output goes to both outputs from the start, it can't be a problem of PPS handling. |
|
|
rsappia
Joined: 22 Dec 2010 Posts: 12
|
|
Posted: Wed Dec 29, 2010 5:24 am |
|
|
What I see is that, first time I run this loop, the first printf ("\n \r Now I use RB15"); is transmitted ok, in RB15 and RB0 stays mute. Then, I configure the RB0 as output and RB15 as default value 0x0000 (this should get RB15 disconnected from UART1... shouldnt it?) and then, when i print printf ("\n \r Now I use RB0");... here is when i see this msg being printed in both ports :(...
Im thinking about forcing the port that I dont want to use, to be an open drain input... without pull resistor... doing this way is just a patch... but it will let me go ahead... I'll comment later! (I listen to better patches than this nasty one ;) ) |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Dec 29, 2010 6:02 am |
|
|
I tried a similar sequence on a 24FJ128GA106 and it worked as expected. The original TX pin is correctly deactivated by writing 0 it's RPORx register.
Either you have a simple case of crosstalk, because the deactivated TX pin is set to Tristate without a pull-up and picking up the signal of the alternative TX pin.
Or there is a special issue with your PIC24 type. |
|
|
rsappia
Joined: 22 Dec 2010 Posts: 12
|
|
Posted: Wed Dec 29, 2010 6:08 am |
|
|
Thanks FvM, right now, im about to try with other model (24fj64ga002) to see what happens! |
|
|
rsappia
Joined: 22 Dec 2010 Posts: 12
|
|
Posted: Wed Dec 29, 2010 8:46 am |
|
|
FvM wrote: | I tried a similar sequence on a 24FJ128GA106 and it worked as expected. The original TX pin is correctly deactivated by writing 0 it's RPORx register.
Either you have a simple case of crosstalk, because the deactivated TX pin is set to Tristate without a pull-up and picking up the signal of the alternative TX pin.
Or there is a special issue with your PIC24 type. |
This is weird... Now instead of having the output repeated in both ports, I have the "Now I use RB4" and the "Now I use RB5" comming out from the same port... the other (RB4) stays mute...
Here is the code I used for the PIC24FJ64GA102:
The .h
Code: |
#include <24FJ64GA102.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 ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES PR //Primary Oscillator
#FUSES NOCKSNOFSM
#FUSES NOOSCIO //OSC2 is clock output
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES WPFP4
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES SOSC_HIGH
#FUSES WUT_DEFAULT
#FUSES DSWDT
#FUSES DSBOR
#FUSES RTCOSC_SOSC
#FUSES DSWDTCK_LPRC
#FUSES WPOSTS1 //Watch Dog Timer PostScalar 1:1
#FUSES I2C1SELD
#FUSES WPFP
#word RPOR2=0x6C4 //registro de configuracion de salida para RP4/5
#word RPINR18L = 0x6A4 //registro de configuracion de entrada para U1RXd
#bit IOLOCK = 0x742.6
#use delay(clock=4000000)
#pin_select U1TX =PIN_B4
#pin_select U1RX=PIN_B3
#use rs232(UART1,baud=4800,parity=N,bits=8,ERRORS)
void unlockIO(void);
void lockIO(void);
|
The main code:
Code: |
#include <Prueba PIC24FJ64GA102.h>
void main()
{
setup_spi( FALSE );
setup_spi2( FALSE );
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
set_tris_b=0x00;
while (1)
{
setup_uart(FALSE);
delay_ms(10);
unlockIO();
RPOR2 = 0x0300; // UART1 TXD1 ---> RP5 RB5
lockIO();
setup_uart(TRUE);
delay_ms(10);
printf ("\n \r Now I use RB5");
delay_ms(50);
setup_uart(FALSE);
delay_ms(10);
unlockIO();
RPOR2 = 0x0003; // UART1 TXD1 ---> RP4 RB4
lockIO() ;
setup_uart(TRUE);
delay_ms(10);
printf ("\n \r Now I use RB4");
delay_ms(50);
}
}
/********************************
* Function: lockIO
* Preconditions: None.
* Overview: This executes the necessary process to set the IOLOCK bit
* to lock I/O mapping from being modified.
* Input: None.
* Output: None.
********************************/
void lockIO(){
#asm
mov #0x742,w1
mov #0x46,w2
mov #0x57,w3
mov.b w2,[w1]
mov.b w3,[w1]
bset 0x742,#6
#endasm
}
/********************************
* Function: unlockIO
* Preconditions: None.
* Overview: This executes the necessary process to clear the IOLOCK
* bit to allow I/O mapping to be modified.
* Input: None.
* Output: None.
********************************/
void unlockIO(){
#asm
mov #0x742,w1
mov #0x46,w2
mov #0x57,w3
mov.b w2,[w1]
mov.b w3,[w1]
bclr 0x742,#6
#endasm
}
|
|
|
|
|
|
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
|