Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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();
}



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.
Posted
Updated 11-May-16 23:57pm

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900