Jump to content
  • 0

arty z7-7020:Overlapped output at putty while calling a function is written using xuartps.h to send data to uart in normal mode in arty z7-7020?


Rai Taimoor Ali

Question

I am trying to send data from arty z7-7020 board to PC using uart through a function (driver xuartps.h). within the main program, the code works but calling it from function, output at putty gets overlapped. i tried to debug the code but it looks fine and get output as expected. Need help. thanks

code:

 

 

#include "platform.h"
#include "xil_printf.h"
#include<stdlib.h>
#include "xuartps.h"


void uart_output(){


        char *p;
	        char  tip[100]=" hi : uart_text_multiple time \n\r\0";

	        u32 transmittedBytes;
	        u32  totalTransmittedBytes;
	        u32 status;
	        u16 byteCnt;


	        XUartPs_Config *PiUartConfig;
	        XUartPs PiUart;
	        byteCnt=0;


	        PiUartConfig=XUartPs_LookupConfig(XPAR_PS7_UART_0_DEVICE_ID);

	        status = XUartPs_CfgInitialize(&PiUart,PiUartConfig, PiUartConfig->BaseAddress);

	        if(status!=XST_SUCCESS)
	            print("Uart initialization failed...\n\r");
	        status = XUartPs_SetBaudRate(&PiUart, 115200);

	        if(status!=XST_SUCCESS)
	                print("BaudRATE init failed....\n\r");
	        int o;
	        o=0;

	        p =tip;



	        while(*p != '\0'){

	            byteCnt+=1;
	            p++;

	            }



	        do{
	            totalTransmittedBytes=0;
	            p =tip;


	                 while( totalTransmittedBytes<byteCnt+2){
	                     transmittedBytes = XUartPs_Send(&PiUart, (u8*)&p[totalTransmittedBytes],byteCnt);
	                     totalTransmittedBytes += transmittedBytes;
	                 }
	                 p++;
	                 o++;

	        }while(o<10);

}

int main()
{


        init_platform();

        uart_output();
        uart_output();

        cleanup_platform();
    return 0;
}

image.png.05b3022dc6ee44f460c737ace33b4c20.png

Edited by Rai Taimoor Ali
not full information
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi @Rai Taimoor Ali,

I'm not certain what all you are attempting to do, but if you just wanted to loop some known text, why not just do something like this?

#include "xparameters.h"
#include "xstatus.h"
#include "xil_types.h"
#include "xil_assert.h"
#include "xuartps_hw.h"
#include "xil_printf.h"

#define UART_BASEADDR		XPAR_XUARTPS_0_BASEADDR

#define CHAR_ESC		0x1b	/* 'ESC' character is used as terminator */

int main(void)
{
	u8 RecvChar = 0;

	xil_printf("type in a number between 1 and 9: ");

	u8 Running = TRUE;
	while(Running) {
		while (!XUartPs_IsReceiveData(UART_BASEADDR)); //wait for data to come in
		RecvChar = XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET);

		 if (('1' <= RecvChar) && ('9' >= RecvChar)) {
			 xil_printf("\n\r");
			 for(int i = 0; i < (RecvChar - 48); i++){
				 xil_printf("Hi : uart_text_mulitple times \n\r");
				}
		 }
		 else if (CHAR_ESC == RecvChar) {
						Running = FALSE; //stop running the example if the ESC key is pressed
					}
			else if (('9' < RecvChar) || ('1' > RecvChar)) {
				xil_printf("\r\nYou did not choose a number between 1 and 9. Try again.\r\n");
				}
	}

	return XST_SUCCESS;

}

Thanks,
JColvin

Link to comment
Share on other sites

  • 0
Quote

basically the idea is to send 5 int and 5 short int values as a single string to PC. And because the reading of these 10 variables will change as per the system response so string values and length always change. 

You can use, for example, xil_printf("%04x", my_short_int); to pad the values sent to four characters with leading zeroes (in this case formatted in hex), to keep the length of the printed string consistent.

usleep(microseconds); can also be used if you need a shorter sleep function.

Thanks,

Arthur

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...