stm32配置PHY芯片

12 篇文章 0 订阅

一、时序介绍

使用MDC 、MDIO两只引脚进行数据配置。时序为:

二、底层驱动代码

1、读PHY寄存器地址:


u16 PHY_WAN_Reg_Read( u8 PhyAddress, u8 RegisterAddress )
{
    u8      i;
    u8      bValue;
    u16     wValue;

    PHY_WAN_MDIO_Out();

//Preamble
    for( i = 0; i < 32; i ++ )
    {
        PHY_WAN_WRITE_BIT(1);
    }

//Start
    PHY_WAN_WRITE_BIT(0);
    PHY_WAN_WRITE_BIT(1);

//Opcode
    PHY_WAN_WRITE_BIT(1);
    PHY_WAN_WRITE_BIT(0);

//PHY Address
    for( i = 0; i < 5; i ++ )
    {
        if( 0x10 & PhyAddress )
        {
            PHY_WAN_WRITE_BIT(1);
        }
        else
        {
            PHY_WAN_WRITE_BIT(0);
        }
        PhyAddress <<= 1;
    }

MDC_DELAY;
MDC_DELAY;


//Register Address
    for( i = 0; i < 5; i ++ )
    {
        if( 0x10 & RegisterAddress )
        {
            PHY_WAN_WRITE_BIT(1);
        }
        else
        {
            PHY_WAN_WRITE_BIT(0);
        }

        RegisterAddress <<= 1;
    }

MDC_DELAY;
MDC_DELAY;


//TA: change MDIO to INPUT
    /* tri-state our MDIO I/O pin so we can read */
    PHY_WAN_MDC(0);PHY_WAN_MDIO_In();MDC_DELAY;PHY_WAN_MDC(1);MDC_DELAY;

    /* check the turnaround bit: the PHY should be driving it to zero */
    PHY_WAN_MDIO_READ(bValue);
    if( 0 != bValue )
    {
        //PHY_ASSERT;
    }

//<READ> Register Data
    wValue = 0;
    for( i = 0; i < 16; i ++ )
    {
        wValue <<= 1;

        PHY_WAN_READ_BIT(bValue);
        if( bValue )
        {
            wValue |= 0x0001;
        }
    }

//Idle: change MDIO to OUTPUT
    PHY_WAN_MDC(0);PHY_WAN_MDIO_Out();MDC_DELAY;PHY_WAN_MDC(1);MDC_DELAY;
    for( i = 0; i < 32; i ++ )
    {
        PHY_WAN_WRITE_BIT(1);
    }

    return wValue;
}

2、写寄存器


void PHY_WAN_Reg_Write( u8 PhyAddress, u8 RegisterAddress, u16 RegisterData )
{
    u8      i;

    PHY_WAN_MDIO_Out();

//Preamble
    for( i = 0; i < 32; i ++ )
    {
        PHY_WAN_WRITE_BIT(1);
    }

//Start
    PHY_WAN_WRITE_BIT(0);
    PHY_WAN_WRITE_BIT(1);

//Opcode
    PHY_WAN_WRITE_BIT(0);
    PHY_WAN_WRITE_BIT(1);

//PHY Address
    for( i = 0; i < 5; i ++ )
    {
        if( 0x10 & PhyAddress )
        {
            PHY_WAN_WRITE_BIT(1);
        }
        else
        {
            PHY_WAN_WRITE_BIT(0);
        }

        PhyAddress <<= 1;
    }

//Register Address
    for( i = 0; i < 5; i ++ )
    {
        if( 0x10 & RegisterAddress )
        {
            PHY_WAN_WRITE_BIT(1);
        }
        else
        {
            PHY_WAN_WRITE_BIT(0);
        }

        RegisterAddress <<= 1;
    }

//TA
    PHY_WAN_WRITE_BIT(1);
    PHY_WAN_WRITE_BIT(0);

//<WRITE> Register Data
    for( i = 0; i < 16; i ++ )
    {
        if( 0x8000 & RegisterData )
        {
            PHY_WAN_WRITE_BIT(1);
        }
        else
        {
            PHY_WAN_WRITE_BIT(0);
        }

        RegisterData <<= 1;
    }

//Idle
    PHY_WAN_MDC(0);PHY_WAN_MDIO_Out();MDC_DELAY;PHY_WAN_MDC(1);MDC_DELAY;
    for( i = 0; i < 32; i ++ )
    {
        PHY_WAN_WRITE_BIT(1);
    }
}

3、说明

其中 PhyAddress 为PHY芯片的 SMI Device Address。RegisterAddress  为PHY芯片的寄存器地址。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值