没有CTS RTS支持,半双工串行连接,“读入一些文本并将其写回终端”的代码。没有反应 [英] No CTS RTS support, half-duplex serial connection, a code which, "reads in some text and writes it back to the terminal" is unresponsive

查看:88
本文介绍了没有CTS RTS支持,半双工串行连接,“读入一些文本并将其写回终端”的代码。没有反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研发飞思卡尔的MKE02Z64VLD2微控制器。我正在使用Kinetis Design Studio IDE。我正在使用此终端应用程序。(sites.google.com/site/terminalbpp)



代码:



I am working on Freescale's MKE02Z64VLD2 microcontroller. I am using Kinetis Design Studio IDE. I am using this Terminal Application.(sites.google.com/site/terminalbpp)

Code:

static void ReadText(void) {
          uint8_t buffer[32], ch, i;

          for(;;) {
            GPIO_PDD_SetPortDataOutputMask(GPIOA_BASE_PTR, GPIO_PDD_PIN_21);
            CLS1_SendStr("Enter some text: ", CLS1_GetStdio()->stdOut);

            buffer[0] = '\0';
            i = 0;
            do {
              if (CLS1_KeyPressed()) {
              GPIO_PDD_ClearPortDataOutputMask(GPIOA_BASE_PTR, GPIO_PDD_PIN_21);
                CLS1_ReadChar(&ch); /* read the character */
                if (ch!='\0') { /* received a character */
                  buffer[i++] = ch; /* store in buffer */
                  if (i>=sizeof(buffer)) { /* reached end of buffer? */
                    buffer[i] = '\0'; /* terminate string */
                    break; /* leave loop */
                  }
                  if (ch=='\n') { /* line end? */
                    buffer[i] = '\0'; /* terminate string */
                    break; /* leave loop */
                  }
                }
              }
            } while(1);
            GPIO_PDD_SetPortDataOutputMask(GPIOA_BASE_PTR, GPIO_PDD_PIN_21);
            CLS1_SendStr("You entered: ", CLS1_GetStdio()->stdOut);
            CLS1_SendStr(buffer, CLS1_GetStdio()->stdOut);
            CLS1_SendStr("\r\n", CLS1_GetStdio()->stdOut);
          }
        }
int main(void)
{
PE_low_level_init();
ReadText();
}







这是我为我的问题陈述写的代码。由于它是半双工连接,并且控制器没有RTS CTS支持,我不知道应该对上面的代码进行哪些更改才能使其工作。



注意:

GPIO_PDD_TogglePortDataOutputMask(GPIOA_BASE_PTR,GPIO_PDD_PIN_21);

这件作品代码基本上启用/禁用发送器。

接收时,应清零此引脚并进行发送,应设置此引脚。我担心除了我在问题中发布的问题之外,我在设置/清除此PIN时可能会出错。

请有人帮我解决这个问题。



我的尝试:



我试图发送工作正常的字符串。这就是代码。

for(;;){

GPIO_PDD_TogglePortDataOutputMask(GPIOA_BASE_PTR,GPIO_PDD_PIN_21);

CLS1_SendStr(Hello World!\ r\\\
,CLS1_GetStdio() - > stdOut);

CLS1_SendStr(欢迎Ganesh!\\\\ n,CLS1_GetStdio() - > stdOut);

WAIT1_Waitms(1000);

}

我得到了所需的输出。




This is the code which I wrote for my problem statement. Since its a Half Duplex connection and there is no RTS CTS support from the controller, I don't know what changes should be made to the above code to make it work.

NOTE:
GPIO_PDD_TogglePortDataOutputMask(GPIOA_BASE_PTR, GPIO_PDD_PIN_21);
This piece of code basically enables/disables the Transmitter.
For receiving, this pin should be cleared and for transmitting, this pin should be set. I fear I may be doing mistake in setting / clearing this PIN apart from the issue I posted in the Question.
Please someone help me fix this.

What I have tried:

I tried to send strings which worked fine. This is that code.
for(;;) {
GPIO_PDD_TogglePortDataOutputMask(GPIOA_BASE_PTR, GPIO_PDD_PIN_21);
CLS1_SendStr("Hello World!\r\n", CLS1_GetStdio()->stdOut);
CLS1_SendStr("Welcome Ganesh!\r\n", CLS1_GetStdio()->stdOut);
WAIT1_Waitms(1000);
}
I got the desired output.

推荐答案

开始通过试图找出它停止的确切位置:

修改执行循环以读取并回显它收到的所有内容。即读一个字符,发送它。读另一个,发送它。继续。

那样 - 假设你已经可以看到你发送的字符串 - 你可以验证你希望接收的代码实际上是什么。

直到你已经建立了完整的双向通信,尝试查看实际数据或将其存储以供以后使用是毫无意义的:首先证明你可以先沟通。

当你可以沟通时,检查'\ n '通过确切地确认您收到的文本,在两个系统上的含义相同。如果另一端发送'\ r'作为行终止符,则不会看到现有代码的任何内容。
Start by trying to find out exactly where it's stopping:
Modify your do loop to read and echo back everything it receives. I.e. read a character, send it. Read another, send it. Keep going.
That way - assuming you can see the strings you send already - you can verify that what you expect that code to receive is actually what it gets.
Until you have established full two way comms, it's pointless trying to look at the actual data or store it for later: start by proving you can communicate first.
When you can communicate, check that '\n' means the same on both systems by confirming exactly what text you receive. If the other end sends '\r' for line terminator, you aren't going to see anything with your existing code.


这篇关于没有CTS RTS支持,半双工串行连接,“读入一些文本并将其写回终端”的代码。没有反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆