FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

UART Communication problem

Altera_Forum
Honored Contributor II
860 Views

Hi All, 

 

I am using DE1 kit and connect UART to COM1 port of pc.I write a code in Nios to transfer a single character to hyperterminal. Also set all the settings like baudrate,flow control,parity etc..in appropriate manner.At the run time I can see the TXD LED blinking on the kit But I can't receive any character on hyperterminal. 

 

Any suggestions ???
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
124 Views

试用一下下面的代码。 

祝你好运! 

 

Try to use the code as bellow. 

Best regards! 

#include "unistd.h" // UNIX API # include <fcntl.h> // UNIX API # include <stdio.h> // printf() # include <string.h> // strlen() # include "alt_types.h" //++++++++++++++++++++++++++++++++++++++ // &#20462;&#25913;UART&#21517;&#31216; &#24320;&#22987; // &#26681;&#25454;SOPC Builder&#35774;&#32622;&#20462;&#25913; //++++++++++++++++++++++++++++++++++++++ # include "system.h" # define my_uart_name UART_NAME //-------------------------------------- // &#20462;&#25913;UART&#21517;&#31216; &#24320;&#22987; //-------------------------------------- # define CHAR_NUM 8 int main() { int fd; alt_u8 *ptr; alt_u8 charBuf; // 100&#23383;&#33410;&#30340;&#23383;&#31526;&#32531;&#23384; alt_u8 num_temp1, num_temp2; // &#20020;&#26102;&#21464;&#37327; alt_u8 *msg1 = "Please Enter 8 charaters : "; alt_u8 *msg2 = " has been Rcved\n"; //++++++++++++++++++++++++++++++++++++ // &#21021;&#22987;&#21270; &#24320;&#22987; //++++++++++++++++++++++++++++++++++++ ptr = charBuf; // &#25351;&#21521;&#23383;&#31526;&#32531;&#20914;&#21306; num_temp2 = CHAR_NUM; // &#27442;&#35835;&#20837;CHAR_NUM&#20010;&#23383;&#31526; num_temp1 = num_temp2; //----------------------------------- // &#21021;&#22987;&#21270; &#32467;&#26463; //----------------------------------- //++++++++++++++++++++++++++++++++++++ // &#25171;&#24320;UART &#24320;&#22987; //++++++++++++++++++++++++++++++++++++ fd = open(my_uart_name, O_RDWR, 0666); // &#20197;&#21487;&#35835;&#20889;&#26041;&#24335;&#25171;&#24320;&#35774;&#22791;&#25991;&#20214; if (fd < 0) // &#22914;&#26524;&#25171;&#24320;&#22833;&#36133; { printf("error\n "); return 1; } //------------------------------------ // &#25171;&#24320;UART &#32467;&#26463; //------------------------------------ //++++++++++++++++++++++++++++++++++++ // &#36755;&#20986;msg1 &#24320;&#22987; //++++++++++++++++++++++++++++++++++++ write(fd, msg1, strlen(msg1)); //------------------------------------ // &#36755;&#20986;msg1 &#32467;&#26463; //------------------------------------ //++++++++++++++++++++++++++++++++++++ // &#35835;&#21462;CHAR_NUM&#20010;ASCII&#30721;&#23383;&#31526; &#24320;&#22987; //++++++++++++++++++++++++++++++++++++ while(num_temp1) // &#35835;&#21462;CHAR_NUM&#20010;ASCII&#30721;&#23383;&#31526; { num_temp2 = read(fd, ptr, num_temp2); ptr += num_temp2; num_temp1 -= num_temp2; num_temp2 = num_temp1; } //------------------------------------ // &#35835;&#21462;CHAR_NUM&#20010;ASCII&#30721;&#23383;&#31526; &#32467;&#26463; //------------------------------------ //++++++++++++++++++++++++++++++++++++ // &#36755;&#20986;&#35835;&#20837;&#23383;&#31526;&#21644;msg2 &#24320;&#22987; //++++++++++++++++++++++++++++++++++++ write(fd, charBuf, 8); // &#36755;&#20986;&#35835;&#20837;&#23383;&#31526; write(fd, msg2, strlen(msg2)); // &#36755;&#20986;msg2 //------------------------------------ // &#36755;&#20986;&#35835;&#20837;&#23383;&#31526;&#21644;msg2 &#32467;&#26463; //------------------------------------ //++++++++++++++++++++++++++++++++++++ // &#20851;&#38381;UART &#24320;&#22987; //++++++++++++++++++++++++++++++++++++ close(fd); // &#20851;&#38381;&#35774;&#22791; //------------------------------------ // &#20851;&#38381;UART &#32467;&#26463; //------------------------------------ return 0; }
Reply