Skip to main content
John Doe1
Associate III
November 18, 2018
Solved

STM32 HAL PHY Write register question

  • November 18, 2018
  • 1 reply
  • 1394 views

I have trouble to understand bits in phy registers using HAL_ETH_WritePHYRegister() method.

I'll try to explain my question using PHY_AUTONEGOTIATION value defined in stm32xxxx_hal_config.h

Basing on the default LAN8742a which is implemented on nucleo boards with ethernet, also well supported by CubeMX.

Define in stm32fxxx_hal_config.h:

#define PHY_BCR ((uint16_t)0x00U) /*!< Transceiver Basic Control Register */
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */

File stm32fxxx_hal_eth.c:

 /* Enable Auto-Negotiation */
 if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_AUTONEGOTIATION)) != HAL_OK)
 {
 	...
 }

In LAN8742a datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/8742a.pdf):

4.2.1 Basic Control Register, Page 67:

bit 12: Auto-Negotiation Enable
 0: disable auto-negotiation process
 1: enable auto-negotiation process
 

As I understand HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_AUTONEGOTIATION) sets 12th bit of BCR.

The question is:

How come that PHY_AUTONEGOTIATION is defined as 0x1000U (binnary to int = 8 ) to manage 12th bit of Basic Control Register?

How 0x1000U means 12th bit of PHY_BCR register? I can't figure it out.

Many thanks for explanation.

This topic has been closed for replies.
Best answer by waclawek.jan

> 0x1000U (8 decimal)

No, that's 4096 decimal. 0x in C means hexadecimal.

JW

1 reply

waclawek.jan
waclawek.janBest answer
Super User
November 18, 2018

> 0x1000U (8 decimal)

No, that's 4096 decimal. 0x in C means hexadecimal.

JW

John Doe1
John Doe1Author
Associate III
November 18, 2018

My mistake. Of course I mean 8 binnary, not decimal.

Edit:

I GOT IT!

Many thanks!