Nucleo to nucleo serial Communication via TX and RX

Hi All,
I am using two Nucleo board (F746ZG and F746ZG) both are same to simulate a Serial communication. The HW Connection is as follows
MAIN-NUCLEO SUB-NUCLEO
F746ZG (TX) —>F746ZG (RX)
F746ZG (RX) —>F746ZG (TX)

I want to send a character from main nucleo to sub nucleo and After send some done from sub nucleo to main nucleo. but i cann’t do this automatically , could you have some ideas? pls see my Code snip below .

// main Nucleo
#include “mbed.h”
#include"string.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PG_14,PG_9); // NUCLEO-F746zg
char resStr = “#ABCDEFGH$”;
char received=“”;

int main()
{
pc.baud(115200);
receiver.baud(9600);
pc.printf(“Starting…\r\n”); // Send to PC’s serial terminal
int ch;

while (1) {
     pc.printf("\n Select The case :"); 
    scanf("%d",&ch);
     switch(ch)
    {
        case 1:
        {
            printf("nucleo to nucleo Communication");
            for (int i = 0; resStr[i] != '$'; i++)
            { //sending to Sub Nucleo F746ZG
            receiver.putc(resStr[i]);
            printf("\n send=%c",resStr[i]);
            wait_ms(10);
            } 
            printf("sending done");
            
           while (receiver.readable() !='#') //receive from Sub Nucleo F746zg
           {
            printf("inside while loop ready for reading");
            int j=0;
            char c = receiver.getc();   // Receive from main NUCLEO-F746zg
            printf("\n received=%c",c);
            received[j]=c;
            j++;
            wait_ms(10);
           }
       }
       break;
   }

}
}

// Sub Nucleo
#include “mbed.h”
#include"string.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PG_14,PG_9); // NUCLEO-F746ZG

char resStr = “done#”;
char received=“”;

int main()
{
pc.baud(115200);
receiver.baud(9600);
pc.printf(“Starting…\n\r”);
int k=0;
while (1)
{
while(receiver.readable() !=‘$’)
{
int i=0;
char c = receiver.getc(); // Receive from main NUCLEO-F746zg
received[i]=c;
printf(“\n received=%c”,received[i]);
i++;
k++;
wait_ms(10);

    }

        while(k==7)
        {
        for (int j = 0; resStr[j] != '#'; j++)
            { //sending to main Nucleo F746ZG
            printf("ready to sending");
            receiver.putc(resStr[j]);
            printf("\n send= %c",resStr[j]);
            wait_ms(10);
            }  
        }       // Send back to main NUCLEO(done message);
    }
}

these are my code,

Hello,

be so kind use these symbols ``` before and after your code for corect formating

```

//my code
int main(){
   // do something
}

```

First this line is wrong

while(receiver.readable() !=‘$’)

The readable methond return just bool so you cano not ask for a char.

//the i variable need to be somewhere else
int i=0;

// insde the loop
if(receiver.readable())
{
   char c = receiver.getc(); // Receive from main NUCLEO-F746zg
   if (c  !=‘$’) {
      // do something
   }else{
      // do something else
   }
// rest...

BR, Jan

hi
i will send 0and1 combination for one string ,that String Length are around 200 ,
// Sub Nucleo
#include “mbed.h”
#include"string.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PG_14,PG_9); // NUCLEO-F746ZG

char resStr = “done#”;
char received=“”;

int main()
{
pc.baud(115200);
receiver.baud(9600);
pc.printf(“Starting…\n\r”);
int k=0;
while (1)
{
if(receiver.readable())
{
int i=0;
char c = receiver.getc(); // Receive from main NUCLEO-F746zg
received[i]=c;
printf(“\n received=%c”,received[i]);
i++;
k++;
wait_ms(10);
if(c==‘$’)
break;

    }

        if(k==7)
        {
        for (int j = 0; resStr[j] != '#'; j++)
            { //sending to main Nucleo F746ZG
            printf("ready to sending");
            receiver.putc(resStr[j]);
            printf("\n send= %c",resStr[j]);
            wait_ms(10);
            }  
        }       // Send back to main NUCLEO(done message);
    }
}

i changed the code now also its not working,

You did only half. The i variable have to be outside of loop and set to zero inside whne the msg is complete.

BR, Jan

hi i changed i variable also ,now also not working ,can you my code
// Sub Nucleo code

#include “mbed.h”
#include"string.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PG_14,PG_9); // NUCLEO-F746ZG

char received= “”;
int main()
{
pc.baud(115200);
receiver.baud(9600);
pc.printf(“Starting…\n\r”);
int i=0;
while (1)
{
if(receiver.readable())
{
char c = receiver.getc(); // Receive from main NUCLEO-F746zg
received[i]=c;
printf(“\n received=%c”,received[i]);
i++;
wait_ms(10);
if(c==‘$’)
{
i=0;
break;
}

}
}
}

Please I do not want to struggling with your code in this state, use code formatting (how i wrote above) for looks like below.

Try this.

#include "mbed.h"
#include"string.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PG_14,PG_9); // NUCLEO-F746ZG

char received[50]; // buffer with a size
int main()
{
    pc.baud(115200);
    receiver.baud(9600);
    pc.printf("Starting…\n\r");
    int i=0;
    while (1)
    {
        if(receiver.readable())
        {
            char c = receiver.getc(); // Receive from main NUCLEO-F746zg
            //if(c != '$' && c != '#') //posible ignoring flags
            received[i++]=c;
            if(c == '$') //end of string detection
            {
                received[i]= '\0';
                printf("received=%s\n",received);
                i=0;
            }
        }
        else wait_ms(10);
    }
}

BR, Jan

hi JohnnyK i tried this one also not Working my Nucleo F746ZG$AU1.