Wiznet makers

austin

Published February 16, 2023 ©

44 UCC

3 WCC

13 VAR

0 Contests

1 Followers

0 Following

Original Link

How to Use W5300 TOE - MQTT

How to Use W5300 TOE Shield with STM32 NUCLEO-144 Board

COMPONENTS Hardware components

WIZnet - W5300

x 1


PROJECT DESCRIPTION

# Overview

The W5300 TOE - MQTT Publish & Subscribe example use W5300 TOE Shield - ethernet I/O shield compatible with STM32 Nucleo-144 board built on WIZnet's W5300 ethernet chip, and STM32 Nucleo-144 board.

  • W5300 TOE Shield

STM32 Nucleo-144 boards support the list below.

And W5300 TOE - MQTT Publish & Subscribe example support two IDEs.

※ Please select and use the IDE according to the environment you are using.

Board

Example

Description

NUCLEO-F207ZG

MDK-ARM

C-based example implemented using MDK-ARM.

STM32CubeIDE

C-based example implemented using STM32CubeIDE.

NUCLEO-F429ZI

MDK-ARM

C-based example implemented using MDK-ARM.

STM32CubeIDE

C-based example implemented using STM32CubeIDE.

NUCLEO-F439ZI

MDK-ARM

C-based example implemented using MDK-ARM.

STM32CubeIDE

C-based example implemented using STM32CubeIDE.

NUCLEO-F722ZE

MDK-ARM

C-based example implemented using MDK-ARM.

STM32CubeIDE

C-based example implemented using STM32CubeIDE.

NUCLEO-F756ZG

MDK-ARM

C-based example implemented using MDK-ARM.

STM32CubeIDE

C-based example implemented using STM32CubeIDE.

NUCLEO-F767ZI

MDK-ARM

C-based example implemented using MDK-ARM.

STM32CubeIDE

C-based example implemented using STM32CubeIDE.

# Hardware Requirements

※ Currently, W5300 TOE examples only support NUCLEO-F207ZG, NUCLEO-F429ZI, NUCLEO-F439ZI, NUCLEO-F722ZE, NUCLEO-F756ZG and NUCLEO-F767ZI, so please refer to this.

# Development Environment Configuration

Setup ST-LINK

The ST-LINK pin was changed due to overlapping use of the FMC(Flexible Memory controller) data pin to control the W5300 built in the W5300 TOE Shield and the ST-LINK pin of the STM32 Nucleo-144 board.

  • STLK_RX[STM32F103CBT6_PA3] : PD8 → PC10
  • STLK_TX[STM32F103CBT6_PA2] : PD9 → PC11

Therefore, in order to use the ST-LINK of the STM32 Nucleo-144 board, minor settings are required for the W5300 TOE Shield and STM32 Nucleo-144 board.

1. Remove SB5 and SB6 from the top of the STM32 Nucleo-144 board.

2. With the W5300 TOE Shield and STM32 Nucleo-144 board combined, connect PC10, PC11 of the W5300 TOE Shield and CN5 TX, RX of the top of the STM32 Nucleo-144 board with jumper cables.

  • W5300 TOE Shield : PC10 - STM32 Nucleo-144 board : RX
  • W5300 TOE Shield : PC11 - STM32 Nucleo-144 board : TX

# How to Test MQTT Publish & Subscribe Example

Step 1: Prepare software

The following serial terminal programs are required for MQTT Publish & Subscribe example test, download and install from below links.

Step 2: Prepare hardware

1. Combine W5300 TOE Shield with STM32 Nucleo-144 board.

2. Connect ethernet cable to W5300 TOE Shield ethernet port.

3. Connect STM32 Nucleo-144 board to desktop or laptop using 5 pin micro USB cable.

Step 3: Setup MQTT Publish & Subscribe Example

To test the MQTT Publish & Subscribe example, minor settings shall be done in code.

1. Select demo application.

To run the MQTT Publish & Subscribe example, you must select the demo application in 'w5x00_demo.h' in 'W5300-TOE-C/Examples/' directory.

uncomment APP_MQTT_PUBLISH_SUBSCRIBE and comment the rest of the defined demo application macros.

// ----------------------------------------------------------------------------------------------------
// The application you wish to use should be uncommented
// ----------------------------------------------------------------------------------------------------
//#define APP_DHCP
//#define APP_DNS
//#define APP_HTTP_SERVER
//#define APP_MQTT_PUBLISH
//#define APP_MQTT_SUBSCRIBE
#define APP_MQTT_PUBLISH_SUBSCRIBE
//#define APP_LOOPBACK
// ----------------------------------------------------------------------------------------------------

2. Setup network configuration.

Setup network configuration such as IP in 'main.c' in 'W5300-TOE-C/Projects/NUCLEO-F429ZI/Core/Src/' directory.

  wiz_NetInfo net_info =
      {
          .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
          .ip = {192, 168, 11, 2},                     // IP address
          .sn = {255, 255, 255, 0},                  // Subnet Mask
          .gw = {192, 168, 11, 1},                   // Gateway
          .dns = {8, 8, 8, 8},                             // DNS server
#ifdef APP_DHCP
          .dhcp = NETINFO_DHCP                // Dynamic IP
#else
          .dhcp = NETINFO_STATIC              // Static IP
#endif
      };

3. Setup MQTT configuration.

In the MQTT configuration, the broker IP is the IP of your desktop or laptop where broker will be created.

You can modify it in 'w5x00_mqtt_publish_subscribe.c' in 'W5300-TOE-C/Examples/MQTT/Publish_Subscribe/' directory.

static uint8_t g_mqtt_broker_ip[4] = {192, 168, 11, 3};

Step 4: Build and Download

1. After completing the MQTT Publish & Subscribe example configuration, build in the IDE you are using.

2. When the build is completed, download the firmware to the STM32 Nucleo-144 board.

Step 5: Run

1. Connect to the serial COM port of STM32 Nucleo-144 board with Tera Term.

2. Run Mosquitto to be used as the broker.

3. Create broker using Mosquitto by entering the following command. If the broker is created normally, the broker's IP is the current IP of your desktop or laptop, and the port is 1883 by default.

mosquitto -c mosquitto.conf -v

4. Reset your board.

5. If the MQTT Publish & Subscribe example works normally on STM32 Nucleo-144 board, you can see the network information of STM32 Nucleo-144 board, connecting to the broker, subscribing to the subscribe topic and publishing the message.

Appendix

  • In Mosquitto versions earlier than 2.0 the default is to allow clients to connect without authentication. In 2.0 and up, you must choose your authentication options explicitly before clients can connect. Therefore, if you are using version 2.0 or later, refer to following link to setup 'mosquitto.conf' in the directory where Mosquitto is installed.
Documents
  • W5300-TOE-C

Comments Write