cmelnu
cmelnu

Reputation: 11

Xilinx: send data via UART to a ZedBoard

I am using a ZedBoard, which has a Zynq-7000 all programmable SoC. I am trying one of the examples provided (can be imported from Xilinx SDK), it's called xuartps_intr_example.c

This file contains an UART driver, which is used in interrupt mode. The application sends data and expects to receive the same data through the device using the local loopback mode

I would like to adapt that code in such a way that I can send data to my ZedBoard from a terminal or some kind of program that implements serial communication. I have tried using XUartPs_Recv function to receive data from outside, and sending data from different terminals in my PC (by disabling console in Xilinx SDK, otherwise the serial port is not accessible), but the board is not receiving anything. On the other hand, sending data from the ZedBoard to my PC works properly, and I can see the messages coming from the board in different terminals.

I have attached the source code that I can't get to understand and I think is giving me problems. My questions are preceded by a hash sign:

    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??

Also, I would like to know if sending data via SDK Terminal (Xilinx SDK) to the ZedBoard would be possible. At the moment, every attempt has been unsuccessful.

Thank you in advance

Christian

Upvotes: 0

Views: 5358

Answers (2)

Zain
Zain

Reputation: 436

  1. LOCAL LOOPBACK MODE does not send anything to the outside application and just loops back its sent stream to itself.

  2. We actually do not start receiving data. We start waiting to receive data.

  3. As @Cesar has mentioned correctly, just change XUARTPS_OPER_MODE_LOCAL_LOOP to XUARTPS_OPER_MODE_NORMAL at the beginning of the code, and you are good to go. NORMAL LOOPBACK MODE sends data to the outside application.

Upvotes: 2

Cesar Raitz Jr
Cesar Raitz Jr

Reputation: 11

To receive data on the ZedBoard from a PC terminal, you have to be in normal operation mode, which is the default mode when the PS starts up. Have a look at the Zynq-7000 Technical Reference Manual, page 598, Figure 19-7, to understand the UART operation modes.

Upvotes: 1

Related Questions