AD7940 with ATmega16M1 [solved: damaged IC]

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guys,

I am wondering if anyone here has experience with the 14-bit Analog Devices AD7940 SPI ADC.

I am trying to get on to work here to no avail. I have it connected to a ATmega16M1 which also has a 16MHz crystal connected.

I am initialising my spi as below, with the SS and SCLK set as outputs and MISO as input.

// Enable SPI, Master Mode 2, set the clock rate fck/16,
    SPCR |= (1<<SPE)|(1<<MSTR)|(1<<CPOL)|(1<<SPR0);

I am using the SCLK provided by the avr at the moment and request the two bytes as follows:

// Activate the CS pin
      clear_bit(AD7940_CS_PORT,AD7940_CS_PIN);

     // Send data
     SPDR = 0xFF;

     // Wait for transmission complete
     while(!(SPSR & (1<<SPIF)));

     // Send data
     SPDR = 0xFF;

      // Wait for transmission complete
      while(!(SPSR & (1<<SPIF)));

      // De-activate the CS pin
      set_bit(AD7940_CS_PORT,AD7940_CS_PIN);

At the minute i am monitoring the SDATA pin with my scope which has a SPI serial bus monitor built in.

There is no data coming back from the ADC.

Could this be due to the gap between the two SPI sends and hence I am not getting 16 consecutive clock pulses going to the AD7940?

Would i be better using a PWM output as my SCLK, or is there away to send 16 consecutive pulses using the onboard SPI SCLK?

Any input or advice would be gratefully appreciated

The datasheet for the part can be found here:
http://www.analog.com/static/imp...

Thanks,
Pat

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Could this be due to the gap between the two SPI sends and hence I am not getting 16 consecutive clock pulses going to the AD7940?


No. While some devices may have a timeout from "start of transaction" to completion, you as the master can have arbitrary times and clock pulse configurations (as long as minimums are met).

Have you tried going slower?

Is Mode 3 correct for the device?

Do you see the clock pulses on the 'scope?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A pass through the datasheet indicates that it is a pretty straightforward part as far as the AVR interface goes. Once >>some<< reading is made, CPOL/CPHA/DORD can be sorted out.

Do you see /CS drop and the SCK pulses >>right at the pin(s) of the device<<?

What supply voltage level and Vin level?

Have you done multiple reads in case the device was in power-down?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Theusch.

Thanks for the reply.

Quote:
Have you tried going slower?

As per the datasheet,which states 250KHz min and 2.5MHz max, my 16MHz / 16 should be inside the range.

Quote:
Is Mode 3 correct for the device?

I believe i have set the SPI to Mode 2, is this not the case (CPOL = 1, CPHA = 0)

Quote:
Do you see the clock pulses on the 'scope?

Yes I see the clock pulses and the SS line going low and returning high after the 16 clock pulses

Thanks,
Pat

Last Edited: Mon. Sep 16, 2013 - 03:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What supply voltage level and Vin level?

5V supply, I have tried Vin set at 1.5V and tried it with 0V (NC)

Quote:
Have you done multiple reads in case the device was in power-down?

I tried 1 read every 1 msec with no joy. I will try slow it down and see then.

I tried it at at 250msec between reading, but still no reply from the ADC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Gee, I hate asking questions like this: is the a/d data line going to MISO? We might as well look at your code that reads the data back after ea byte of FF is sent. seems like there should be a datahi=SPDR; after the SPIF timeout?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The SDATA line is connected to the MISO on the uC (PB0, Pin 8 )

I am currently probing the pin with my scope, i still have to add in the uint16_t to store the returned value in my software but i don't think that is an issue.

As per the data sheet, once the CS line goes low and there are clock pulses, data should be present on the SDATA line which I do not have at the minute.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to get into the habit of making a schematic, for yourself and others that you could post it for. As it is, check that everything is correctly connected. You need mode 1 from pg. 16, and mode 3 MIGHT work, and your spi_read() is wrong. You must store the MISO data, which is in SPDR, in a variable or it'll get overwrote.

Are you using the SS pin of the MCU or another pin ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

indiana--

I do not disagree with your points. However, they don't really apply to the OP's symptoms. Remember that he is reporting that with a 'scope /CS is dropping/rising appropriately at the device pin. Also, SCK pulses are seen at the device pin. As a sanity check, that implies that /SS is indeed an output (or isn't floating high). It implies that the read routine is sufficient for this sanity check as the SCK pulses are seen.

So I can't tell why no MISO pulses are seen. It would make sense with a 0V input to the ADC. But not with a real voltage applied.

If the slight pause between bytes is indeed the problem, then this is an awfully touchy device. Two ways around that I can think of: Bit-bang as a sanity check; or USART-as-SPI-master.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My intent with the SS was only to make sure which pin was actually tied to the adc. ALOT of people will yes make SS an output...but then use some other pin to actually work the slave's /CS. I was just making sure the slave's /CS was connected. If something other than the SS, OP may have forgotten to make that connect. Also, OP should try mode 1, I believe that's the main issue...and 2X check all connects, esp. power pin for the ADC ( it could happen... ).

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I was just making sure the slave's /CS was connected.

Quote:

the SS line going low and returning high after the 16 clock pulses

So, that was already addressed. (I am assuming that OP is checking right at the device pin, as I asked.)

Quote:

Also, OP should try mode 1, I believe that's the main issue..

Regardless of CPOL/CPHA/DORD, OP should see some bits coming back. (Especially on the 'scope trace.)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Regardless of CPOL/CPHA/DORD, OP should see some bits coming back. (Especially on the 'scope trace.)
Oh, I always thought mode had to be set correctly for a slave to get started...good to know !

Edit: I missed this:

Quote:
...i still have to add in the uint16_t to store the returned value in my software but i don't think that is an issue.
I'm sorry about the spi_rd() remark, OP.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Oh, I always thought mode had to be set correctly for a slave to get started...good to know !


Well, think about it. The device is "send only", so all it sees is SCK and /CS.

How could it ever know whether your master is set for DORD==0 or DORD==1? the same for the other parameters....

... with an asterisk. It >>could<< be important for the slave if the SCK "idles high" (as indicated in the datasheet for this device), or "idles low". So the CPOL==1 (mode 2) looks appropriate.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guys,

Thanks for the all the replys.
Turns out the component was damaged.

Replaced it and is now working fine, very accurate. Nice piece of kit.

Thanks again,
Pat