UDP Communication and an addtional SPI connection, STM32duino

All about boards manufactured by ST
Post Reply
furkanalemdar
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
  SPI.begin();
  Ethernet.begin(mac, ip);

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  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
  Udp.begin(localPort);
  Udp.beginPacket(server,localPort);
  Udp.write(ReplyBuffer);
  Udp.endPacket();
}

void loop() {

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

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}
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));
  SPI.endTransaction();
it wont work anymore, and I have really not one idea, why it doesnt.

I need your help please..

LG
Furkan
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

 {PA_7,  SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, // - ETH RMII RX Data Valid (when JP6 ON)
sheepdoll
Posts: 32
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.
Manish1996
Posts: 1
Joined: Mon Sep 26, 2022 10:00 pm

Re: UDP Communication and an addtional SPI connection, STM32duino

Post by Manish1996 »

Is this issue resolved? How exactly did u overcome the conflict?
Post Reply

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