Post Go back to editing

Rasp Pi SPI Initial Settings

Thread Summary

The user was unable to establish SPI communication with an ADAU1467 DSP on a Raspberry Pi. The solution involved using SPI mode 0 or 3, ensuring the correct pin connections on J1 (slave control port), and toggling the CS line to switch from I2C to SPI mode. The user also confirmed that a readback cell can be used to monitor the status of a logic gate in the DSP flow.
AI Generated Content
Category: Software
Product Number: ADAU1467
Software Version: 4.7

I am doing initial interface to a R-pi using J1 on the board.  MISO, SS, MOSI, and SCLK are all verified.  Can't seem to establish com with the board and read the registers. Couple questions.

1) Do I need to buffer the SS line with the Pi?

2) Do I need to change the DIP or boot switches on the board?

3) Are there any configuration options in SS that need to be changed/set for these lines?

Any reference examples would be appreciated.  

Thanks!

 

Parents
  • Disregard that code, that was an I2C test that I have not yet run... Here is the SPI test....

    #!/usr/bin/env python3
    """
    Test ADAU1467 hardware register read/write
    Based on DaveThib's advice from Analog Devices forum
    """
    import spidev
    import time
    import RPi.GPIO as GPIO

    RESET_PIN = 26

    class ADAU1467:
    def __init__(self):
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(RESET_PIN, GPIO.OUT, initial=GPIO.HIGH)

    self.spi = spidev.SpiDev()
    self.spi.open(0, 0)
    self.spi.max_speed_hz = 1000000
    self.spi.mode = 0
    time.sleep(0.1)

    def write_register_16bit(self, addr, value):
    """Write 16-bit value to hardware register"""
    addr_high = (addr >> 8) & 0xFF
    addr_low = addr & 0xFF
    val_high = (value >> 8) & 0xFF
    val_low = value & 0xFF

    packet = [addr_high, addr_low, val_high, val_low]
    self.spi.xfer2(packet)
    time.sleep(0.01)

    def read_register_16bit(self, addr):
    """Read 16-bit value from hardware register"""
    addr_high = ((addr >> 8) & 0xFF) | 0x01 # Set read bit
    addr_low = addr & 0xFF

    packet = [addr_high, addr_low, 0x00, 0x00]
    result = self.spi.xfer2(packet)

    # Return 16-bit value from bytes 2 and 3
    return (result[2] << 8) | result[3]

    def close(self):
    self.spi.close()
    GPIO.cleanup()

    # Test as Dave suggested
    print("=" * 60)
    print("ADAU1467 Hardware Register Test")
    print("Testing register 0xF026 (Clock Gen 3 Input Reference)")
    print("=" * 60)

    CLOCK_REG = 0xF026

    dsp = ADAU1467()

    # Step 1: Read default value
    print("\nStep 1: Read default value")
    default = dsp.read_register_16bit(CLOCK_REG)
    print(f" Register 0xF026 = 0x{default:04X} (expected 0x000E)")

    # Step 2: Write new value
    new_value = 0x0005 # Valid 5-bit value
    print(f"\nStep 2: Write new value 0x{new_value:04X}")
    dsp.write_register_16bit(CLOCK_REG, new_value)
    time.sleep(0.05)

    # Step 3: Read back
    verify = dsp.read_register_16bit(CLOCK_REG)
    print(f" Read back: 0x{verify:04X}")

    if verify == new_value:
    print("\n✓✓✓ SUCCESS! Hardware register write works!")
    else:
    print(f"\n✗ Failed (expected 0x{new_value:04X}, got 0x{verify:04X})")

    dsp.close()
    print("=" * 60)

    ****And the result....****

    ============================================================
    ADAU1467 Hardware Register Test
    Testing register 0xF026 (Clock Gen 3 Input Reference)
    ============================================================

    Step 1: Read default value
    Register 0xF026 = 0x00DD (expected 0x000E)

    Step 2: Write new value 0x0005
    Read back: 0x00DD

    ✗ Failed (expected 0x0005, got 0x00DD)
    ============================================================

  • Hello ElsaDog,

    Please note that when the DSP is powered on or comes out of reset, by default the slave control port will be an I2C port, so you have to put it in SPI mode to read/write via SPI.

    Please add this code snippet and try again.

    If it still doesn't work, please attach your hardware schematic and probe the SPI port and send us the scope shots.

    Regards,

    Harish

  • Thanks for the answer, Harish!  It does not seem to change.  I also did an I2C address scan on pins 1 and 3 and see nothing (I am on the  Peripheral Cntl port, J6, btw).  I see SPI echos from the chip when in SPI mode.  Also running MODE 3 per datasheet. Still cant seem to access the registers.  Just FYI, I have a working schematic loaded and it is sending status back to Sig Studio.  When I connect on J1 to the USBi, I see constant updates streaming over the MISO lines on an SPI decode scope.  I was trying to identify the polling protocol but no luck, so far.  The pi is also very particular about seizing the CS line once SPI is running, so I moved it to another GPIO, did the pulse, then moved it back to CE0.  Still no luck.  I am hardware connected MISO on Pi to pin 5, MOSI to pin 8, CLK to pin 7, CEO/SS/CS to pin 9.   Is there a simple handshake code I can execute in the proper format so that I know I have syntax correct?  Thanks!

Reply
  • Thanks for the answer, Harish!  It does not seem to change.  I also did an I2C address scan on pins 1 and 3 and see nothing (I am on the  Peripheral Cntl port, J6, btw).  I see SPI echos from the chip when in SPI mode.  Also running MODE 3 per datasheet. Still cant seem to access the registers.  Just FYI, I have a working schematic loaded and it is sending status back to Sig Studio.  When I connect on J1 to the USBi, I see constant updates streaming over the MISO lines on an SPI decode scope.  I was trying to identify the polling protocol but no luck, so far.  The pi is also very particular about seizing the CS line once SPI is running, so I moved it to another GPIO, did the pulse, then moved it back to CE0.  Still no luck.  I am hardware connected MISO on Pi to pin 5, MOSI to pin 8, CLK to pin 7, CEO/SS/CS to pin 9.   Is there a simple handshake code I can execute in the proper format so that I know I have syntax correct?  Thanks!

Children
No Data