Hot!PIC32MK UART pin settings problem

Author
p_stoyanoff
Senior Member
  • Total Posts : 140
  • Reward points : 0
  • Joined: 2011/06/30 00:23:55
  • Location: 0
  • Status: offline
2018/07/12 03:57:16 (permalink)
0

PIC32MK UART pin settings problem

Greetings! I`m using multiple UARTs on PIC32MK1024GPD064. The problem is income data on 1 RX pin cause the data to be accepted from multiple pins - it triggers multiple interrupts and many UARTs receive the same data. Here is my code:

#pragma config DEBUG = OFF
#pragma config JTAGEN = OFF
#pragma config ICESEL = ICS_PGx1
#pragma config TRCEN = OFF
#pragma config BOOTISA = MIPS32
#pragma config FSLEEP = OFF
#pragma config DBGPER = PG_ALL
#pragma config SMCLR = MCLR_NORM
#pragma config SOSCGAIN = GAIN_2X
#pragma config SOSCBOOST = ON
#pragma config POSCGAIN = GAIN_LEVEL_3
#pragma config POSCBOOST = ON
#pragma config EJTAGBEN = NORMAL
#pragma config CP = OFF
/*** DEVCFG1 ***/
#pragma config FNOSC = SPLL
#pragma config DMTINTV = WIN_127_128
#pragma config FSOSCEN = OFF
#pragma config IESO = ON
#pragma config POSCMOD = HS
#pragma config OSCIOFNC = OFF
#pragma config FCKSM = CSECME
#pragma config WDTPS = PS1048576
#pragma config WDTSPGM = STOP
#pragma config FWDTEN = OFF
#pragma config WINDIS = NORMAL
#pragma config FWDTWINSZ = WINSZ_25
#pragma config DMTCNT = DMT31
#pragma config FDMTEN = OFF
/*** DEVCFG2 ***/
#pragma config FPLLIDIV = DIV_1
#pragma config FPLLRNG = RANGE_5_10_MHZ
#pragma config FPLLICLK = PLL_POSC
#pragma config FPLLMULT = MUL_48
#pragma config FPLLODIV = DIV_4
#pragma config VBATBOREN = ON
#pragma config DSBOREN = ON
#pragma config DSWDTPS = DSPS32
#pragma config DSWDTOSC = LPRC
#pragma config DSWDTEN = OFF
#pragma config FDSEN = ON
#pragma config BORSEL = HIGH
#pragma config UPLLEN = OFF
/*** DEVCFG3 ***/
#pragma config USERID = 0xffff
#pragma config FUSBIDIO2 = ON
#pragma config FVBUSIO2 = ON
#pragma config PGL1WAY = ON
#pragma config PMDL1WAY = ON
#pragma config IOL1WAY = ON
#pragma config FUSBIDIO1 = ON
#pragma config FVBUSIO1 = ON
/*** BF1SEQ0 ***/
#pragma config TSEQ = 0x0000
#pragma config CSEQ = 0xffff

static inline __attribute__((always_inline)) void HardwareUseMultiVectoredInterrupts( void )
{
__builtin_disable_interrupts();
/* Enable multi-vector interrupts. */
_CP0_BIS_CAUSE( 0x00800000U );
INTCONSET = _INTCON_MVEC_MASK;
__builtin_enable_interrupts();
}
#define PPSUnLock() {SYSKEY=0x0;SYSKEY=0xAA996655;SYSKEY=0x556699AA;CFGCONbits.IOLOCK=0;}
#define PPSLock() {CFGCONbits.IOLOCK=1;SYSKEY=0x0;}
#define RX5_TRIS TRISAbits.TRISA7
#define TX5_TRIS TRISBbits.TRISB14
#define RX5_PINREG U5RXR
#define TX5_PINREG RPB14R
#define RX5_Init() {RX5_TRIS=1;}
#define TX5_Init() {TX5_TRIS=0;}
#define RX4_TRIS TRISDbits.TRISD5
#define RX4_ANSEL ANSELDbits.ANSD5
#define TX4_TRIS TRISCbits.TRISC6
#define RX4_PINREG U6RXR
#define TX4_PINREG RPC6R
#define RX4_Init() {RX4_TRIS=1;RX4_ANSEL=0;}
#define TX4_Init() {TX4_TRIS=0;}
void __ISR(_UART6_RX_VECTOR, IPL3AUTO) UART6Interrupt(void)
{
static unsigned char value;
while(U6STA & _U6STA_URXDA_MASK)
{
value=U6RXREG;
buffer[pointer++]=value;
}
IFS5CLR = _IFS5_U6RXIF_MASK;
}
void __ISR(_UART5_RX_VECTOR, IPL3AUTO) UART5Interrupt(void)
{
static unsigned char value;
while(U5STA & _U5STA_URXDA_MASK)
{
value=U5RXREG;
buffer5[pointer5++]=value;
}
IFS2CLR = _IFS2_U5RXIF_MASK;
}
 
int main ( void )
{
/* Initialize all MPLAB Harmony modules, including application(s). */
SYS_Initialize ( NULL ); //Harmony generated
WDTCONSET=_WDTCON_ON_MASK;
WDTCONbits.WDTCLRKEY=0x5743;

RX6_Init();
TX6_Init();

RX5_Init();
TX5_Init();
PPSUnLock();

RX6_PINREG=9;
TX6_PINREG=11;

RX5_PINREG=7;
TX5_PINREG=11;
PPSLock();

while(1)
{
//main
}
}

Any idea what I`m doing wrong?!
Thanks!
#1

13 Replies Related Threads

    cvm
    Super Member
    • Total Posts : 141
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/12 09:24:54 (permalink)
    0
    Here is my code
    but not all.
     
    buffer[pointer++]=value;
    buffer5[pointer5++]=value;
     
    so what keeps you inside each buffer?
    #2
    p_stoyanoff
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2011/06/30 00:23:55
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/12 10:20:48 (permalink)
    0
    Nothing keeps me inside! This is the original code:

    void __ISR(_UART5_RX_VECTOR, IPL3AUTO) UART5Interrupt(void)
    {
    static unsigned char value;
    while(U5STA & _U5STA_URXDA_MASK)
    {
    value=U5RXREG;
    RS485_Port5_IncomeBuffer[RS485_Port5_IncomeBuffer_Pointer]=value;
    RS485_Port5_IncomeBuffer_Pointer++;
    RS485Port5_Properties.UpdateTicks=0;
    if(RS485_Port5_IncomeBuffer_Pointer>=RS485_PORT5_INCOMEBUFFER_SIZE)
    {
    RS485_Port5_IncomeBuffer_Pointer=0;
    RS485_Port5_Reloaded=1;
    }
    }
    IFS2CLR = _IFS2_U5RXIF_MASK;
    }
     

    I`ve used this with other PIC32 without any problems. And the problem is not I`m staying inside, but triggering multiple interrupts on different UxRX. I suppose the problem is in the initialization. I`ll try to repeat this using Harmony pin setup...
    #3
    cvm
    Super Member
    • Total Posts : 141
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/12 11:00:09 (permalink)
    0
    Its difficult to help when the code is incomplete and mixed up- you use RX6, but the defines you have never refer to RX6, etc.
     
    You certainly need to stay inside those buffers, and it is a problem no matter what else you have going on. Depending on how you are diagnosing your problem, you may see rx buffer data from one pin go into rx buffer data of another due to the pointer incrementing into the other- and that's the harmless version of the buffer overrun.
    #4
    p_stoyanoff
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2011/06/30 00:23:55
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/14 11:33:38 (permalink)
    0
    Hi, again! Everything is just fine now. Only my error handle function is not OK. Here is my code:

    calculatedValue=(_XTAL_FREQ/(4*baudrate))-1;
    U2BRG=calculatedValue;
    U2MODEbits.CLKSEL=1;
    U2MODECLR=_U2MODE_RTSMD_MASK;

    U2MODECLR=_U2MODE_UEN0_MASK;
    U2MODESET=_U2MODE_BRGH_MASK;
    U2MODECLR=_U2MODE_LPBACK_MASK;
    U2MODECLR=_U2MODE_PDSEL0_MASK;
    U2MODECLR=_U2MODE_STSEL_MASK;
    U2MODECLR=_U2MODE_ABAUD_MASK;


    U2STASET=_U2STA_URXEN_MASK;
    U2STASET=_U2STA_UTXEN_MASK;
    U2STACLR=_U2STA_URXISEL0_MASK;
    U2STACLR=_U2STA_ADDEN_MASK;
    IEC1SET=_IEC1_U2EIE_MASK;//error int enable
    IPC14bits.U2EIP=7; //error priority
    IPC14bits.U2EIS=7;
    IEC1bits.U2EIE=1;
    IEC1SET=_IEC1_U2RXIE_MASK;
    IPC14bits.U2RXIP=6;
    IPC14bits.U2RXIS=6;
    U2MODESET=_U2MODE_ON_MASK;
    //Error int
    void __ISR(_UART2_FAULT_VECTOR, IPL7AUTO) UART2Error()
    {
    static int c;
    while (U2STA & _U2STA_URXDA_MASK) c = U2RXREG;
    U2STACLR = _U2STA_OERR_MASK; 
    }

    The problem is when I activate this interrupt(IEC1SET=_IEC1_U2EIE_MASK) it triggers constantly by FERR error. Without it everything is working, but when I turn it on I never get out of that interrupt. It happens soon after I initialize the UART. There is no transmition on the line - no in or out data...
    What am I doing wrong?! 
    #5
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/14 11:46:48 (permalink)
    0
    Is baud rate correct? Is pin idle-high?

    GENOVA :D :D ! GODO
    #6
    p_stoyanoff
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2011/06/30 00:23:55
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/14 12:24:48 (permalink)
    0
    Here are my pin init functions:

     
    #define GSM_RX_TRIS TRISBbits.TRISB1
    #define GSM_RX_ANSEL ANSELBbits.ANSB1
    #define GSM_TX_TRIS TRISBbits.TRISB0
    #define GSM_TX_ANSEL ANSELBbits.ANSB0
    #define GSM_RX_PINREG U2RXR
    #define GSM_TX_PINREG RPB0R
     
    #define GSM_RX_Init() {GSM_RX_TRIS=1;GSM_RX_ANSEL=0;}
    #define GSM_TX_Init() {GSM_TX_TRIS=0;GSM_TX_ANSEL=0;}
     
     
     
     
     
    GSM_RX_Init();
    GSM_TX_Init();
     
    PPSUnLock();
    GSM_RX_PINREG=2;
    GSM_TX_PINREG=2;
     
    PPSLock();
     

    I have a bidirectional level shifter connected to the pins - TXS0108EPWR. This time I don`t have any pull up or down resistors on the lines. Do I have to add if you think this is the problem?! 
     
    post edited by p_stoyanoff - 2018/07/14 12:27:18
    #7
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/14 12:50:05 (permalink)
    0
    No pullups are usually needed on a UART, since pins are always driven. But how about a possiblt invert-setting on the USART? (check registers)

    GENOVA :D :D ! GODO
    #8
    p_stoyanoff
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2011/06/30 00:23:55
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/14 22:44:24 (permalink)
    3 (1)
    I`ve tried - no luck...
    #9
    marcov
    Super Member
    • Total Posts : 216
    • Reward points : 0
    • Joined: 2006/10/08 01:59:40
    • Location: Eindhoven, NL.
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/15 03:35:06 (permalink)
    4 (1)
    Personally I thought that setting both TX5_PINREG and TX6_PINREG to 11 a bit dodgy?

    Trying to tie two uarts' TX on one output pin?
    #10
    p_stoyanoff
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2011/06/30 00:23:55
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/15 04:54:25 (permalink)
    3 (1)
    I do not tie 2 UARTs on one output! Where did you see that?!
    Any ideas about the error handling?! Can you give me an example how do you do it?!
    Thanks!
    #11
    marcov
    Super Member
    • Total Posts : 216
    • Reward points : 0
    • Joined: 2006/10/08 01:59:40
    • Location: Eindhoven, NL.
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/15 06:19:00 (permalink)
    0
    Sorry. It is indeed the other way around you tie two pins to the same uart:


    PPSUnLock();
     
     RX6_PINREG=9;
     TX6_PINREG=11; // <- THIS
     
     RX5_PINREG=7;
     TX5_PINREG=11; // <- AND THIS
     PPSLock();



    #12
    p_stoyanoff
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2011/06/30 00:23:55
    • Location: 0
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/15 11:25:24 (permalink)
    0
    No!  This is incorrect! TX6_PINREG and TX5_PINREG point to different registers! And every register 11 points to different pin!
    OK! I`ve done it! I just added a time called function which checks OERR and cleans it. No interrupt! And it works fine.

     
    if(timeout>TIMEOUT_VALUE)
    {
    if(U2STAbits.OERR==1)
    {
    U2STACLR = _U2STA_OERR_MASK;
    }
    timeout=0;
    }
     

    Thanks to everyone!
    #13
    marcov
    Super Member
    • Total Posts : 216
    • Reward points : 0
    • Joined: 2006/10/08 01:59:40
    • Location: Eindhoven, NL.
    • Status: offline
    Re: PIC32MK UART pin settings problem 2018/07/15 12:23:11 (permalink)
    0
    (ah wait yes, mk had something strange like every side of chip was its own peripheral pin realm. Oops, sorry, too much dspic lately)
    #14
    Jump to:
    © 2018 APG vNext Commercial Version 4.5