Xilinx:通过UART将数据发送到ZedBoard

时间:2018-01-03 19:29:36

标签: terminal xilinx uart zynq

我使用的是ZedBoard,它有一个Zynq-7000全可编程SoC。我正在尝试提供的一个示例(可以从Xilinx SDK导入),它被称为 xuartps_intr_example.c

该文件包含一个UART驱动程序,用于中断模式。应用程序发送数据并希望使用本地环回模式

通过设备接收相同的数据

我想以这样的方式调整该代码,即我可以从终端或某种实现串行通信的程序向ZedBoard发送数据。我尝试使用 XUartPs_Recv 功能从外部接收数据,并从我的PC中的不同终端发送数据(通过在Xilinx SDK中禁用控制台,否则串口无法访问),但是主板不是收到任何东西另一方面,从ZedBoard向我的电脑发送数据工作正常,我可以在不同的终端看到来自电路板的消息。

我附上了我无法理解的源代码,我认为这给了我一些问题。我的问题前面有一个哈希符号:

    XUartPs_SetInterruptMask(UartInstPtr, IntrMask);

XUartPs_SetOperMode(UartInstPtr, XUARTPS_OPER_MODE_LOCAL_LOOP);

#WHAT IS LOCAL LOOPBACK MODE?? DOES THIS PREVENT THE BOARD FROM RECEIVING 
DATA COMING FROM MY PC?

/*
 * Set the receiver timeout. If it is not set, and the last few bytes
 * of data do not trigger the over-water or full interrupt, the bytes
 * will not be received. By default it is disabled.
 *
 * The setting of 8 will timeout after 8 x 4 = 32 character times.
 * Increase the time out value if baud rate is high, decrease it if
 * baud rate is low.
 */
XUartPs_SetRecvTimeout(UartInstPtr, 8);


/*
 * Initialize the send buffer bytes with a pattern and the
 * the receive buffer bytes to zero to allow the receive data to be
 * verified
 */
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {

    SendBuffer[Index] = (Index % 26) + 'A';

    RecvBuffer[Index] = 0;
}

/*
 * Start receiving data before sending it since there is a loopback,
 * ignoring the number of bytes received as the return value since we
 * know it will be zero
 */
XUartPs_Recv(UartInstPtr, RecvBuffer, TEST_BUFFER_SIZE);

/*
 * Send the buffer using the UART and ignore the number of bytes sent
 * as the return value since we are using it in interrupt mode.
 */
XUartPs_Send(UartInstPtr, SendBuffer, TEST_BUFFER_SIZE);

#HOW DOES THIS ACTUALLY WORK? WHY DO WE START RECEIVING BEFORE WE SEND ANY 
BYTES?

/*
 * Wait for the entire buffer to be received, letting the interrupt
 * processing work in the background, this function may get locked
 * up in this loop if the interrupts are not working correctly.
 */
while (1) {
    if ((TotalSentCount == TEST_BUFFER_SIZE) &&
        (TotalReceivedCount == TEST_BUFFER_SIZE)) {
        break;
    }
}

/* Verify the entire receive buffer was successfully received */
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
    if (RecvBuffer[Index] != SendBuffer[Index]) {
        BadByteCount++;
    }
}

/* Set the UART in Normal Mode */
XUartPs_SetOperMode(UartInstPtr, XUARTPS_OPER_MODE_NORMAL);

#WHAT DOES SETTING THE UART IN NORMAL MODE MEAN??

另外,我想知道是否可以通过SDK终端(Xilinx SDK)向ZedBoard发送数据。目前,每次尝试都没有成功。

提前谢谢

基督教

2 个答案:

答案 0 :(得分:0)

要从PC终端在ZedBoard上接收数据,您必须处于正常操作模式,这是PS启动时的默认模式。看看Zynq-7000 Technical Reference Manual,第598页,图19-7,以了解UART操作模式。

答案 1 :(得分:0)

  1. LOCAL LOOPBACK MODE不会向外部应用程序发送任何内容,而只是将其发送的流循环回自身。

  2. 我们实际上并未开始接收数据。我们开始等待接收数据。

  3. 正如@Cesar正确提到的那样,只需在代码开头将XUARTPS_OPER_MODE_LOCAL_LOOP更改为XUARTPS_OPER_MODE_NORMAL,就可以了。 NORMAL LOOPBACK MODE将数据发送到外部应用程序。