Arduino SPI时钟相位与所有4种模式的数据同步,怎么了?

问题描述 投票:0回答:1

我正在尝试从Arduino(Mega 2560)驱动LTC1664 DAC。当DAC数据表指示定相时,对于所有4种模式,从Arduino输出的SPI数据和时钟始终保持同步(上升和下降)。

我已经尝试了所有模式,写入期间芯片上的SS线被拉低(应该如此

),并且我尝试了不同的速度和shiftOut(),setClockDivider(),setDataMode (),beginTransaction()和endTransaction()

这是Arduino SPI中的错误,是Mega 2560的特定错误,我应该尝试Uno还是Due? 请帮助!

o形迹线下方的代码。

BTW:我要发送的16位字是0x3600(o-scope跟踪被截断

)。

"MODE1""MODE0"

/*
  Test DAC Control

  created 18 Mar 2020 (Covid-19, oppsies)
  by Danny Holstein

*/


// inslude the SPI library:
#include <SPI.h>

void DAC(unsigned short value, unsigned char channel, int SS_Pin, int model);
enum models{LTC1664};
enum models model;

// set pin 10 as the slave select for the digital pot:
const int DAC_SS_Pin = 22;

void setup() {
  // set the DAC_SS_Pin as an output:
  // initialize SPI:
  Serial.begin(115200);
  SPI.begin();
  Serial.println("SPI.begin");
  pinMode(DAC_SS_Pin, OUTPUT);

}

void loop() {
  // go through the six channels of the digital pot:
    for (int channel = 1; channel < 6; channel++) {
        delay(500);
        DAC(128*channel, channel, DAC_SS_Pin, LTC1664);
    }
    delay(1000);
 Serial.println("new loop");
}

/*
  DAC Control

  This function controls an LTC1664 Micropower Quad 10-Bit DAC.

 The LTC1664 is SPI-controlled,and to command it, you send one 16 bit word,
  A3 A2 A1 A0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 X1 X0
  |  ADDR   |         INPUT CODE           | DON'T CARE

 The circuit:
  * CS - to digital pin 22  (SS pin)
  * SDI - to digital pin 51 (MOSI pin)
  * SDO - to digital pin 50 (MISO pin, not used in this function)
  * CLK - to digital pin 52 (SCK pin)

 created 18 Mar 2020 (Covid-19, oppsies)
 by Danny Holstein

*/

void DAC(unsigned short value, unsigned char channel, int SS_Pin, int model) {
  // take the SS pin low to select the chip:
    digitalWrite(SS_Pin, LOW); delay(100);
    unsigned short buf, b16;
    unsigned char *c, b; c = (unsigned char *) &buf;
    switch (model)
    {
        case LTC1664:
            if (channel > 4) channel = 0xF;
            buf = (channel << 12) | ((value & 0x3FF) << 2);
            SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
            b16 = SPI.transfer16(buf);
            Serial.print("0x" + String(buf, HEX)); Serial.println("\t0x" + String(b16, HEX) + "\t");
            SPI.endTransaction();
            break;
        default:
            break;
    }   
    delay(100);
  // take the SS pin high to de-select the chip:
    digitalWrite(SS_Pin, HIGH);
    // printf("value = 0x%04x", buf);
}

我正在尝试从Arduino(Mega 2560)驱动LTC1664 DAC。当DAC数据表指示...

arduino spi
1个回答
0
投票
时,对于所有4种模式,从Arduino发出的SPI数据和时钟始终保持同步(上升和下降)。

事实证明它与Arduino SPI功能或定相问题无关,LTC1664具有一个CLR引脚,我已将其连接到GPIO,但未能命令HIGH,它一直悬空并禁止芯片,命令HIGH和现在一切都很好。

© www.soinside.com 2019 - 2024. All rights reserved.