Skip to content
Snippets Groups Projects
Commit 5be2058c authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

First script for testing the MDIO interface to access the Switch registers.

parent c1f2beb0
No related branches found
No related tags found
1 merge request!2Modified the scripts to run on Raspberry Pi.
mdio.py 0 → 100644
# MDIO Interface to the ethernet Switch
import RPi.GPIO as GPIO
ClockPin =23
DataPin = 22
GPIO.setmode(GPIO.BCM)
GPIO.setup = (ClockPin, GPIO.OUT)
GPIO.setup = (DataPin, GPIO.OUT)
# Preamble
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.LOW)
for preamble_cnt in range(32):
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
# Start of Frame
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.HIGH)
# Operant Write
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.HIGH)
# Phy address
phy_addr = 0x1E
phy_addr_bits = "{:0>5b}".format(phy_addr)
for bit in phy_addr_bits:
if bit:
GPIO.output(DataPin, GPIO.HIGH)
else:
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
# phy reg
phy_reg = 0x16
phy_reg_bits = "{:0>5b}".format(phy_reg)
for bit in phy_reg_bits:
if bit:
GPIO.output(DataPin, GPIO.HIGH)
else:
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
# TA
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
#data
phy_data = 0x16
phy_data_bits = "{:0>16b}".format(phy_reg)
for bit in phy_data_bits:
if bit:
GPIO.output(DataPin, GPIO.HIGH)
else:
GPIO.output(DataPin, GPIO.LOW)
GPIO.output(ClockPin, GPIO.HIGH)
GPIO.output(ClockPin, GPIO.LOW)
GPIO.cleanup()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment