Nucleo to nucleo serial Communication via TX and RX

fermedicius
Tue, 30 Jan 2024 10:39:26 +0000
Mbed OS

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,

7 posts - 2 participants