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);
if (ch!='\0') {
buffer[i++] = ch;
if (i>=sizeof(buffer)) {
buffer[i] = '\0';
break;
}
if (ch=='\n') {
buffer[i] = '\0';
break;
}
}
}
} 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.