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

Added EEPROM check + read from PLL after write to check write.

parent bf6c2e04
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ if os.name =="posix":
else:
from I2C_serial import *
DEBUG = True
I2CBUSNR=3
sleep_time = 0.05
PWR_RST = False
......@@ -32,6 +33,10 @@ INT_POWER_CYCLE = False
RESET_PLL = False
UPDATE_PLL = False
READ_ALL = False
CHECK_EEPROM = True
dev_i2c_eeprom = I2C(0x50)
dev_i2c_eeprom.bus_nr = I2CBUSNR
CS = 6
SCLK = 4
......@@ -67,6 +72,11 @@ def Write_byte_PLL(reg_address, wr_data, ADDRESS=0x20):
Write_data = 0x02 | (1 << CS) | (0 << SCLK) | (0 << SDI)
I2C_device.write_bytes(0x02, Write_data)
if DEBUG:
read_bits = Read_byte_PLL(reg_address, ADDRESS)
stri = "Bits written {0} to register {1} read from PLL are {2}".format(wr_data, reg_address, read_bits)
print(stri)
def Read_byte_PLL(reg_address, nof_bytes=1, ADDRESS=0x20 ):
#
......@@ -110,8 +120,14 @@ def setup_pll(pll_frequency='200MHz') :
# Check PLL is in lock
if pll_frequency == '160MHz':
pll_address = PLL_160M
I2C_device = I2C(0x20, BUSNR=I2CBUSNR)
I2C_device.write_bytes(0x07, 0x00)
I2C_device.write_bytes(0x07, 0x08)
else:
pll_address=PLL_200M
I2C_device = I2C(0x20, BUSNR=I2CBUSNR)
I2C_device.write_bytes(0x07, 0x00)
I2C_device.write_bytes(0x07, 0xF8)
Write_byte_PLL(0x05, 0x97, pll_address)
Write_byte_PLL(0x06, 0x10, pll_address) # cp inv = 0xF4 other 0xE4
Write_byte_PLL(0x07, 0x04, pll_address) # Divider R = 1 dec
......@@ -138,6 +154,31 @@ def power(state):
I2C_IO_device.write_bytes(0x02, bits_to_set)
def read_eeprom():
#
# Read the EEPROM with the serial number etc.
#
ret_ack, ret_value = dev_i2c_eeprom.read_last_reg(1)
if ret_ack < 1:
print("no EEPROM found during read")
return False
else:
ret_ack, ret_value = dev_i2c_eeprom.read_bytes(0x00, 1)
return ret_value
def wr_rd_eeprom( value=0x34):
#
# Write and Read the EEPROM to check functionality
#
if write_eeprom(value):
ret_value = self.read_eeprom()
stri = "Wrote to EEPROM: 0x{0:X}, Read from EEPROM: 0x{1} ".format(value, ret_value)
print(stri)
return True
if CHECK_EEPROM :
wr_rd_eeprom()
if PWR_RST :
power(False)
sleep(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment