cancel
Showing results for 
Search instead for 
Did you mean: 

Products: Two PCBs Steval-FKI433V2 and S2-LP DK_1.2.1 project example "SDK_Chat.c". How correctly organize echo of Rx data in one of the Steval without connecting it to terminal?

bvn123
Associate II

Hello.

I use the S2-LP DK_1.2.1 project example "SDK_Chat.c" as the base for two Steval-FKI433V2 PCBs.

The 1st Steval with unchanged SDK_Chat.c program is used as a base device, connected to COM-port,

the 2nd Steval without connection to COM-port should send the data on request of the 1st Steval.

Question: how to switch S2LP-Rx/S2LP-Tx modes correctly without the cycle of waiting the COM-port's chars sequence?

May be there is Echo example for two Steval PCBs?

A target part of the program SDK_Chat.c is placed in infinite loop of main().

The start line 347 (line count for original SDK_Chat.c): tx_data_size=0;

the end line 378: tx_data[tx_data_size] = '\0';

(All this part of original SDK_Chat.c is placed in the end of this question.

The file SDK_Chat.c with my changes is attached, the added lines are signed with '//my' comment).

I try to replace the target part with the next one:

 /* infinite loop */ //- line345

isRxCmd=0; //this is added

 while (1){ 

  while(!isRxCmd) {

//isRxCmd=1 is added to void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) after printf(),line 176 to signal Rx

for(uint32_t i=0;i<0x10000;i++); //it doesn't work without this delay (about 0.01s)

//when it was i<0x1000, there were more malfunctions

S2LPCmdStrobeRx();}; //it doesn't work without this in while{}

};

isRxCmd=0;

//then fill the tx_data[] and tx_data_size and use existing part of program to transmit tx_data

Even if the device would work properly with cyclic call of the delay and S2LPCmdStrobeRx(), it seems strange.

Best regards,

bvn123

the part, which should be replaced (bold text):

 /* infinite loop */ //- line 345 SDK_Chat.c (original)

 while (1){ 

   tx_data_size=0; //line 347

   while(__io_getcharNonBlocking(&tx_data[tx_data_size]));

   /* reset the data to be sent */

   tx_data_size=0;

   printf("tx>");

   /* RX command */

   S2LPCmdStrobeRx();

   do

   {

     while(!__io_getcharNonBlocking(&tx_data[tx_data_size]));

     if((char)tx_data[tx_data_size] != '\r' && (char)tx_data[tx_data_size] != '\n')

     {

       putchar(tx_data[tx_data_size]);

     }

     else

     {

       putchar('\n');

       putchar('\r');

       break;

     }

     tx_data_size++;

     /* if '\r' has been received */

   }while(tx_data_size != MAX_PAYLOAD_LENGTH);

   /* add the string termination chars */

   /*tx_data[tx_data_size] = '\n';

   putchar(tx_data[tx_data_size]);*/

   tx_data[tx_data_size] = '\0';

1 ACCEPTED SOLUTION

Accepted Solutions
Winfred LU
ST Employee

Hi Bvn123,

I have come out a "Chat Echo" example for your reference.

Please use it for the 2nd set of boards.

It continuously receives from S2LP, copies rx_data to tx_data, and sends out (echos) tx_data.

Connecting to the COM port is not required.

Note.

In this scenario, copying is not needed actually. It will be more efficient to just send out the rx_data. But i keep the copying parts in case you'd like to modify the data. Please modify according to your needs.

Modifications descriptions:

  • line 366, set S2-LP to RX mode
  • line 368, empty main loop, because the packets handling is inside the GPIO callback
  • line 182-200, fill tx_data with rx_data, and send the rx_data out
  • line 161, when TX is done, set S2-LP back to RX mode

Thank you.

Best Regards,

Winfred

View solution in original post

2 REPLIES 2
Winfred LU
ST Employee

Hi Bvn123,

I have come out a "Chat Echo" example for your reference.

Please use it for the 2nd set of boards.

It continuously receives from S2LP, copies rx_data to tx_data, and sends out (echos) tx_data.

Connecting to the COM port is not required.

Note.

In this scenario, copying is not needed actually. It will be more efficient to just send out the rx_data. But i keep the copying parts in case you'd like to modify the data. Please modify according to your needs.

Modifications descriptions:

  • line 366, set S2-LP to RX mode
  • line 368, empty main loop, because the packets handling is inside the GPIO callback
  • line 182-200, fill tx_data with rx_data, and send the rx_data out
  • line 161, when TX is done, set S2-LP back to RX mode

Thank you.

Best Regards,

Winfred

bvn123
Associate II

Hi Winfred LU,

thank You very much for Your answer.