Post Go back to editing

HW error in callback function when trying to read data from UART0

In the call back function, I am getting event as 4 which as I understand is ADI_UART_EVENT_HW_ERROR_DETECTED, even though I can see that the data in the Receive buffer is as expected.

Why am I receiving a ADI_UART_EVENT_HW_ERROR_DETECTED instead of an ADI_UART_EVENT_RX_BUFFER_PROCESSED event?  

Find the code below:

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

switch (nEvent)
{
case ADI_UART_EVENT_TX_BUFFER_PROCESSED:
nTxCallbackCounter++;
break;
case ADI_UART_EVENT_RX_BUFFER_PROCESSED:
nRxCallbackCounter++;
break;
default:
break;


}
}

int main(void)
{

/* Variable that keeps track of any errors found. */
bool bResult = true;

/* Variable to confirm the transmit shift register is empty before closing the device. */
bool bTxComplete = false;

/* Variable to get the buffer size to compare the buffer contents at the end of this test. */
uint32_t nCounter = 0u;

/* Pinmux initialization. */
adi_initpinmux();

do{
/* Power initialization. */
if(adi_pwr_Init() != ADI_PWR_SUCCESS)
{
DEBUG_MESSAGE("Failed to intialize the power service.");
bResult = false;
break;
}

/* System clock initialization. */
if(adi_pwr_SetClockDivider(ADI_CLOCK_HCLK, 1u) != ADI_PWR_SUCCESS)
{
DEBUG_MESSAGE("Failed to intialize the system clock.");
bResult = false;
break;
}

/* Peripheral clock initialization. */
if(adi_pwr_SetClockDivider(ADI_CLOCK_PCLK, 1u) != ADI_PWR_SUCCESS)
{
DEBUG_MESSAGE("Failed to intialize the peripheral clock.");
bResult = false;
break;
}

/* Open the bidirectional UART device. */
if(adi_uart_Open(UART_DEVICE_NUM, ADI_UART_DIR_BIDIRECTION, UartDeviceMem, ADI_UART_MEMORY_SIZE, &hDevice) != ADI_UART_SUCCESS)
{
DEBUG_MESSAGE("Failed to open the UART device.");
bResult = false;
break;
}

/* Register a callback. */
if(adi_uart_RegisterCallback(hDevice, UARTCallback, NULL) != ADI_UART_SUCCESS)
{
DEBUG_MESSAGE("Call back registration failed");
bResult = false;
break;
}

/* Submit an empty buffer to the driver for receiving data using interrupt mode.*/
if(adi_uart_SubmitRxBuffer(hDevice, nBufferRx1, SIZE_OF_BUFFER, 0u) != ADI_UART_SUCCESS)
{
DEBUG_MESSAGE("Failed to submit the Rx buffer 1 using interrupt mode.");
bResult = false;
break;
}

return(0);
}

  • I have an updated code, where I have setup bidirectional UART 0 and 1. Both UART channels upon receiving data in the buffer transmit that data immediately to the other UART. 

    Here are the updated Callback functions: 

    static void UARTCallback0(
    void *pAppHandle,
    uint32_t nEvent,
    void *pArg
    )
    {

    switch (nEvent)
    {
    case ADI_UART_EVENT_TX_BUFFER_PROCESSED:
    nTx0CallbackCounter++;
    break;
    case ADI_UART_EVENT_RX_BUFFER_PROCESSED:
    nRx0CallbackCounter++;
    memcpy(nBufferTx1,pArg,SIZE_OF_BUFFER);
    adi_uart_SubmitTxBuffer(hDevice1, nBufferTx1, SIZE_OF_BUFFER, 0u);
    adi_uart_SubmitRxBuffer(hDevice0, nBufferRx0, SIZE_OF_BUFFER, 0u);
    break;
    default:
    break;


    }
    }

    static void UARTCallback1(
    void *pAppHandle,
    uint32_t nEvent,
    void *pArg
    )
    {

    switch (nEvent)
    {
    case ADI_UART_EVENT_TX_BUFFER_PROCESSED:
    nTx1CallbackCounter++;
    break;
    case ADI_UART_EVENT_RX_BUFFER_PROCESSED:
    nRx1CallbackCounter++;
    memcpy(nBufferTx0,pArg,SIZE_OF_BUFFER);
    adi_uart_SubmitTxBuffer(hDevice0, nBufferTx0, SIZE_OF_BUFFER, 0u);
    adi_uart_SubmitRxBuffer(hDevice1, nBufferRx1, SIZE_OF_BUFFER, 0u);
    break;
    default:
    break;


    }
    }

    My question is, how do I set priority for the interrupts? I want UART 1 RX to have the highest priority. Is there way to override the default priority settings while using the API functions? 

  • Hi,

    We don't have device specific API to change the priority level of the interrupt. We also don't recommend to change anything on the interrupt assignments. 

    With your own risk you can play with the interrupt  number assignments located on adi_ADuCM4050_device.h file.

    Regards,

    Jeric