Hot!PIC32MX : Unable to Receive . What I Transmit

Page: 12 > Showing page 1 of 2
Author
karan123
Super Member
  • Total Posts : 616
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
2017/11/13 10:24:51 (permalink)
0

PIC32MX : Unable to Receive . What I Transmit

Hello,
 
I am working on UART of  PIC32MX795F512L.
From below code I am unable to Receive . What I Transmit with Interrupt .
I am testing with PC. Every Eighth (may be more or less) time I have exact character which I have typed from
PC.

 
 
 
void UART2Init()
{
U2BRG = BAUDRATEREG;
U2MODE = 0;
U2MODEbits.BRGH = BRGH;
U2STA = 0;
U2MODEbits.UARTEN = 1;
U2STAbits.UTXEN = 1;
IFS1bits.U2RXIF = 0;
 
 
 
// This is UART Interrupt Code [Added from]
UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
 
 
 
// Configure UART2 RX Interrupt
INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);
 
 
 
// configure for multi-vectored mode
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
 
 
 
// enable interrupts
INTEnableInterrupts();
#if defined (__PIC32MX__)
U2STAbits.URXEN = 1;
#endif
}

 
Unable to attached Code of ISR .. Please See attachment.
 
I think I need to disable 8-level-deep FIFO. Is it   ? From URXISEL = 0b00 Register ?
What is the solution of this problem. ? or any other issue ?
 
--
karan
post edited by karan123 - 2017/11/13 10:30:27
#1

31 Replies Related Threads

    DarioG
    farewell.
    • Total Posts : 53177
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 10:27:49 (permalink)
    0
    If the FIFO is the issue, then this means that you're not reading all the available chars when you receive an interrupt;
    or, anyway, that you're too slow at handling the IRQs

    forget about me, subhumans. adieu

    #2
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 10:31:37 (permalink)
    0
    UART Baudrate is 9600 bps.
    Please Check attachment  in Msg #1..
    Whether ISR is correct or not ?
     
    post edited by karan123 - 2017/11/13 10:38:39
    #3
    DarioG
    farewell.
    • Total Posts : 53177
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 10:41:41 (permalink)
    0
    Ah, that's a mistake: never perform a SEND inside a RECEIVE IRQ - you will spend time in there and lose chars.
     
    Also, you may need to perform this
    RetrievePacketGroupFArray[UARTInterruptCounter]= UARTGetDataByte(UART2) ;
    many times till the FIFO is empty.

    forget about me, subhumans. adieu

    #4
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 10:50:27 (permalink)
    0
    Thanks DarioG..

    First Never Send character in RecvIRQ... Correct.. I forgot

    Second.. I don't want to use FIFO.
    By Default.. FIFO is enabled..?

    Thanks again for Correcting me
    __Karan
    #5
    DarioG
    farewell.
    • Total Posts : 53177
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 10:58:19 (permalink)
    0
    ok!
    I don't know... usually, yes, it is enabled...

    forget about me, subhumans. adieu

    #6
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 11:02:11 (permalink)
    4 (1)
    Ok.. I WILL DISABLE IT (FIFO).
    Send the recevied bytes outside from. ReceiveIRQ.
    Then let you know.. Thanks.
    #7
    qhb
    Superb Member
    • Total Posts : 6257
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 12:30:04 (permalink)
    4 (1)
    There are very few situations where it is useful to disable the FIFO.
    It it there to help you avoid missing received characters.
    Just make sure you read each character until it is empty.
     
     
    #8
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/13 23:35:56 (permalink)
    0
    Hi qhb .. Thanks for update..

    There are very few situations where it is useful to disable the FIFO.
    It it there to help you avoid missing received characters.
    Just make sure you read each character until it is empty.

    But How to disable it...? I am trying as below: 
    // Disable FIFO  from PIC32MX UART FRM  - Page 8 (Register 21-2)
    U2STAbits.URXISEL = 0b00 ;
    but still getting Every Eighth  time I have exact character which I have typed from PC
     

     
    void UART2Init()
    {
    // Baudrate 9600
    U2BRG = BAUDRATEREG_2;
    U2MODE = 0;
    U2MODEbits.BRGH = BRGH_2;
    U2STA = 0;
    // UART TX Enable
    U2STAbits.UTXEN = 1;
    // UART RX Enable
    U2STAbits.URXEN = 1;
    // UART FIFO = Interrupt is generated and asserted
    // while the transmit buffer contains at least one empty space
    U2STAbits.UTXISEL = 0b00 ;
    // UART FIFO = Interrupt flag bit is asserted while receive buffer is not empty
    U2STAbits.URXISEL = 0b00 ;
    // UART Enable
    U2MODEbits.UARTEN = 1;
    IFS1bits.U2RXIF = 0;
     
    // This is UART Interrupt Code [Added from]
    // C:\Program Files (x86)\Microchip\mplabc32\v1.12\
    // examples\plib_examples\uart\uart_interrupt\source
    UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
     
    UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
     
    // Configure UART2 RX Interrupt
    INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);
     
    // configure for multi-vectored mode
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    // enable interrupts
    INTEnableInterrupts();
    #if defined (__PIC32MX__)
    U2STAbits.URXEN = 1;
    #endif
    }
     

     
    Please update..
     
    --
    Thanks
    KR
    post edited by karan123 - 2017/11/14 00:54:21
    #9
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 00:07:03 (permalink)
    3 (1)
    Please See Attachment...
    Now Transmitting is taken out from receive interrupt ..
    #10
    ROSS
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2014/04/08 07:14:15
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 01:12:25 (permalink)
    3 (1)
    hi
    I am using the pic32mx795 with uarts, what I found is that if you didn't configure your pins before initialising your uarts and use pull up external resistor then when you configure you uarts the pc comms see a character.  
    regards
    Ross
    #11
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 01:27:55 (permalink)
    0
    Hi ROSS,
     
    I have added below in Uart Init Code still same results..

    // UART TX as Output
    TRISFbits.TRISF5 = 0 ;
    // UART RX as Input
    TRISFbits.TRISF4 = 1 ;

    #12
    ROSS
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2014/04/08 07:14:15
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 03:55:57 (permalink)
    0
    hi I don't use harmony or plibs, I just use xc32 for coding
    so I don't know how much you can follow this
     
     first configure part and baud rate
    //////////////////////////////////////////////////////////////////////////////
    //
    //      CONFIG   A S S I G N M E N T  FOR PIC32MX795F512L
    //
    ///////////////////////////////////////////////////////////////////////////////
    // DEVCFG3
    #pragma config USERID = 0xffff
    #pragma config FSRSSEL = PRIORITY_7     // SRS Select (SRS Priority 7)
    #pragma config FMIIEN = OFF             // Ethernet RMII/MII Enable (RMII Enabled)
    #pragma config FETHIO = OFF             // Ethernet I/O Pin Select (Alternate Ethernet I/O)
    #pragma config FCANIO = OFF             // CAN I/O Pin Select (Alternate CAN I/O)
    #pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by Port Function)
    #pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)
    // DEVCFG2
    #pragma config FPLLIDIV = DIV_2         // PLL Input Divider (2x Divider) :8MHZ/2 = 4
    #pragma config FPLLMUL = MUL_20         // PLL Multiplier (20x Multiplier) :4MHZx20 = 80MHZ
    #pragma config UPLLIDIV = DIV_2        // USB PLL Input Divider (2x Divider) : 4MHZ/2 = 4 (USB)
    #pragma config UPLLEN = OFF             // USB PLL Enable (Disabled and Bypassed)
    #pragma config FPLLODIV = DIV_1         // System PLL Output Clock Divider (PLL Divide by 1) :80MHZ/1 = 80MHZ
    // DEVCFG1
    //#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
    //#pragma config FNOSC = FRCPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL)): INTERNAL 8mHZ
    #pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL)): INTERNAL 8mHZ
    #pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
    //#pragma config IESO = OFF               // Internal/External Switch Over (Disabled)
    #pragma config IESO = ON               // Internal/External Switch Over (Disabled)
    #pragma config POSCMOD = EC             // Primary Oscillator Configuration (EC osc mode)
    #pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
    #pragma config FPBDIV = DIV_2           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) : 80MHZ
    //#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
    #pragma config FCKSM = CSECMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
    #pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
    #pragma config FWDTEN = OFF              // Watchdog Timer Enable (WDT Enabled)
    // DEVCFG0
    #pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
    #pragma config ICESEL = ICS_PGx2        // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2)
    #pragma config PWP = OFF                // Program Flash Write Protect (Disable)
    #pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
    #pragma config CP = OFF                 // Code Protect (Protection Disabled)

    ///////////////////////////////////////////////////////////////////////////////
    //
    //      BAUDRATE  A S S I G N M E N TS
    //
    ///////////////////////////////////////////////////////////////////////////////
    //#define FPB 40000000.0
    #define FPB 36864000.0
    #define BAUDRATE 115200.0
    #define BAUDRATE9600 9600.0
    #define BAUDRATE_1MBIT 921600.0 //460800
    #define BRGVAL ((FPB/BAUDRATE)/16)-1 //11520
    #define BRGVAL9600 ((FPB/BAUDRATE9600)/16)-1 // 9600
    #define BRGVAL_1MBIT ((FPB/BAUDRATE_1MBIT)/4.0)-1.0 // 921600 NEED TO SET BAUD TO 1
     
    ****************************************
    next uart
    void InitUART2() //  HAS CTS RTS BUT NOT USED
    {
       // Configure U3MODE Register
        U2MODEbits.ON = 0;   // Bit15 TX, RX DISABLED, ENABLE at end of func  
        U2MODEbits.USIDL = 0; // Bit13 Continue in Idle
        U2MODEbits.IREN = 0; // Bit12 No IR translation
        U2MODEbits.RTSMD = 0; // Bit11 Simplex Mode
        U2MODEbits.UEN = 00; // Bits8,9 TX,RX enabled, *CTS,RTS not
        U2MODEbits.WAKE = 0; // Bit7 No Wake up (since we don't sleep here)
        U2MODEbits.LPBACK = 0; // Bit6 No Loop Back
        U2MODEbits.ABAUD = 0; // Bit5 No Autobaud (would require sending '55')
        U2MODEbits.RXINV = 0; // Bit4 IdleState = 1  (for dsPIC)
        U2MODEbits.BRGH = 0; // Bit3 16 clocks per bit period*
        U2MODEbits.PDSEL = 0; // Bits1,2 8bit, No Parity
        U2MODEbits.STSEL = 0; // Bit0 One Stop Bit
        // Load a value into Baud Rate Generator.  Target is 115200.
     //  U1BRG = (Fcy/(16*BaudRate))-1
     //  U1BRG = (80.000M/(16*115200))-1
     //  U1BRG = 3
     U2BRG = BRGVAL9600;         // Set the baud rate
        // Configure U2STA register
     U2STAbits.UTXISEL1 = 1; //Bit15 Int when Char is transferred
     U2STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
        U2STAbits.UTXINV = 0; //Bit14 N/A, IRDA config
     U2STAbits.UTXBRK = 0; //Bit11 Sync break trans is disabled
     U2STAbits.UTXEN = 0; //Bit10 TX pins controlled by periph
     U2STAbits.URXISEL = 0; //Bits6,7 Int. on character received
        U2STAbits.ADDEN = 0; //Bit5 Address Detect Disabled
        U2STAbits.URXISEL0 = 0;
        U2STAbits.URXISEL1 = 0;
       
    // Mid Range Interrupt Priority level, no urgent reason
        //IPC8 = 0x0000000C;      // set UART priority = 3, IPC8<4:2> SEC priority = 0, IPC8<1:0>
        //IPC8 = 0x0000000D;      // set UART priority = 3, IPC8<4:2> SEC priority = 1, IPC8<1:0>
        IPC8bits.U2IP = 5;
        IPC8bits.U2IS = 2;
        U2MODEbits.UARTEN = 1; // Enable UART
     U2STAbits.UTXEN = 1;    // Enable UART TX (dont turn on as TXIE will be on)
        if (IFS1bits.U2TXIF == 1)
        {
            IFS1bits.U2TXIF = 0;
            //IFS1CLR = 0x00000400;          // clear FLAG IFS1(7) TX
        }
        U2STAbits.URXEN = 1;    // Enable UART RX ?
        //clear receive buffer by reading all data out to nowhere
        while (U2STAbits.URXDA == 1)
        {
            tempbyte = U2RXREG;
            IFS1bits.U2RXIF = 0; // Clear the Receive Interrupt Flag
            //IFS1CLR = 0x00000200;          // clear FLAG IFS1(6) RX
            if (tempbyte == 0)
            {
                debugpic();
            }
            else
            {
                debugpic();
                debugpic();
            }
        }
        IFS1bits.U2TXIF = 0; // Clear the Transmit Interrupt Flag
        //IFS1CLR = 0x00000400;          // clear FLAG IFS1(7) TX
     IEC1bits.U2TXIE = 0; // disable Transmit Interrupts
     IFS1bits.U2RXIF = 0; // Clear the Receive Interrupt Flag
        //IFS1CLR = 0x00000200;          // clear FLAG IFS1(6) RX
     IEC1bits.U2RXIE = 1; // Enable Receive Interrupts
    }
     
    next******************
    isr
    void __ISR(_UART_2_VECTOR, IPL5SOFT) Uart2HostInterrupt(void) //
    //void __ISR(_UART_2_VECTOR, IPL3AUTO) Uart2HostInterrupt(void) //
    {
        asm ("ei");
        if  (IFS1bits.U2RXIF == 1) // interrupt u2   
    check receive flag(as above or transmit) and store date clear flag
     
    in your main remember to enable interrupts and multivector ints
     
    I hope this helps
    Ross
     
    #13
    DarioG
    farewell.
    • Total Posts : 53177
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 04:03:08 (permalink)
    4 (1)
    don't do "ei" inside an ISR...

    forget about me, subhumans. adieu

    #14
    ROSS
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2014/04/08 07:14:15
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 04:08:46 (permalink)
    0
    hi
    I found that it don't mater about "ei", I just read it was good practice?
    regards
    Ross
    #15
    DarioG
    farewell.
    • Total Posts : 53177
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 04:13:10 (permalink)
    0
    Well, yes:
    I mean, it's unlikely that, since you're already inside an interrupt handler, you want to change the global interrupt enable flags. Hardware manages that state for you.
     
    This is basically *very* true Smile on baseline PICs, but also stands for more complex MCUs. Only in some special situations you may want to deal with IPL or alike, when interrupts are expected to get "nested" and alike.

    forget about me, subhumans. adieu

    #16
    qhb
    Superb Member
    • Total Posts : 6257
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 04:17:08 (permalink)
    4 (1)
    ROSS
    I found that it don't mater about "ei",

    Yes it does.
     
    I just read it was good practice?

    Where?
    It is incredibly BAD practice.
     
    #17
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 06:10:15 (permalink)
    0
    Hello,
     
    Can Anybody look my code as in Msg #10.. ?
     
    --
    Karan123
    post edited by karan123 - 2017/11/14 06:15:59
    #18
    karan123
    Super Member
    • Total Posts : 616
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 09:44:25 (permalink)
    0
    I don't want use FIFO or generate interrupt every receive (Not Filled FIFO)
    #19
    qhb
    Superb Member
    • Total Posts : 6257
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MX : Unable to Receive . What I Transmit 2017/11/14 12:07:10 (permalink)
    3 (1)
    karan123
    I don't want use FIFO

    Why not?
     
    or generate interrupt every receive (Not Filled FIFO)

    When do you want to generate interrupts then?
     
    Your whole approach seems self defeating.
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2017 APG vNext Commercial Version 4.5