UDP Communication and an addtional SPI connection, STM32duino

All about boards manufactured by ST
Post Reply
Posts: 1
Joined: Sat Apr 11, 2020 6:21 pm

UDP Communication and an addtional SPI connection, STM32duino

Post by furkanalemdar »

Hello guys,

I am working on a project, where I want to make two MCUs communicate with each other. I am using STM32F29ZI. I am using the example sketch UDPSendReceiveString and it works fine. The two MCUs have different MAC-Addresses and IPs. And one of them begins to send a message. After that the infinite loop begins..

Code: Select all

#include <SPI.h>
#include <LwIP.h>
#include <STM32Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xFF
IPAddress ip(192, 168, 1, 176);
IPAddress server(192, 168, 1, 177);
const int slaveSelectPin = 7;
unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged";        // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  pinMode (slaveSelectPin, OUTPUT);
// start the Ethernet
  Ethernet.begin(mac, ip);

  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");

  // start UDP // only one of them

void loop() {

  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print("Received packet of size ");
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i=0; i < 4; i++) {
      Serial.print(remote[i], DEC);
      if (i < 3) {
    Serial.print(", port ");

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);

    // send a reply to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Soo the code above works, but if I paste this code right under void loop{

Code: Select all

void loop() {

  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE2));
it wont work anymore, and I have really not one idea, why it doesnt.

I need your help please..


User avatar
Posts: 848
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 33
Location: Le Mans

Re: UDP Communication and an addtional SPI connection, STM32duino

Post by fpiSTM »

Hi @furkanalemdar
sorry for the delay.
which board you used the Nucleo F429ZI ?
I guess there is a conflict btw some pin used by ETH and the SPI instance.
Ex: PA7:
https://github.com/stm32duino/Arduino_C ... ins.c#L284

Code: Select all


Posts: 27
Joined: Fri Dec 20, 2019 6:47 pm

Re: UDP Communication and an addtional SPI connection, STM32duino

Post by sheepdoll »

Yes, If you want to use ETH, you have to move some straps on the Nucleo. These are called out in the app note for the Nucleo board. There may have been some discussion on Stack exchange which pointed to this.

For some reason ST did not mount the 8Mhz crystal on the 144 pin STM32F429 Nucleo either. The Osc clock clock strapped to the On board ST Link. At least they give you the digikey part number. The bypass crystals are pretty small. I ordered 402 but it looks like 603 would fit.

The other downside to the STM32F429 in any variation is that one can not use the LCD in the LTDC mode. Well you can but cubeMX will not allow both code setups due to one of the pins (126 PG11) with a function overlap. This is the B3 address line, which is the third weighed blue channel address. On the other hand one can connect the display to SPI/ which is slow. The FMC LCD might work. I did manage to get ETH to work on the 429i discovery and did not really notice any noise on the display. You really have to hack out a lot of the429i disco I removed the MEMS GYRO, USB and I think the indicator LEDs. On the other hand one can run a uC Linux on it with these hacks.

The other thing is that CubeMX generates a bad address setup for the LAN8742APHY. The HAL code is really written for the 83848PHY. One has to check the datasheet for the PHY as only a skeleton driver is provided.

I am not using LWIP, but the library I am using code that copied some functions from the ASF LWIP.

Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”