From ed816517cffd1b351514a452dd7c8ebdc0caff92 Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Wed, 31 Jul 2024 16:40:09 +0800 Subject: [PATCH] si5340: implement paged register writes Signed-off-by: Florian Agbuya --- fast-servo/pyfastservo/si5340.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fast-servo/pyfastservo/si5340.py b/fast-servo/pyfastservo/si5340.py index 67132be..2cc5b74 100644 --- a/fast-servo/pyfastservo/si5340.py +++ b/fast-servo/pyfastservo/si5340.py @@ -35,6 +35,15 @@ STATUS_LOSREF = 0x04 STATUS_LOL = 0x08 +def write_register(bus, address, value): + page = address >> 8 + register = address & 0xFF + bus.write_byte_data(IC_ADDR, 0x01, page) + try: + bus.write_byte_data(IC_ADDR, register, value) + except Exception as e: + raise Exception(f"Write failed 0x{value:02X} at 0x{address:04X}: {e}") + def write_preamble(bus): preamble = [ (0x0B24, 0xC0), @@ -45,7 +54,7 @@ def write_preamble(bus): (0x0B4E, 0x1A), ] for address, value in preamble: - bus.write_byte_data(IC_ADDR, address, value) + write_register(bus, address, value) def write_postamble(bus): postamble = [ @@ -54,7 +63,7 @@ def write_postamble(bus): (0x0B25, 0x02), ] for address, value in postamble: - bus.write_byte_data(IC_ADDR, address, value) + write_register(bus, address, value) def wait_device_ready(bus): for _ in range(15): @@ -244,7 +253,7 @@ def configure_si5340(): print("Writing main configuration...") for address, value in main_config: - bus.write_byte_data(IC_ADDR, address, value) + write_register(bus, address, value) print("Main configuration written") write_postamble(bus) -- 2.44.1