Hi,
I have some simple code to try and capture characters on the UART on the EZlite board with a BF609 processor but it is not working.
The function adi_uart_IsRxBufferAvailable() always returns success and that no data is available.
No errors are reported with the calls to setup the UART.
I have proven the connection and UART baud etc. settings by running an echo that uses blocking mode (adi_uart_Read()) to read the characters instead of dma mode.
Any idea what is stopping this simple code running?
#define BUFFER_SIZE 1
int buffer0[BUFFER_SIZE];
int buffer1[BUFFER_SIZE];
void processData(int *data){
/*process data from pointer here*/
adi_uart_Write(ghUART, data, 1);
}
void getData(void){
void* completedBuffer;
//get the completed buffer and store it in the pointer
adi_uart_GetRxBuffer(ghUART, &completedBuffer);
//pass the data to get processed
processData(completedBuffer);
//re-submit the buffer
adi_uart_SubmitRxBuffer(ghUART, completedBuffer, BUFFER_SIZE);
}
void uart_echo (void){
ADI_UART_RESULT eResult;
uint32_t nTxSize = 1;
//a _Bool bStopFlag = false;
adi_uart_Open(
UART_DEVICE_NUM,
ADI_UART_DIR_BIDIRECTION,
gUARTMemory,
ADI_UART_BIDIR_DMA_MEMORY_SIZE,
&ghUART
);
eResult = adi_uart_EnableDMAMode(ghUART, true);
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not enable dma Mode 0x%08X \n", eResult);
return FAILED;
}
/*configure UART*/
/* Set the UART Mode */
eResult = adi_uart_SetMode(ghUART, ADI_UART_MODE_UART );
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not set the Mode 0x%08X \n", eResult);
return FAILED;
}
/* Set UART Baud Rate */
eResult = adi_uart_SetBaudRate(ghUART, BAUD_RATE );
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not set the Baud Rate 0x%08X \n", eResult);
return FAILED;
}
/* Set number of stop bits */
eResult = adi_uart_SetNumStopBits(ghUART, ADI_UART_ONE_STOPBIT );
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not set the stop bits 0x%08X \n", eResult);
return FAILED;
}
/* Set number of stop bits */
eResult = adi_uart_SetWordLen(ghUART, ADI_UART_WORDLEN_8BITS );
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not set word length 0x%08X \n", eResult);
return FAILED;
}
printf("Setup Hyperterminal as described in Readme file. \n");
//submit buffers
eResult = adi_uart_SubmitRxBuffer(ghUART, buffer0, BUFFER_SIZE);
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not submit rx buff 0x%08X \n", eResult);
return FAILED;
}
eResult = adi_uart_SubmitRxBuffer(ghUART, buffer1, BUFFER_SIZE);
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not submit rx buff 0x%08X \n", eResult);
return FAILED;
}
eResult = adi_uart_EnableRx(ghUART, true);
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not enable rx 0x%08X \n", eResult);
return FAILED;
}
while (true){
bool dataReceived = false;
//Check if the buffer is completed
eResult = adi_uart_IsRxBufferAvailable(ghUART, dataReceived);
if(ADI_UART_SUCCESS != eResult)
{
REPORT_ERROR("Could not is rx avail 0x%08X \n", eResult);
return FAILED;
}
//if so, do something in getData()
if (dataReceived){
printf("gotit\n");
//getData();
}else{
uint32_t buf;
adi_uart_GetHWErrorStatus(ghUART, &buf);
if(buf)
REPORT_ERROR("hw error status 0x%08X \n", buf);
}
}
}