Two Nucleo boards (NUCLEO-F746ZG to NUCLEO-F746ZG) to communicate with each other using SPI

fermedicius
Wed, 13 Mar 2024 11:08:34 +0000
Mbed OS

Hello,
I’m trying to make two boards (NUCLEO-F746ZG and NUCLEO-F103RB) to communicate with each other using SPI. However, my slave code does not seem to work on neither of the boards.
In my board master to slave connection as per below

MASTER ( Nulceo F746ZG)
SCK -PE_2
MISO-PE_5
MOSI-PE_6
CS-PE_4

SLAVE( Nulceo F746ZG)
SCK -PE_2
MISO-PE_5
MOSI-PE_6
CS-PE_4

IN Slave Nucleo its Showing Errorbelow
pinmap not found for peripheral

Here i have Attach My Master and Slave Code
This one is Master Code Below

// master Nucleo(F746ZG)
#include "mbed.h"
#include"string.h"

Serial pc(USBTX, USBRX);                    // tx, rx (serial Communication Tera Term)
SPI Master_To_Slave(PE_6,PE_5,PE_2); // mosi, miso, sclk
DigitalOut Slave1_Selection(PE_4);               //master NUCLEO-F746ZG slave selection pin
DigitalOut Master_Led(PG_3);
char Send_String[20] = "KALAIVANAN#";
char Received_String[30]="\0";

int main()
{
    pc.baud(9600);
    int i=0;
    int j=0;
    int ch;

    while (1)
    {
        pc.printf("\n Select The case :\n");
        pc.scanf("%d",&ch);
        switch(ch)
        {
            case 1:
            {
                pc.printf("nucleo to nucleo SPI Communication\n");
                Slave1_Selection = 1; // De_Select the 1st Slave
                Master_To_Slave.format(8,3);        // Setup: 8bit mode 3
                Master_To_Slave.frequency(1000000); // Starting Frequency 1 MHZ
                while(Send_String[i] != '\0' )  // Send the String Upto Null
                    {
                        Slave1_Selection = 0; // Select the 1st Slave (Activate)
                        Received_String[j++] =  Master_To_Slave.write(Send_String[i++]); //Data Send to Master and Data Receiver From Master
                        Master_Led=!Master_Led;//LEd Blinking While Data Transfer
                        Slave1_Selection = 1; // De_Select the 1st Slave
                        wait_ms(200); // Wait for readability only(Ready to wait for Next Data)
                    }
                pc.printf("Received String=%s",Received_String);
                NVIC_SystemReset();//system reset
            }
            break;
        }
    }
}

  paste code here

This one is Slave Code Below

// Slave Nucleo (F746ZG)
#include "mbed.h"
#include"string.h"
#include"SPISlave.h"

Serial pc(USBTX, USBRX);    // tx, rx
SPISlave Master_To_Slave(PE_6,PE_5,PE_2,PE_2); //mosi, miso, sclk,SSEL - (Slave Select its activate by master in this pin low mean this Slave Selected )
DigitalOut Slave_Led(PG_3);
char Send_String[25] = "DONE#";
char Received_String[20]="\0";

int main()
{
    pc.baud(9600);
    Master_To_Slave.format(8,3);                 // Setup: 8bit mode 3
    Master_To_Slave.frequency(1000000);          // Starting Frequency 1MHZ
    pc.printf("\n Ready");
    int Responce =2024;
    int i=0;
    int j=0;
    Master_To_Slave.reply(++Responce);              // SPI with 1st reply
    Master_To_Slave.reply(++Responce);              // SPI with 2nd reply its just Responces
    printf(" \n Replay Last Responce and before while(1)=%d",Responce);
    while(1)
    {
        if(Master_To_Slave.receive());  // start Reading from Master
        {
            Received_String[i++] = Master_To_Slave.read();   // Read Data from master and Stored to Received String
            pc.printf("\n Slave1 Received String %s",Received_String); //print the Receiving Char
            Slave_Led = !Slave_Led;// LEd Blinking While Data Transfer
            Master_To_Slave.reply(Send_String[j++]); //Data Send to Master (Done Message)
            pc.printf("\n Sending String %s",Send_String[j++]); //print the sending Char
            wait_ms(200);//waiting
        }
    }
    wait_ms(10);
    NVIC_SystemReset(); //System Reset
}

10 posts - 3 participants