AD5206 Without SPI

Hi!

I have a small problem with the current project I'm working on...
On the PCB I made,The AD5206's CS-pin happened to be connected to the MISO-pin on the ATMega.
I didn't think this would be a problem, but it seems the SPI-lib is using that pin somehow.

Is there any way I can modify the SPI-code to prevent it from touching the MISO-pin? It seems like it's using interrupts, which is almost greek to me...
I've been attempting to white a new lib that doesnt use interrupts, but I'm finding it hard to read the timing diagram for the IC.

Of course, the alternative would to make a new PCB.. But I've already painstakingly soldered hundreds of components to it...

If you are using the SPI hardware you will have to use the SPI hardware pins: SCLK, MOSI, MISO and there are restrictions on what you can do with the SS pin. Time to cut the trace on your board and move the CS/SS signal to some other pin.

There is no way to use the SPI library for hardware SPI and not use the SPI pins.

The SPI library has MISO as input. That shouldn't affect you too much. If you want it as an output you are out of luck. According to the datasheet, page 168:

When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to Table 18-1 on page 168. For more details on automatic port overrides, refer to ”Alternate Port Functions” on page 80.

If forces MISO to be an input. This is nothing to do with interrupts.

Wow! Thanks for your quick and helpful replies! :smiley:

Is there any way to control the AD5206 without using SPI?
I'm quite a decent programmer, but the timing diagrams gives me a headache :confused:

It looks quite easy to just zero the CS and send the 11 bits needed, but I can't figure out how the CLK-pin is supposed to be controlled...

You have a couple of options. First the USART can be set up as an SPI master. See:

Scroll down to "SPI from the USART ... an alternative".

Or, you can bit-bang it. For example in my chip programmer:

// bit banged SPI pins
const byte MSPIM_SCK = 4;  // port D bit 4
const byte MSPIM_SS  = 5;  // port D bit 5
const byte BB_MISO   = 6;  // port D bit 6
const byte BB_MOSI   = 7;  // port D bit 7

// for fast port access (Atmega328)
#define BB_MISO_PORT PIND
#define BB_MOSI_PORT PORTD
#define BB_SCK_PORT PORTD

const byte BB_SCK_BIT = 4;
const byte BB_MISO_BIT = 6;
const byte BB_MOSI_BIT = 7;

// control speed of programming
const byte BB_DELAY_MICROSECONDS = 4;

...

// Bit Banged SPI transfer
byte BB_SPITransfer (byte c)
{       
  byte bit;
   
  for (bit = 0; bit < 8; bit++) 
    {
    // write MOSI on falling edge of previous clock
    if (c & 0x80)
        BB_MOSI_PORT |= _BV (BB_MOSI_BIT);
    else
        BB_MOSI_PORT &= ~_BV (BB_MOSI_BIT);
    c <<= 1;
 
    // read MISO
    c |= (BB_MISO_PORT & _BV (BB_MISO_BIT)) != 0;
 
   // clock high
    BB_SCK_PORT |= _BV (BB_SCK_BIT);
 
    // delay between rise and fall of clock
    delayMicroseconds (BB_DELAY_MICROSECONDS);
 
    // clock low
    BB_SCK_PORT &= ~_BV (BB_SCK_BIT);
    }
   
  return c;
  }  // end of BB_SPITransfer

Is there any way I can modify the SPI-code to prevent it from touching the MISO-pin?

Very easy. Two options:

  1. cook your own hardware spi: turn miso as output and code it as the cs pin;
  2. use software spi: code it whatever you want.

Either can be done in minutes.

dhenry:

  1. cook your own hardware spi: turn miso as output and code it as the cs pin;

What do you mean by that? You can't "cook" your own hardware. It comes pre-made.