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 (STM32-F746ZG) and SUB-NUCLEO(STM32-F746ZG)
F746ZG pin-PC_12(TX) —>F746ZG pin-PG_9 (RX)
F746ZG pin-PD_2(RX) —>F746ZG pin-PG_14(TX)
I want to send a set of character(String) from main nucleo to sub nucleo and After sent the Full String some done Message will send from sub nucleo to main nucleo. pls see my Codes.
// main Nucleo
#include "mbed.h"
#include"string.h"
Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PC_12,PD_2); // NUCLEO-F746zg
char resStr[] = "ABCDEFGH#";
int main()
{
pc.baud(115200);
receiver.baud(115200);
pc.printf("Starting...\r\n"); // Send to PC's serial terminal
int ch;
int i=0;
while (1)
{
pc.printf("\n Select The case :");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\n nucleo to nucleo Communication");
while(resStr[i] != '#' )
{
if(receiver.writeable())
{
receiver.putc(resStr[i]); //sending to Sub Nucleo F746ZG
printf("\n send=%c",resStr[i]);
wait_ms(100);
}
i++;
}
printf("\nsending done");
}
break;
}
}
}
// Sub Nucleo
#include "mbed.h"
#include"string.h"
Serial pc(USBTX, USBRX); // tx, rx
Serial receiver(PG_14,PG_9); // NUCLEO-F746ZG
char received[50] = "\0"; // buffer with a size with Null
char c='\0';
int main()
{
pc.baud(115200);
receiver.baud(115200);
pc.printf("Ready\n\r");
int i=0;
while(1)
{
//while(receiver.readable() < '\0')
while(receiver.readable() )
{
c = receiver.getc(); // Receive from main NUCLEO-F746zg
received[i]=c;
printf("Received=%c",received[i]);
i++;
c='\0'; // make it c null for ready to receive the next Char
wait_ms(100);
}
for(int j=0;j!=50;j++)
{
received[j] = '\0'; // make it Received String Null for Next Receive Data
wait_ms(100);
}
}
}