Showing results for 
Search instead for 
Did you mean: 
Registered: ‎02-02-2009

Using the Spartan 3E Starter Kit ADC with Microblaze

Hi all,


I'm trying to get my ADC to work using Microblaze and C code.  I set the amp using my writeSPI() function, which works on the DAC just fine.  However, with the ADC, the AD_CONV signal is throwing me off.  I'm trying to use the SPISSR register to control it like my other SPI devices, but the user's guide said the SS register is an active-low register.  Does this mean that SCK won't output unless one of the vectors is low?  Here's my code for the ADC function:


int readADC()
    unsigned int numBytes = 4;
    int i;
    unsigned int adc_data = 0;
    int adc_a=0, adc_b=0;
    SPI_DEV_CTL=0x6;  // Turn off DAC, AMP, and Flash memory

    while(SPISSR!=deviceMask);        // Must wait for last transaction to finish
    SPICR=0x08E;    // Change SCK Polarity to high

    SPISSR=~0;                            // Assert AD_CONV to begin data conversion        
    SPISSR=~0x04;                        // Deassert AD_CONV
    // Wait 32 SCK cycles for ADCs to be read
    //for(i=0; i<1000;i++);
    SPISSR=~0;                            // Assert AD_CONV to begin sending on MISO
    SPISSR=~0x04;                        // Deassert AD_CONV
    for(; numBytes; --numBytes)                    // Read in each byte from Rx FIFO
        adc_data=(adc_data<<8)|(SPIDRR&0x0FF);            // "Append" to LSB of value
    adc_a = ((adc_data & 0xFFFC000) >> 14);
    adc_b = (adc_data & 0x3FFF);
    writeLcd(LCD_CMD, 0x01);
    printLcd("ADC A: ");
    writeLcd(LCD_CMD, 0xC0);
    printLcd("ADC B: ");
    SPICR=0x086;    // Change SCK Polarity back to low
    return adc_a;

This code is a work in progress, so many things are commented out for testing.  The SS register is as follows:


bit0 = DAC

bit1 = AMP

bit2 = ADC


SPI_DEV_CTL is a macro that is linked to a GPIO that controls the DAC CLR, AMP SHDN, and flash CEN signals.  I've set up several macros for the SPI registers (i.e. SPIDRR) which are volatile entries in my header file:


 * spi.h
#ifndef SPI_H
#define SPI_H

#define SPI_DEV_CTL_DD    (*(volatile unsigned long *)(XPAR_SPI_DEV_CTL_BASEADDR+0x04))
#define SPI_DEV_CTL        (*(volatile unsigned long *)(XPAR_SPI_DEV_CTL_BASEADDR+0x00))
#define disableSPI()        {SPI_DEV_CTL=0x6;}

#define AMP_DOUT_DD    (*(volatile unsigned long *)(XPAR_AMP_DOUT_BASEADDR+0x04))
#define AMP_DOUT        (*(volatile unsigned long *)(XPAR_AMP_DOUT_BASEADDR+0x00))

#define    SPICR        (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x60))
#define    SPISR        (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x64))
#define    SPIDTR    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x68))
#define    SPIDRR    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x6C))
#define    SPISSR    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x70))
#define    SPIGIE    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x1C))
#define    SPIISR    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x20))
#define    SPIIER    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x28))
#define    SPIRXF    (*(volatile unsigned long *)(XPAR_OPB_SPI_0_BASEADDR+0x78))

#define    SPI_DAC    0x01
#define    SPI_AMP    0x02
#define    SPI_ADC    0x04

#define FLASH 0x03

#define DAC_A 0x00
#define DAC_B 0x01
#define DAC_C 0x02
#define DAC_D 0x03
#define DAC_ALL 0x0F

#define    sendDAC(n,val)        writeSPI(SPI_DAC, 0x00300000 | (((n)&0x0F)<<16) | (((val)&0x0FFF)<<4), 4)
#define    sendAmp(a,b)        writeSPI(SPI_AMP, (((b)&0x07)<<4) | ((a)&0x07), 1)

#define  readADC()           readSPI(SPI_ADC, 2)

void initSPI(void);
void clearSPI(void);
int readSPI(unsigned int numBytes);
void writeSPI(unsigned int device, unsigned int value, unsigned int numBytes);



I'm focusing on the CPOL and CPHA values right now, since changing it to a idle-high clock gave me some results.  However, I think I'm just reading what's left on the MISO line after setting the amp; there's no information coming from the ADC.


Any info or code snippets would be great.  Thanks!



7 Replies
Registered: ‎11-27-2010

Re: Using the Spartan 3E Starter Kit ADC with Microblaze

I was sorry to see no one helped with this as I have the same question.  Does anyone have an example of a C++ method to read from the ADC (With a Spartan board w/ microblaze)

0 Kudos
Xilinx Employee
Xilinx Employee
Registered: ‎01-03-2008

Re: Using the Spartan 3E Starter Kit ADC with Microblaze

It is likely that the original question was re-posted and answered in the Embedded Processing forums which would have the right audience to be able to help.

------Have you tried typing your question into Google? If not you should before posting.
Too many results? Try adding
0 Kudos
Registered: ‎11-27-2010

Re: Using the Spartan 3E Starter Kit ADC with Microblaze

Actually I have.  I have searched through every community posting with the key words analog digital | a/d | adc & microblaze.  I have found instances of people asking similar questions, but no examples of helpful solutions or example communications using C/C++.  I did however find plenty of condescending redirects.  

0 Kudos
Registered: ‎02-07-2011

Re: Using the Spartan 3E Starter Kit ADC with Microblaze

i thing that your problem is th gain of the op amp. You should set the gain vector otherwise the opamp return 0.

0 Kudos
Registered: ‎09-29-2011

Spartan 3A Starter Kit ADC Microblaze


I am trying to add an xps_adc ip core to a Microblaze processor,but i have a few questions.

1.)What others peripherals do I need to add?

2.)What do the xps_adc's port signify and how should i connect them?

Thank you.

Tags (1)
0 Kudos
Registered: ‎07-21-2009

Re: Spartan 3A Starter Kit ADC Microblaze



Please start a new thread for this topic, in the Embedded Processing forum.


It is considered bad manners to bring a new and unrelated topic or question into an existing thread.  This practice makes a mess of the discussions, similar to multiple conversations in a small and crowded room.


Thank you for your consideration.


-- Bob Elkind

README for newbies is here:

1. Read the manual or user guide. Have you read the manual? Can you find the manual?
2. Search the forums (and search the web) for similar topics.
3. Do not post the same question on multiple forums.
4. Do not post a new topic or question on someone else's thread, start a new thread!
5. Students: Copying code is not the same as learning to design.
6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).
7. You are not charged extra fees for comments in your code.
8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.
0 Kudos
Registered: ‎04-30-2012

Re: Using the Spartan 3E Starter Kit ADC with Microblaze

Could you post your project ? thank you
0 Kudos