chipKIT® Development Platform

Inspired by Arduino™

Cerebot MX3cK with PmodAD5

Created Mon, 04 Nov 2013 14:18:24 +0000 by RobinSI


RobinSI

Mon, 04 Nov 2013 14:18:24 +0000

hello all. I need your help. To perform the analog-digital conversion I acquired the PmodAD5 and I have no idea how to acquire the information to my chipKIT Cerebot MX3cK. I decided to use MPIDE because I want to code program usable on several plateform (like Arduino). I downloaded the generic DRIVER for the PmodAD5 on this site: http://wiki.analog.com/resources/tools-software/uc-drivers/renesas/ad7193

The DRIVER is correctly compile, but I had to create three functions for using my PmodAD5 with the SPI communication.

SPI_Init() function :

unsigned char SPI_Init(unsigned char lsbFirst,
                       unsigned long clockFreq,
                       unsigned char clockPol,
                       unsigned char clockEdg)
{
}

this function must initialize the SPI communication peripheral and return 1 if initilization is succesfull.

SPI_Read() function :

unsigned char SPI_Read(unsigned char slaveDeviceId,
                       unsigned char* data,
                       unsigned char bytesNumber)
{
}

Reads data from SPI: -slaveDeviceId - The ID of the selected slave device -Data represents the write buffer as an input parameter and the read buffer as an output parameter. -bytesNumber - Number of bytes to read. -return Number of read bytes.

SPI_Write() function :

unsigned char SPI_Write(unsigned char slaveDeviceId,
                        unsigned char* data,
                        unsigned char bytesNumber)
{
}

Writes data to SPI: -slaveDeviceId - The ID of the selected slave device. -Data represents the write buffer. -bytesNumber - Number of bytes to write. -return Number of written bytes.

I have no ideas how to implemente those functions. SPI_(Init/Read/Write) functions are implemented on this site : [url]https://github.com/analogdevicesinc/no-OS/blob/master/Microchip/PIC32MX320F128H/Common/Communication.c[/url] So, I try with that, and I add this code :

void setup()
{
   Serial.begin(9600);
   SPI.begin();//start SPI communication
   pinMode(PMOD1_CS_PIN, OUTPUT);// define the chipselect
   pinMode(AD7193_RDY_STATE, INPUT);// define Miso pin as an input
   AD7193_Init();//initialize PmodAD5
   AD7193_ChannelSelect(AD7193_CH_0);// select channel 0 on PmodAD5
}
void loop()
{ 
  unsigned long data;
  data= AD7193_GetRegisterValue(AD7193_REG_ID, 1, 1);
  Serial.print(data, HEX);
  Serial.print("\n");
}

The code is correctly compiled! But I do not communicate with PmodAD5, I have nothing in Serial Clock, i think SPI communication isn't properly configurate.
I don't know where is the mistake, in my code, or in SPI_(Init/read/write) functions.

An other DRIVER is available on this site : [url]http://wiki.analog.com/resources/tools-software/uc-drivers/microchip/ad7193[/url] i try to follow this tutorial but the DRIVER does nor work and it use DSPI library(specific SPI library to chipkit) and I want to use SPI library(for using on Arduino) , that's why I decided to use generic DRIVER.

Somebody can help me? please...

In advance thank you for your help. Regards, Robin.


edernolli

Wed, 06 Nov 2013 13:33:42 +0000

Hello Robin,

You should read the pdf as below : http://www.analog.com/static/imported-files/data_sheets/AD7193.pdf

Edern OLLIVIER

PS : http://www.analog.com/en/analog-to-digital-converters/ad-converters/ad7193/products/product.html