tms320c206 与 pc机串口通讯问题
一下是我用 C 写的 DSP 函数
//功能:DSP 从串口读数据
//参数:buff 为数据缓冲
// buff_len 为数据缓冲长度
// nMaxOutTime 为最大读取时间(单位毫秒)
//返回值: 已接受数据的长度
int read_comm( char *buff, unsigned buff_len, unsigned nMaxOutTime )
{
const unsigned nDR =0x0100 ;
unsigned cntBuff ;
float currPassTime ; //发送字符串已经过的总时间
currPassTime =0.0 ;
cntBuff =0;
while (currPassTime < nMaxOutTime)
{
if ( IOSR & nDR == nDR ) //有数据
{
buff[cntBuff++] = ADTR & 0xFF ;
if (cntBuff >= buff_len) break ;
}
delay(0.1 ms) ; //延时0.1 ms
currPassTime += 0.1 ;
}
return cntBuff ;
}
//功能:DSP 向串口写数据
//参数:buff 为数据缓冲
// buff_len 为数据缓冲长度
//返回值:发送是否成功 1- 成功 ;0- 失败
int write_comm(char *buff ,unsigned buff_len)
{
const unsigned nTHRE =0x0800 ;
const float nMaxCharTime =2.0 ; //发送两个字符间的最大间隔时间 ms
unsigned n ;
float curDelay ;
for(n=0; n< buff_len; n++)
{
ADTR = buff[n] & 0x00FF ;
curDelay =0.0 ;
while ( curDelay <= nMaxCharTime )
{
delay(0.1ms) ; //延时0.1ms
curDelay += 0.1 ;
if (IOSR & nTHRE == nTHRE) //已发送
break ;
}
if ( curDelay> nMaxCharTime ) return 0;
}
return 1;
}
-----------------------------------------------------------
我得问题是:
1. read_comm 函数读取字符时总是掉字符
2. write_comm 函数 必须去掉 if (IOSR & nTHRE == nTHRE) 才正常
我是初学DSP 编程, 以上我已调试了多天, 望各位大侠能出手相助
不胜感谢.
打赏帖 | |
---|---|
汽车电子中巡航控制系统的使用被打赏10分 | |
分享汽车电子中巡航控制系统知识被打赏10分 | |
分享安全气囊系统的检修注意事项被打赏10分 | |
分享电子控制安全气囊计算机知识点被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】【OZONE】使用方法总结被打赏20分 | |
【分享开发笔记,赚取电动螺丝刀】【S32K314】芯片启动流程分析被打赏40分 | |
【分享开发笔记,赚取电动螺丝刀】【S32K146】S32DS RTD 驱动环境搭建被打赏12分 | |
【分享开发笔记,赚取电动螺丝刀】【IAR】libc标注库time相关库函数使用被打赏23分 | |
LP‑MSPM0L1306开发版试用结果被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】【LP-MSPM0L1306】适配 RT-Thread Nano被打赏23分 |