- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ???Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
试用一下下面的代码。
祝你好运! 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"
//++++++++++++++++++++++++++++++++++++++
// 修改UART名称 开始
// 根据SOPC Builder设置修改
//++++++++++++++++++++++++++++++++++++++
# include "system.h"
# define my_uart_name UART_NAME
//--------------------------------------
// 修改UART名称 开始
//--------------------------------------
# define CHAR_NUM 8
int main()
{
int fd;
alt_u8 *ptr;
alt_u8 charBuf; // 100字节的字符缓存
alt_u8 num_temp1, num_temp2; // 临时变量
alt_u8 *msg1 = "Please Enter 8 charaters : ";
alt_u8 *msg2 = " has been Rcved\n";
//++++++++++++++++++++++++++++++++++++
// 初始化 开始
//++++++++++++++++++++++++++++++++++++
ptr = charBuf; // 指向字符缓冲区
num_temp2 = CHAR_NUM; // 欲读入CHAR_NUM个字符
num_temp1 = num_temp2;
//-----------------------------------
// 初始化 结束
//-----------------------------------
//++++++++++++++++++++++++++++++++++++
// 打开UART 开始
//++++++++++++++++++++++++++++++++++++
fd = open(my_uart_name, O_RDWR, 0666); // 以可读写方式打开设备文件
if (fd < 0) // 如果打开失败
{
printf("error\n ");
return 1;
}
//------------------------------------
// 打开UART 结束
//------------------------------------
//++++++++++++++++++++++++++++++++++++
// 输出msg1 开始
//++++++++++++++++++++++++++++++++++++
write(fd, msg1, strlen(msg1));
//------------------------------------
// 输出msg1 结束
//------------------------------------
//++++++++++++++++++++++++++++++++++++
// 读取CHAR_NUM个ASCII码字符 开始
//++++++++++++++++++++++++++++++++++++
while(num_temp1) // 读取CHAR_NUM个ASCII码字符
{
num_temp2 = read(fd, ptr, num_temp2);
ptr += num_temp2;
num_temp1 -= num_temp2;
num_temp2 = num_temp1;
}
//------------------------------------
// 读取CHAR_NUM个ASCII码字符 结束
//------------------------------------
//++++++++++++++++++++++++++++++++++++
// 输出读入字符和msg2 开始
//++++++++++++++++++++++++++++++++++++
write(fd, charBuf, 8); // 输出读入字符
write(fd, msg2, strlen(msg2)); // 输出msg2
//------------------------------------
// 输出读入字符和msg2 结束
//------------------------------------
//++++++++++++++++++++++++++++++++++++
// 关闭UART 开始
//++++++++++++++++++++++++++++++++++++
close(fd); // 关闭设备
//------------------------------------
// 关闭UART 结束
//------------------------------------
return 0;
}

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page