Post Go back to editing

General purpose input parameters controlled by an external microcontroller

Method 1: Using the GPIO Value Registers

The ADAU1761, ADAU144x, and ADAU1781 SigmaDSPs are capable of reading GPIO inputs from registers instead of pins. Please take a look at AN-951:

http://www.analog.com/static/imported-files/application_notes/AN-951.pdf

The use case of interest is “Input Driven by Control Port,” which is shown in Figure 16 on page 6.

The corresponding registers in the ADAU1761 allowing control over the GPIO inputs are shown here:

I attached two example projects. In both projects, the schematic is the same. A GPIO input is connected to a readback cell, which allows you to read back the value of the signal via the I2C/SPI port.

In the first project, Input_GPIO_Switch_S3.dspproj, the GPIO registers are configured as GPIO Active, Input Debounce mode.

The data flow for this use case is shown in this figure:

If I download this project and press the switch S3 on the evaluation board, I can see that I read back zero (5.23 format) on the DSP readback cell.

If I release the switch S3 on the evaluation board, I can read back one (5.23 format) on the DSP readback cell.

In the second project, “Input_GPIO0SET_Register_1568”, the GPIO pin changes its function to an I2S port. However, the DSP core reads its value from an address instead.

Unfortunately there is a small error in this figure. The arrow  connecting REGISTER and DSP CORE should have its direction reversed. So,  the value goes in through the CONTROL PORT, is written to the REGISTER,  and then read into the DSP CORE.

Here are the register settings for this case. Note that all GPIO pins are used for the I2S port, but the core will read GPIO input values from the corresponding GPIO register.

Now I open the Register Read/Write Window…

If I write 0x00 0x80 0x00 0x00 to the GPIO0SET register (address 1568 in the case of the ADAU1761)…

I read back 1.

If I write 0x00 0x00 0x00 0x00 to address 1568…

I read back 0.

Using this method, you can have direct control over a GPIO input in the signal flow, regardless of what value is actually on the input pin. All you need to do is configure the GPIO pin as "Input controlled by I2C/SPI port."

Method 2: Creating a "Dummy" DC Source

This method works for all SigmaDSPs.

Create a DC source in the project.

Give it a meaningful name.

Compile the project.

Click the Export System Files button.

Save the exported files somewhere in the project folder. I named my exported files “Test.”

Open either Test.params or Test_IC1_1.PARAM.h. The address of the Test_Input you created is listed there.

Using this address, the MCU can update this parameter at any time.

So, using this method, you simply create one DC Source cell in the SigmaStudio project for each parameter that the MCU will be updating via the I2C port.

ADAU1761GPIOExamples.zip
  • Hi,

    I' m a little in trouble:

    in the ADAu1761 datasheet it seem that I have to send to the address (0x620+gpiopin) the 0x00 00 00 01 word in order to enable an output.

    For what I saw in your post I have to send a 0x00 80 00 00

    I'm not able to set the GPIO .... any suggestion?

    I made the following function to manage the io pins:

    void CodecConfigGPIO(u8 codecid, u8 gpio, u8 mode)
    {
        if ( gpio > 3)
        {
            return;
        }

     

        SIGMA_READ_REGISTER(codecid, REG_SERIAL_DATAGPIO_PIN_CONFIG_ADDR , par, 1);

     

        par[0] |= 1 << gpio;

     

        SIGMA_WRITE_REGISTER_BLOCK(codecid, REG_SERIAL_DATAGPIO_PIN_CONFIG_ADDR , 1, par);

     

        par[0] = mode;
        SIGMA_WRITE_REGISTER_BLOCK(codecid, REG_GPIO_0_CONTROL_ADDR+gpio, 1, par);
    }

     

    void CodecSetGPIO(u8 codecid, u8 gpio, u8 mode)
    {
        memset(par, 0, 4);
        if (gpio > 3)
        {
            return;
        }


       // par[1] = mode ? 0x80 : 0x00;
        par[4] = mode ? 0x01 : 0x00;
        SIGMA_WRITE_REGISTER_BLOCK(codecid, CODEC_GPIO_ADDRESS+gpio, 4, par);
    }

     

    u8 CodecGetGPIO(u8 codecid, u8 gpio)
    {
        if (gpio > 3)
        {
            return 0;
        }

     

        SIGMA_READ_REGISTER(codecid,CODEC_GPIO_ADDRESS+gpio , par, 4);

     

        return (par[1] != 0);
    }

    In the main loop:

         CodecConfigGPIO(0x72, 0, OUTPUT_PULLUP_I2C_CONTROL);
         CodecConfigGPIO(0x72, 1, OUTPUT_PULLUP_I2C_CONTROL);
         CodecConfigGPIO(0x72, 2, OUTPUT_PULLUP_I2C_CONTROL);
         CodecConfigGPIO(0x72, 3, OUTPUT_PULLUP_I2C_CONTROL);

    where the OUTPUT_PULLUP_I2C_CONTROL = 0x09.

    I read back the configuration register and the values seem to be ok.

    To set the port Icall the function

        CodecSetGPIO(0x72, 0, 1);

    Have I to set any other register in order to enable the GPIO pins

    other than register 0x40C6-C9 and 0x40F4?

  • I'm trying to use only some features of adau1761 in my project.

    I initialized the codec configuring the minimum register's set

    At the moment I use the internal in/out pga and mixer and the gpio.

    I didn't make any sigmastudio project for this configuration.

    In the datasheet (page 50 of rev C) in the table 32 I see: to drive the output  I have write a word at the loaction 1568-1571

    with the bit 0 set and the bit [31:1] are reserved.There is  an erroro in the datasheet ?

  • Have I to enable the DSP core in order to access to the 0x0620 address ?

    I'm not able to enable disable the pin....

  • Ok I solved the problem! I forgot to enable the CLOCK!

    The minimal setup sequence in order to work with the codec (no DSP) is:

    4000 --> select the clock source 0x7F

    4002 --> PLL setting

    40F9 --> Clock Enable 0 --> 0x7F

    40FA --> Clock Enable 1 --> 0x01

    40C6--> GPIO CONFIG  ---> 0x09 (for I2C output)

    40F4 ---> GPIO CONFIG  --> 0x0F

  • I just gave this a try on my evaluation board and had no issues. Please try this sequence on your evaluation board to confirm:

    Power on the board.

    Connect jumpers J9 and J10. (connects the LEDs to the GPIO pins)

    Link-compile-download a simple program.

    Set address 0x40C8 to 0x09. (enables GPIO2 as a control port GPIO output with pull-up)

    Set address 0x40C9 to 0x09. (enables GPIO2 as a control port GPIO output with pull-up)

    Set address 0x40F4 to 0x0F. (enables all GPIO pins)

    Write any value (except zero) to addresses 0x0622 and 0x0623. The LEDs on the board should turn on.

    Two important notes:

    NOTE #1 - You must perform the link-compile-download, which will set up the PLL, start the DSP core, et cetera. If you don't perform this step, then the GPIO pins will not output the value specified in the GPIO value registers.

    NOTE #2 - You can write any non-zero value to the GPIO value registers (adresses 0x0620 to 0x0623). It will be stored as 0x00 0x80 0x00 0x00, regardless of what you write. So, I could write 0x00 0x67 0x45 0x23 - a random set of bits - and the value will be stored in the register as 0x00 0x80 0x00 0x00. So, a non-zero value written to this register will be saved as "1", and a zero value written to this register will be saved as "0".

  • Stefano Fante wrote:

    I'm trying to use only some features of adau1761 in my project.

    I initialized the codec configuring the minimum register's set

    At the moment I use the internal in/out pga and mixer and the gpio.

    I didn't make any sigmastudio project for this configuration.

    I believe the core needs to at least be running in order for the GPIOs to work. Please make sure you enable the DSP Enable bit (0x40F5) and DSP Run bit (0x40F6). Also set the DSP sample rate 0x40EB and enable the clocks (0x40F9 and 0x40FA). Most importantly, the internal core clocks should be enabled (0x4000).

    Stefano Fante wrote:

    In the datasheet (page 50 of rev C) in the table 32 I see: to drive the output  I have write a word at the loaction 1568-1571

    with the bit 0 set and the bit [31:1] are reserved.There is  an erroro in the datasheet ?

    I suppose this is just a simplification in the documentation, not really an error. The main idea is that you can write any non-zero value and it will be treated as a logic 1, and if you write all zeros then it will be treated as logic 0. Really, toggling only one bit is necessary, so for simplicity, bit [0] was chosen. So, the datasheet is essentially correct - writing a zero or one to bit [0] will indeed toggle the GPIO output accordingly.

  • To complete the initialization.....

    In order to access the 0x0620-0x623 parameter register for the I2C GPIO management I have to

    enable the dsp.

    0x40F5 -- > 0x01          // DSP ENABLE

  • Yes, without the clocks, the memory controller will not allow access to the memory. You'll need to enable the internal MCLK registers in order to have data transferred around appropriately inside the chip.

    Thanks for posting your sequence for the ADAU1761 codec-only minimum use case.

  • Hello BrettG,

    I tried Method 1 with EVAL-ADAU1x81Z using GPIO_0 and S2 combo. Can you see a mistake I m making? Been banging my head for a while now. I also tried using GPIO with a multiplexer to switch between two virtual oscillators. No switching action although I have oscillator output at the DAC. Thanks!

    redBeard

    attachments.zip