2018-11-18 02:12 PM
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.
Solved! Go to Solution.
2018-11-18 03:17 PM
> 0x1000U (8 decimal)
No, that's 4096 decimal. 0x in C means hexadecimal.
JW
2018-11-18 03:17 PM
> 0x1000U (8 decimal)
No, that's 4096 decimal. 0x in C means hexadecimal.
JW
2018-11-18 03:31 PM
My mistake. Of course I mean 8 binnary, not decimal.
Edit:
I GOT IT!
Many thanks!