AnsweredAssumed Answered

DMA operation using I2C

Question asked by arvindnataraj on May 17, 2016
Latest reply on May 23, 2016 by sachin06j


Im using ADuCm3029 mixed signal processor. I was able to read the temperaure values from the onboard ADT7420 temperature sensor using I2C. Now, I want to write the sensor values via DMA into the memory directly. I ran into troubles during this. When is a DMA request initiated? Can anyone please help?

 

/*!

*****************************************************************************

* @file:    temperature_sensor.c

* @brief:   ADT7420 temperature sensor example using I2C device driver.

* @version: $Revision: 28843 $

* @date:    $Date: 2014-11-28 09:10:14 -0500 (Fri, 28 Nov 2014) $

*-----------------------------------------------------------------------------

*

Copyright (c) 2011-2014 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.

*

*****************************************************************************/

/*!

* @file      temperature_sensor.c

*

* @brief     ADT7420 temperature sensor example using I2C device driver

*

*/

 

 

#include <stdio.h>

#include <assert.h>

#include <system.h>

#include <drivers/i2c/adi_i2c.h>

#include <services/pwr/adi_pwr.h>

#include "common.h"

#include "temperature_sensor.h"

 

 

 

 

static ADI_I2C_HANDLE masterDev;

uint16_t a;

uint32_t mem[ADI_DMA_MEMORY_SIZE];

/*

* main

*/

void dmaCallBack(void *pCBParam,uint32_t Event,void *pArg)

{

 

}

int main(void)

{

    ADI_I2C_RESULT eResult=ADI_I2C_SUCCESS;

    uint8_t DevID;

    //uint8_t t_msb, t_lsb;

    //int16_t Temp;

   // float ctemp, ftemp;

    uint8_t deviceMemory[ADI_I2C_MEMORY_SIZE];

  

    /* Clock initialization */

    SystemInit();

  

    adi_initpinmux();

  

    /* test system initialization */

    test_Init();

      

    do

    {

  

        if(adi_pwr_Init()!= ADI_PWR_SUCCESS)

        {

            DEBUG_MESSAGE("\n Failed to intialize the power service \n");

            eResult = ADI_I2C_FAILURE;

            break;

        }

      

        if(ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_HCLK,1))

        {

            DEBUG_MESSAGE("Failed to set clock divider for HCLK\n");

            break;

        }

       

        if(ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_PCLK,1))

        {

            DEBUG_MESSAGE("Failed to set clock divider for PCLK\n");

            break;

        }  

      

        eResult = adi_i2c_Open(TWIDEVNUM,

                              ADI_I2C_MASTER,

                              &deviceMemory[0],

                              ADI_I2C_MEMORY_SIZE,

                              &masterDev);

        DEBUG_RESULT("adi_i2c_Open failed\n",eResult,ADI_I2C_SUCCESS);

      

        eResult = adi_i2c_SetBitRate(masterDev, BITRATE);

        DEBUG_RESULT("adi_i2c_SetBitRate failed\n",eResult,ADI_I2C_SUCCESS);

 

 

        eResult = adi_i2c_SetDutyCycle(masterDev, DUTYCYCLE);

        DEBUG_RESULT("adi_i2c_SetDutyCycle failed\n",eResult,ADI_I2C_SUCCESS);

      

      

        /* Set hardware address width */

        eResult = adi_i2c_SetHWAddressWidth(masterDev, ADI_I2C_HWADDR_WIDTH_7_BITS);

        DEBUG_RESULT("adi_i2c_SetHWAddressWidth failed\n",eResult,ADI_I2C_SUCCESS);

 

 

        /* set ADT7420 slave address */

        eResult = adi_i2c_SetHardwareAddress(masterDev, TARGETADDR);

        DEBUG_RESULT("adi_i2c_SetHardwareAddress failed\n",eResult,ADI_I2C_SUCCESS);

      

  void* dest=&a;

      

ADI_DMA_CHANNEL_HANDLE hDevice0;

 

 

ADI_DMA_TRANSFER dmaDevice;//(void *TARGETADDR,void* dest,ADI_DMA_WIDTH_1_BYTE,(1u<<4u),ADI_DMA_INCR_1_BYTE,ADI_DMA_INCR_1_BYTE);

 

 

void* cbParam;

 

 

adi_dma_Open(ADI_DMA_CHANNEL_I2CS_TX,mem,&hDevice0,dmaCallBack,cbParam);//open - incomplete

 

 

adi_dma_SetPriority(hDevice0,ADI_DMA_PRIORITY_DEFAULT);//set basic priori

 

 

 

 

 

 

//  dmaDevice.pSrcData =(TARGETADDR);//0x48-ADT7420(Hardware Address)

  dmaDevice.pDstData = dest;

  dmaDevice.DataWidth = ADI_DMA_WIDTH_1_BYTE;

  dmaDevice.NumTransfers =(1u<<4u);

  dmaDevice.SrcInc = ADI_DMA_INCR_1_BYTE ;

  dmaDevice.DstInc = ADI_DMA_INCR_1_BYTE ;

 

adi_dma_SetArbitrationRate(hDevice0,ADI_DMA_RPOWER_1);//arbitration rate

 

 

adi_dma_SetMode(hDevice0,ADI_DMA_MODE_BASIC);//basic mode

 

adi_dma_Enable(hDevice0,true);//enable

 

 

adi_dma_SubmitTransfer(hDevice0,&dmaDevice);//submit transfer

 

    }while(0);

   /* In the folllowing lines, I print the value of data received via DMA operation through UART*/

   int temp=(int)a;

    int d = 48+(temp%10);

  char b=(char)d;

   char *c=&b;

   DEBUG_MESSAGE(c);

 

    d = 48+((temp/10)%10);

   b=(char)d;

   c=&b;

   DEBUG_MESSAGE(c);

  

    return 0;

}

Outcomes