ADF 7241

Hi,
i try to setup a simple ping pong test with two devices, therefore i search for a simple sample code to do this with the ADF7241.
Host CPU ist a STM31L1XXX
Does someone know, where to find something?
Regards
KHB

Parents Reply Children
  • +1
    •  Analog Employees 
    on Oct 23, 2018 5:28 AM over 1 year ago in reply to Allan.Chan@analog.com

    /*
    
    Copyright (c) 2011-2017 Analog Devices, Inc.
    
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without modification,
    are permitted provided that the following conditions are met:
      - Redistributions of source code must retain the above copyright notice,
        this list of conditions and the following disclaimer.
      - Redistributions in binary form must reproduce the above copyright notice,
        this list of conditions and the following disclaimer in the documentation
        and/or other materials provided with the distribution.
      - Modified versions of the software must be conspicuously marked as such.
      - This software is licensed solely and exclusively for use with processors
        manufactured by or for Analog Devices, Inc.
      - This software may not be combined or merged with other code in any manner
        that would cause the software to become subject to terms and conditions
        which differ from those listed here.
      - Neither the name of Analog Devices, Inc. nor the names of its
        contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
      - The use of this software may or may not infringe the patent rights of one
        or more patent holders.  This license does not release you from the
        requirement that you obtain separate licenses from these patent holders
        to use this software.
    
    THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
    TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
    NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
    PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
    OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *****************************************************************************/
    
    #include <stddef.h>        /* for 'NULL' */
    #include <string.h>        /* for strlen */
    #include "common.h"
    #include <stdio.h>
    
    #include <drivers/general/adi_drivers_general.h>
    
    #include <drivers/spi/adi_spi.h>
    #include <drivers/pwr/adi_pwr.h>
    
    /* Choose a SPI device */
    #define SPI_DEVICE_NUM    2U
    
    /** define size of data buffers, DMA max size is 255 */
    #define BUFFERSIZE 255
    
    /* SPI Peropherals*/
    #define SPI2_SCLK_PORTP1_MUX    ((uint16_t) ((uint16_t) 1<<4))
    #define SPI2_MISO_PORTP1_MUX    ((uint16_t) ((uint16_t) 1<<6))
    #define SPI2_MOSI_PORTP1_MUX    ((uint16_t) ((uint16_t) 1<<8))
    #define SPI2_CS_3_PORT2_MUX     ((uint16_t) ((uint16_t) 2<<14))
    
     /* data buffer */
    static uint8_t txbuf[BUFFERSIZE];
    static uint8_t rxbuf[BUFFERSIZE];
    
    /* device memory */
    uint8_t spidevicemem[ADI_SPI_MEMORY_SIZE];
    
    int main(void)
    {
        ADI_SPI_HANDLE hDevice;
    
        /* Board Initialization */
        adi_pwr_Init();
        adi_pwr_SetClockDivider(ADI_CLOCK_HCLK,1);
        adi_pwr_SetClockDivider(ADI_CLOCK_PCLK,1);
        
        /* Pin Initialization */
        *((volatile uint32_t *) REG_GPIO1_CFG) = SPI2_SCLK_PORTP1_MUX | SPI2_MISO_PORTP1_MUX | SPI2_MOSI_PORTP1_MUX;
        *((volatile uint32_t *) REG_GPIO2_CFG) = SPI2_CS_3_PORT2_MUX;
        
        /* SPI */
        adi_spi_Open(SPI_DEVICE_NUM,spidevicemem, ADI_SPI_MEMORY_SIZE, &hDevice);
        adi_spi_SetBitrate(hDevice, 100000);
        adi_spi_SetChipSelect(hDevice, ADI_SPI_CS3);
        
        ADI_SPI_TRANSCEIVER transceive;
          transceive.TransmitterBytes = BUFFERSIZE;
          transceive.ReceiverBytes = BUFFERSIZE;
          transceive.pTransmitter = txbuf;
          transceive.pReceiver = rxbuf;
          transceive.nTxIncrement = 1;
          transceive.nRxIncrement = 1;
          transceive.bDMA = false;
          transceive.bRD_CTL = false;
    
        /* set the SPI command to be sent */
          
        txbuf[0] = 0xB2;                                            // load RC_IDLE (0xFF) to txbuf 
        adi_spi_MasterReadWrite(hDevice, &transceive);              // Read initial value and send RC_IDLE
        printf("Tx Buffer: 0x%x\n", txbuf[0]);
        printf("Rx Buffer: 0x%x\n", rxbuf[0]);
        
        txbuf[0] = 0xFF;                                            //load NOP (0xFF) to txbuf 
        adi_spi_MasterReadWrite(hDevice, &transceive);              // Read received status from radio and send NOP
        printf("Tx Buffer: 0x%x\n", txbuf[0]);
        printf("Rx Buffer: 0x%x\n", rxbuf[0]);
        
        txbuf[0] = 0xB3;                                            // RC_PHY_RDY (0xFF) to txbuf 
        adi_spi_MasterReadWrite(hDevice, &transceive);              // Read status from radio and send RC_PHY_RDY 
        printf("Tx Buffer: 0x%x\n", txbuf[0]);
        printf("Rx Buffer: 0x%x\n", rxbuf[0]);
        
        txbuf[0] = 0xFF;                                            //load NOP (0xFF) to txbuf 
        adi_spi_MasterReadWrite(hDevice, &transceive);              // Read received status from radio and send NOP
        printf("Tx Buffer: 0x%x\n", txbuf[0]);
        printf("Rx Buffer: 0x%x\n", rxbuf[0]);
    
        /* Close the SPI device  */
        adi_spi_Close(hDevice);
        
        /* The example has successfully completed */
        common_Pass();
    }
    
    
    

    Hi!

    I have attached a sample code for a ping pong test between the ADF7021 and the ADuCM3029 EZ-KIT. Hope this will help.

    Regards,
    Allan