Pages: [1]   Go Down
Author Topic: AD5206 Without SPI  (Read 742 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8975
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19350
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote
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.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow! Thanks for your quick and helpful replies! smiley-grin


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 :/

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...
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19350
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.gammon.com.au/spi

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


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

Code:
// 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

Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19350
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: [1]   Go Up
Jump to: