首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 单片机 >

怎么使arm串口1接收数据

2012-05-16 
如何使arm串口1接收数据.问一个问题,我的试验板串口1用做命令通信口了,现在的话我用串口1做测试,用远程tel

如何使arm串口1接收数据.
问一个问题,我的试验板串口1用做命令通信口了,现在的话我用串口1做测试,用远程telnet登录进行调试,串口1数据发送正常,但我电脑对串口发送数据时我的测试程序却接收不到,好像开发板还是把数据当作命令来处理.

[解决办法]
华恒上有示例,

http://www.91linux.com/html/article/qianrushiyingyong/20070806/5074_4.html
问题39
39、关于关闭shell,使能串口通信
鉴于我们提供的版本不断的升级,所以针对不同版本的方法略有区别,下面一共提供两种方法:
方法一
1.修改uClinux/linux-2.4.x/init/main.c
- if (open("/dev/ttyS0", O_RDWR, 0) < 0)
+ if (open("/dev/null", O_RDWR, 0) < 0)
修改以后启动过程中printk内容仍会打印,printf内容如rc内步骤不会打印。
2.同时最好在user/init/simpleinit.c中不要启动/bin/sh,具体操作是:
/* Fake an inittab entry if boot console defined */
#ifdef CONFIG_USER_INIT_CONSOLE_SH
#if LINUX_VERSION_CODE < 0x020100
if (console_device && strcmp(console_device, "/dev/null"))
#else
if (have_console)
#endif
/*{ 【就是注释掉这一段代码!!!!】
struct initline *p;
p = inittab + numcmd++;
init_itab(p);
strcpy(p->fullline, "console");
strcpy(p->tty, "console");
strcpy(p->termcap, "linux");
p->toks[0] = "/bin/sh";
} */
#endif
**************************************************************************************
方法二
【这是最新的测试结果】
通常不能使用COM1进行串口通信的原因是它已被重定向为标准输入输出,系统的shell进程将对其监视并处理从此处发送进来的数据,而不能被用户程序所得到。
解决办法我认为有两种,一是不把Com1口重定向为标准输入输出,二是在标准输入输出上不启动shell。第一种没有试过,第二种可以按下面方法修改。
ü uC的版本很多,好像有一种是在uClinux/linux-2.4.x/init/main.c中启动shell,该代码在do_shell函数中,检查main.c文件,如果有该函数,把
if(open("/dev/ttyS0",O_RDWR,0)<0)
改为
if(open("/dev/null",O_RDWR,0)<0)
没有就算了。
在uClinux/user/init/simpleinit.c中注掉read_inittab函数中下面HHTECH部分的内容:
void read_inittab(void)
{
numcmd = 0;
/* Fake an inittab entry if boot console defined */
#ifdef CONFIG_USER_INIT_CONSOLE_SH
#if LINUX_VERSION_CODE < 0x020100
if (console_device && strcmp(console_device, "/dev/null"))
#else
if (have_console)
#endif
/*HHTECH
{
struct initline *p;
p = inittab + numcmd++;
init_itab(p);
strcpy(p->fullline, "console");
strcpy(p->tty, "console");
strcpy(p->termcap, "linux");
strcpy(p->termcap, "linux");
p->toks[0] = "/bin/sh";
}
*/
#endif
read_initfile(_PATH_INITTAB);
#ifdef CONFIG_USER_FLATFSD_FLATFSD
read_initfile(_PATH_CONFIGTAB);
#endif
if (numcmd == 0)
_exit(1);
}
注意:
这样并不是说就永远不会启动shell了,只是在标准输出上不启动shell,但若用户telnet板子还是仍然会在p0口上启动shell的,否则用户就永远无法向板子发布command命令了。
方法三
make menuconfig
Kernel hacking --->
[*] Compiled-in Kernel Boot Parameter
Kernel Boot Parameter: "CONSOLE=/dev/null" 
这样选择最彻底,minicom里面没有任何内核启动的信息,但可以telnet板子操作。

热点排行