# rpi - SPI read fram MB85RS64 status register
# provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-12-28  initial release

import	time
from	spidev	import	SpiDev

# ===================== Constants =====================

WREN	= 0x06						# MB85R64 write enable
WRDI	= 0x04						# MB85R64 write disable
RDSR	= 0x05						# MB85R64 read  status register
WRSR	= 0x01						# MB85R64 write status register
READ	= 0x03						# MB85R64 read  date
WRITE	= 0x02						# MB85R64 write data

# ================== Hardware setup ===================

spi	= SpiDev()						# instantiate object for SPI communication

# ====================== Test =========================

def framOpen(spi):
    spi.open(0, 0)					# /dev/spidev0.0
    spi.max_speed_hz = 1_000_000	# 1 MHz
    spi.mode         = 0b11
    
    
# SPI loop-back test
def framGetStatus(spi):
    data_tx = [RDSR, 0]
    data_rx = spi.xfer(data_tx)
    print("RX:", data_rx)
        

def test():
    framOpen(spi)
    framGetStatus(spi)
    
    
try:
    test()
except:
    print('Test aborted')
spi.close()
    
# ====================== End ==========================
