9 years, 6 months ago.

Setting Registers on PHY chip using the FRDM-K64F

Hi Everyone,

I am attempting to directly modify the registers on the PHY chip on my FRDM-K64F board. The reason I would like to do this, is so that I can shutdown the PHY chip. Reading through the datasheets from both the PHY chip and the MK64F I think this should be possible by setting some of the registers. Here is the code I have come up with:

void PowerDownEthInterface(void){
    // Powers down the Ethernet Interface
    unsigned int data = 0;
    unsigned int adr = 0x0; // The address of the PHY is either 0 or 3.
    
    // Turn on the ENET clock:
    SIM_SCGC2 |= SIM_SCGC2_ENET_MASK;
    // Enable the ENET:
    ENET_ECR |= ENET_ECR_ETHEREN_MASK;
    // Set the MII speed:
    ENET_MSCR |= (0x4) << ENET_MSCR_MII_SPEED_SHIFT;
    // Display some information:
    pc.printf("ENET_ECR: %d", ENET_ECR);
    
    // Build up the data register that will be sent to the PHY.
    // This uses information from Section 45.4.6 of the K64 Sub-Family Reference Manual, Document Number: K64P144M120SF5RM
    // Reset the data variable:
    data = 0;
    // Set bits 31 and 30 to 01 for a vlid MII management frame:
    data |= (0x1) << ENET_MMFR_ST_SHIFT;
    // Set the operation code (bits 29-28) to 0b01 = Write frame operation for a valid MII management frame
    data |= (0x1) << ENET_MMFR_OP_SHIFT;
    // Set the address of the PHY device to 0. There can be up to 32 devices.
    data |= (adr) << ENET_MMFR_PA_SHIFT;
    // Set the register address we would like to write to in the PHY. We want to set bit 11 in register 0, therefore set the address here to 0:
    data |= (0x0) << ENET_MMFR_RA_SHIFT;
    // Set the turn around bits to '10' for a valid MII frame:
    data |= (0x2) << ENET_MMFR_TA_SHIFT;
    // Set the data that will be written to the PHY device. For software power down, set bit 11 to 1:
    data |= ((0x1) << 11) << ENET_MMFR_DATA_SHIFT;
    // Send the data...
    pc.printf("Writing to ENET_MMFR...");
    // Clear the MII write interrupt bit (writing a '1' clears the bit):
    ENET_MMFR &= ENET_EIR_MII_MASK;
    // Send the data to the PHY device by writing to the ENET_MMFR register:
    ENET_MMFR = data;
    // Check to see if it completes:
    while((ENET_EIR & ENET_EIR_MII_MASK) == 0);
    // Done!
    pc.printf("Writing to ENET_MMFR a success!");
    // Put the MII back in a low power state:
    ENET_MSCR = 0;
    // Disable the ENET:
    ENET_ECR &= ~ENET_ECR_ETHEREN_MASK;
    // Turn off the ENET clock:
    SIM_SCGC2 &= ~SIM_SCGC2_ENET_MASK;
    
    return;
}

Unfortunately, it does not seem to work. Furthermore, if you modify the appropriate registers above to read from the PHY chip, I do not read anything either.

Any thoughts?

Thanks,

Damien

Be the first to answer this question.