How receive data over UART from callback on ADuCM4050?

Hello everebody!

I configured UART0 and want receive data byte per byte using callback function.

I constantly receiving data from UART on RX pin (checked it by scope) but get only ONE callback entrance to ADI_UART_EVENT_RX_BUFFER_PROCESSED case (checked by breakpoint.

So my questions are: 

1) Why there is only ONE entrance in UART callback function?

2) How can i get my received byte (or data) from this callback function?

Show me please an example.

Thank you!

void Uart::begin(int _uartId, int baud) {
    uartId = _uartId;
    /* Open the bidirectional UART device. */
    if(adi_uart_Open(uartId, ADI_UART_DIR_BIDIRECTION, UartDeviceMem[uartId], ADI_UART_MEMORY_SIZE, &uartHDevice) != ADI_UART_SUCCESS)
    {
        DEBUG_MESSAGE("Failed to open the UART device.");
        return;
    }

    if (adi_uart_ConfigBaudRate(uartHDevice, 0007, 0002, 0031, 0002) != ADI_UART_SUCCESS)
    {
        DEBUG_MESSAGE("Call back registration failed");
        return;
    }


    if(adi_uart_RegisterCallback(uartHDevice, DustyUart::DustyUARTCallback, NULL) != ADI_UART_SUCCESS)
    {
        DEBUG_MESSAGE("Call back registration failed");
        return;
    }

    /* Submit an empty buffer to the driver for receiving data using interrupt mode. */
    if(adi_uart_SubmitRxBuffer(uartHDevice, nBufferRx, SIZE_OF_BUFFER, INTERRUPT_MODE) != ADI_UART_SUCCESS)
    {
        DEBUG_MESSAGE("Failed to submit the Rx buffer 0 using DMA mode.");
        return;
    }

}



void UARTCallback(void* pAppHandle, uint32_t nEvent, void* pArg) {

    case ADI_UART_EVENT_RX_BUFFER_PROCESSED:
        nRxCallbackCounter++;

        break;

}

  • Hello mappy89,

    Why there is only ONE entrance in UART callback function?

    You only enter the UART callback function once because there is no buffer submitted. Every time the RX buffer gets processed, you need to use adi_uart_SubmitTxBuffer again to receive another byte. You can put it inside the callback function.

    How can i get my received byte (or data) from this callback function?

    When you submit your buffer, you need to include a pointer where the data received will be written to. You can get your data after it gets processed by using that pointer.

    Here's an example of what your UART callback function may look like:

    static void UARTCallback(
        void        *pAppHandle,
        uint32_t     nEvent,
        void        *pArg
    )
    {
        switch (nEvent)
        {
            case ADI_UART_EVENT_RX_BUFFER_PROCESSED:
                // After going inside this case, the submitted buffer now contains
                // the received data. In this case, it's byteBuffer
                
                // Resubmit buffer to receive more data
                // Note that the  submitted buffer pointer is &byteBuffer
                // and the size is 1 byte
                adi_uart_SubmitRxBuffer(hDevice, &byteBuffer, 1, 0);
                break;
        }
    }

    Regards,

    Jhake