• AVR Freaks

Hot!USART Dynamic Interrupt Receive

Author
Velam
Embedded Developer
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/09/23 11:56:48
  • Location: 0
  • Status: offline
2019/09/25 15:08:54 (permalink)
0

USART Dynamic Interrupt Receive

Hello everybody,
I learning about pic, currently I'm using a PIC32MX575F512H, mplab X IDE, Harmony V2.
I am trying read the USART data, with polled it's work fine, but when I try use interrupt my buffer only store the first byte of input string. 
This are the harmony configuration:
  • USART:
    • Dynamic
    • Interrupt enable
    • Byte Model enable
    • Wake on start enable
 
  • System Services
    • Interrupts enable
My buffer has a size of 60 characters and the  Receive event handle is show bellow:
void APP_USARTReceiveEventHandler(const SYS_MODULE_INDEX index)
{
    while(!DRV_USART_ReceiverBufferIsEmpty(serialHandle))
    {
        localBuffer[bufferIndex] = DRV_USART_ReadByte(serialHandle);
        ++bufferIndex;
    }
}

 
My APP_task just wait the occurrence of a new event as bellow:
void APP_Tasks ( void )
{

    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            bool appInitialized = true;
            bufferIndex = 0;
            DRV_USART_ByteReceiveCallbackSet(DRV_USART_INDEX_0, APP_USARTReceiveEventHandler);
            if (appInitialized)
            {
            
                appData.state = APP_STATE_SERVICE_TASKS;
            }
            break;
        }

        case APP_STATE_SERVICE_TASKS:
        {            
            appData.state = APP_STATE_SERVICE_TASKS;
            break;
        }

        /* TODO: implement your application state machine.*/
        

        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }

 
I spent hours in the forum looking for a solution, but no one solved my problem. If I sent from PC the String 12345, my buffer just store the 1 and ignore next characters. Some one can explain what I'm doing wrong? I need read the full string and store it using interrupt.
 
 
#1
BillP
Super Member
  • Total Posts : 334
  • Reward points : 0
  • Joined: 2014/09/28 07:53:35
  • Location: CA
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/09/26 10:34:57 (permalink)
#2
Velam
Embedded Developer
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/09/23 11:56:48
  • Location: 0
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/09/26 13:00:09 (permalink)
0
Yes, not solve my problem.
#3
Paul PortSol
Super Member
  • Total Posts : 493
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/09/27 05:30:25 (permalink)
0
a) Check the return code from library functions to ensure no errors
b) Check interrupt is correctly generated, mine looks like this for callbacks:
void __ISR(_UART_1_VECTOR, ipl1AUTO) _IntHandlerDrvUsartInstance0(void)
{
DRV_USART_TasksTransmit(sysObj.drvUsart0);
DRV_USART_TasksError(sysObj.drvUsart0);
DRV_USART_TasksReceive(sysObj.drvUsart0);
}
c) Turn off error interrupts in MHC (They caused issues in earlier Harmony so mine are still disabled)
d) Where is serialhandle initilized?
 
   D_PRINTF_InitUART("Uart Open:");
    for(eU=0; eU<EuListend; eU++)//Open UARTs
    {
        sUart.psUarts[eU].uIndex = puUartInitIndex[eU];
        D_PRINTF_InitUART(" %s", ppcUartNames[eU]);
        sUart.psUarts[eU].handle = DRV_USART_Open(sUart.psUarts[eU].uIndex, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_NONBLOCKING);//ToDo: Intents do nothing in HarmonyV202b
        if(DRV_HANDLE_INVALID == sUart.psUarts[eU].handle)/* Open Error? Check if the handle is valid */
        {
            D_PRINTF_ERROR_ID("UartInitFail(%s)", ppcUartNames[eU]);
        }
        DRV_USART_ByteReceiveCallbackSet(sUart.psUarts[eU].uIndex, vCallback_usart_rx);
        //unused(Causes Glitches in PIC32MZ HarmonyV202b): DRV_USART_ByteErrorCallbackSet(sUart.psUarts[eU].uIndex, vCallback_usart_err);
    }
    D_PRINTF_InitUART("\n");

e) Where is bufferindex overflow or rollover handled? (when longer than buffer)
f) Post screen capture of your MHC UART Settings
g) Try static mode (instead of dynamic)
 
 
#4
Paul PortSol
Super Member
  • Total Posts : 493
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/09/27 05:31:31 (permalink)
0
uint8_t puUartInitIndex[] = { DRV_USART_INDEX_0, DRV_USART_INDEX_1, DRV_USART_INDEX_2 }; //Allows re-Mapping EUARTs Instances during Init
#5
Velam
Embedded Developer
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/09/23 11:56:48
  • Location: 0
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/10/01 13:38:10 (permalink)
0
Paul PortSol
a) Check the return code from library functions to ensure no errors
b) Check interrupt is correctly generated, mine looks like this for callbacks:
void __ISR(_UART_1_VECTOR, ipl1AUTO) _IntHandlerDrvUsartInstance0(void)
{
DRV_USART_TasksTransmit(sysObj.drvUsart0);
DRV_USART_TasksError(sysObj.drvUsart0);
DRV_USART_TasksReceive(sysObj.drvUsart0);
}
c) Turn off error interrupts in MHC (They caused issues in earlier Harmony so mine are still disabled)
d) Where is serialhandle initilized?
 
   D_PRINTF_InitUART("Uart Open:");
    for(eU=0; eU<EuListend; eU++)//Open UARTs
    {
        sUart.psUarts[eU].uIndex = puUartInitIndex[eU];
        D_PRINTF_InitUART(" %s", ppcUartNames[eU]);
        sUart.psUarts[eU].handle = DRV_USART_Open(sUart.psUarts[eU].uIndex, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_NONBLOCKING);//ToDo: Intents do nothing in HarmonyV202b
        if(DRV_HANDLE_INVALID == sUart.psUarts[eU].handle)/* Open Error? Check if the handle is valid */
        {
            D_PRINTF_ERROR_ID("UartInitFail(%s)", ppcUartNames[eU]);
        }
        DRV_USART_ByteReceiveCallbackSet(sUart.psUarts[eU].uIndex, vCallback_usart_rx);
        //unused(Causes Glitches in PIC32MZ HarmonyV202b): DRV_USART_ByteErrorCallbackSet(sUart.psUarts[eU].uIndex, vCallback_usart_err);
    }
    D_PRINTF_InitUART("\n");

e) Where is bufferindex overflow or rollover handled? (when longer than buffer)
f) Post screen capture of your MHC UART Settings
g) Try static mode (instead of dynamic)
 
 




Apologize me for delay to response.
 
a) Did, it's fine.
b) My generated code is the same generated to you.
c) I learned it, did.
d) I initilize the serialHand in APP_Initialize. 
e) I have a flag to control the buffer index. If my input has some end frame, the index return to zero.
f) Attached.
g) I'ill. Back with the feedback.
#6
Paul PortSol
Super Member
  • Total Posts : 493
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/10/02 04:13:39 (permalink)
0
1. Hope Static fixes it.
2. Where is localbuffer defined and initialized? Maybe its getting overwritten elsewhere? 
Use debugger to put breakpoints on localbuffer and on any code that changes localbuffer, then run and see where it stops. Send only a byte at a time to follow what happens for each byte.
3. Protection: No guarantee that frame end with be received correctly, so use:
if(bufferindex < (sizeof(localbuffer)-1)){localBuffer[bufferIndex++];}else {bRxOverflowFlag=true;}//Flag Error if overflow occurs


 
Paul
 
 
 
#7
Velam
Embedded Developer
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/09/23 11:56:48
  • Location: 0
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/10/11 05:59:42 (permalink)
0
Ok, will check it.
post edited by Velam - 2019/10/11 06:01:23
#8
NorthGuy
Super Member
  • Total Posts : 5685
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: USART Dynamic Interrupt Receive 2019/10/11 08:37:15 (permalink)
0
It's been 3 weeks.
 
In all honesty, if you just read the value from the register and organize a circular buffer by yourself (without relaying on libraries), I cannot see how can it possibly take more than 2 hours of programming.
#9
Velam
Embedded Developer
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/09/23 11:56:48
  • Location: 0
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/10/14 06:19:08 (permalink)
0
Hello guys, I'm sorry.
I had some personal problems and stayed off for 2 weeks.Today I back to my problem. Paul PortSol suggested try with static usart, I'm doing now.
NorthGuy, I believe that problem is not the buffer, but something with PIC model and usart interrupt. 
Thank you for all time spent in my problem.
#10
Velam
Embedded Developer
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/09/23 11:56:48
  • Location: 0
  • Status: offline
Re: USART Dynamic Interrupt Receive 2019/10/16 11:57:36 (permalink)
0
Hello guys, 
As I was suspecting, to PIC32mx575, he is blocked in the first uart interrupt character, so was necessary restart the usart to get all data. This bug happen only in the first time.
 
Thank for your help. 
#11
Jump to:
© 2019 APG vNext Commercial Version 4.5