+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Newbie level 1
    Points: 1,174, Level: 7

    Join Date
    Jun 2009
    Posts
    1
    Helped
    0 / 0
    Points
    1,174
    Level
    7

    PIC18F46J50 Problem UART2

    Hello,
    I need help.

    PIC USED 18F46J50
    Compiler MikroC PRO

    Set RX2 and TX2 in the RP0 RP1.
    Puertos TX1 and RX1 occupied.
    code used
    Code:
    {
        RCSTA2.SPEN=1; // activate USART2
        TRISA.F0=1;	   //RX2 Input
        TRISA.F1=0;	   //TX2 Output
    
        INTCON.GIE=0;  // disable interrupts    EECON2=0X55;   //
        EECON2=0XAA;
        PPSCON.IOLOCK=0;// Allows you to change pin
    
        RPINR16=0X00;   //RX2 em RP0
        RPOR1=0X05;	    //TX2 em RP1
    
        EECON2=0X55;
        EECON2=0XAA;
        PPSCON.IOLOCK=1;// closes mapping
        INTCON.GIE=1;   // enable interrupts
    	.
    	.
    	.
    	.
    	.
    UART2_Init(9600);
    }

    Problem - Error when starting the UART2, will the mapping is done well?
    Lack set any records?
    other code that has been tried:
    Code:
    {	Unlock_IOLOCK();
        	PPS_Mapping_NoLock(0, _INPUT, _RX2_DT2);  // RX - RP0.
        	PPS_Mapping_NoLock(1, _OUTPUT, _TX2_CK2); // TX - RP1.
        	Lock_IOLOCK();
    }
    the problem is the same.

    someone can help me with this problem?
    thank
    Last edited by alexan_e; 28th October 2015 at 19:04. Reason: added code tags

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 4
    Points: 7,828, Level: 21

    Join Date
    Jan 2015
    Posts
    1,097
    Helped
    346 / 346
    Points
    7,828
    Level
    21

    Re: PIC18F46J50 Problem UART2

    I suggest that you do not try to unlock and lock the PPS registers until you have everything else working correctly.
    The unprogrammed default is to have the IOL1WAY bit set in the config registers which means that you can only unlock the registers once - once you lock them then you cannot unlock them again (until a power cycle) even if you do use the correct unlock sequence.
    However the power-on default for the IOLOCK bit is to have the PPS registers unlocked. Therefore you can set them however you need to without the need to do the unlock sequence - just DON'T lock them again afterwards.
    In your first code snippet, you are trying to use C to perform the unlock and lock sequences. This may or may not work depending on how the compiler generates the instructions. The unlock sequence must be performed as sequential instructions as given with no intervening code. This is why the macros (that you use in the 2nd snippet) are provided by the compiler.
    Susan



--[[ ]]--