Skip to content

Commit f399f9d

Browse files
committed
PHY address setter
1 parent 03e1d5e commit f399f9d

File tree

8 files changed

+17
-5
lines changed

8 files changed

+17
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ W5500Driver driver(4, 26, 27); // CS pin is 4, INT pin is 26, reset pin is 27
4949
W5500Driver driver(SS, -1, 27); // CS pin is default, INT is not used and reset pin is 27
5050
```
5151

52-
To use other SPIClass instance set it on driver with `setSPI`. To change the SPI frequency use `setSpiFreq`. Default frequency is 20 MHz.
52+
To use other SPIClass instance set it on driver with `setSPI`. To change the SPI frequency use `setSpiFreq`. Default frequency is 20 MHz. Sometimes automatic PHY address detection doesn't work, then use `setPhyAddr` to set the right PHY address.
5353

5454
Example with all options specified (using HSPI as SPI1 on FSPI pins):
5555

@@ -64,6 +64,7 @@ void setup() {
6464
6565
driver.setSPI(SPI1);
6666
driver.setSpiFreq(10);
67+
driver.setPhyAddress(0);
6768
6869
Ethernet.init(driver);
6970
@@ -113,6 +114,8 @@ The EMACDriver has optional parameters:
113114

114115
The values for clockPin and clockMode are [enums from ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_eth.html?highlight=rmii#id14).
115116

117+
Sometimes automatic PHY address detection doesn't work, then use `setPhyAddr` to set the right PHY address.
118+
116119
## The Ethernet object
117120

118121
### MAC address

src/utility/DM9051Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ esp_eth_mac_t* DM9051Driver::newMAC() {
4141

4242
esp_eth_phy_t* DM9051Driver::newPHY() {
4343
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
44-
phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO;
44+
phy_config.phy_addr = phyAddr;
4545
phy_config.reset_gpio_num = digitalPinToGPIONumber(pinRst);
4646

4747
return esp_eth_phy_new_dm9051(&phy_config);

src/utility/EMACDriver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ esp_eth_mac_t* EMACDriver::newMAC() {
4848

4949
esp_eth_phy_t* EMACDriver::newPHY() {
5050
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
51+
phy_config.phy_addr = phyAddr;
5152
phy_config.reset_gpio_num = digitalPinToGPIONumber(powerPin);
5253

5354
switch (type) {

src/utility/ENC28J60Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ esp_eth_mac_t* ENC28J60Driver::newMAC() {
4141

4242
esp_eth_phy_t* ENC28J60Driver::newPHY() {
4343
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
44-
phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO;
44+
phy_config.phy_addr = phyAddr;
4545
phy_config.reset_gpio_num = digitalPinToGPIONumber(pinRst);
4646

4747
return esp_eth_phy_new_enc28j60(&phy_config);

src/utility/EthDriver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ void EthDriver::end() {
3939
}
4040
}
4141

42+
void EthDriver::setPhyAddress(int32_t addr) {
43+
phyAddr = addr;
44+
}
45+
4246
EthDriver::~EthDriver() {
4347
end();
4448
};

src/utility/EthDriver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class EthDriver {
3737
void begin();
3838
void end();
3939

40+
void setPhyAddress(int32_t addr);
41+
4042
virtual bool usesIRQ() = 0;
4143

4244
protected:
@@ -45,6 +47,8 @@ class EthDriver {
4547

4648
friend class EthernetClass;
4749

50+
int32_t phyAddr = ESP_ETH_PHY_ADDR_AUTO;
51+
4852
esp_eth_mac_t* mac = NULL;
4953
esp_eth_phy_t* phy = NULL;
5054
};

src/utility/KSZ8851SNLDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ esp_eth_mac_t* KSZ8851SNLDriver::newMAC() {
4141

4242
esp_eth_phy_t* KSZ8851SNLDriver::newPHY() {
4343
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
44-
phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO;
44+
phy_config.phy_addr = phyAddr;
4545
phy_config.reset_gpio_num = digitalPinToGPIONumber(pinRst);
4646

4747
return esp_eth_phy_new_w5500(&phy_config);

src/utility/W5500Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ esp_eth_mac_t* W5500Driver::newMAC() {
4141

4242
esp_eth_phy_t* W5500Driver::newPHY() {
4343
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
44-
phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO;
44+
phy_config.phy_addr = phyAddr;
4545
phy_config.reset_gpio_num = digitalPinToGPIONumber(pinRst);
4646

4747
return esp_eth_phy_new_w5500(&phy_config);

0 commit comments

Comments
 (0)