AnsweredAssumed Answered

How to use two UARTs in paralell using K60

Question asked by dkarthik on Jul 1, 2014
Latest reply on Jul 8, 2014 by Carlos_Musich

I would like to make the K60 MCU

-> Receive from a UART5(connected to PC) and send it to another UART3(connected to a device)

-> Receive from UART3(connected to device) and send it to UART5(connected to PC)

I set the AS1:serial_LDD to UART5 and AS2:serial_LDD to UART_3.

I referred typical usage of Serial_LDD component in processor expert at polling mode and wrote the following code. The AS1_serial component works. It receives the characters from PC and echoes back but I think AS2_component gets struck in receiving characters.  Please review and the code and help me debug. I would like to know If there is any problem with the code. Thank you.

 

MySerialPtr1 = AS1_Init(NULL); /* Initialization of AS1 component *

MySerialPtr2 = AS2_Init(NULL); /* Initialization of AS2 component */

 

for(;;) {

 

while(1) {

Error1 = AS1_ReceiveBlock(MySerialPtr1, InpData1, 1U); // Start reception of one character

 

while (!DataReceivedFlg1) { // Wait until a character is received

AS1_Main(MySerialPtr1);

}

Error1 = AS1_SendBlock(MySerialPtr1, InpData1, sizeof(InpData1)); // Echo to terminal in PC

Error2 = AS2_SendBlock(MySerialPtr2, InpData1, sizeof(InpData1)); // Send to device

 

if (InpData1[0] == '\r') { // If enter key is received break from the while loop

 

break; }

DataReceivedFlg1 = FALSE;

}

 

while(1) {

Error2 = AS2_ReceiveBlock(MySerialPtr2, InpData2, 1U); // Start reception of one character from the device

 

while (!DataReceivedFlg2) { // Wait until a character is received

AS1_Main(MySerialPtr2);

}

Error1 = AS1_SendBlock(MySerialPtr1, InpData2, sizeof(InpData2)); // Send it to PC

 

if(InpData2[0] == '>') { //If '>' is received break from the while loop

 

break; }

DataReceivedFlg2 = FALSE;

}

DataReceivedFlg1 = FALSE;

DataReceivedFlg2 = FALSE;

}

Outcomes