Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By snapdan
#16406 I'm using an LTC1257 DAC with a 10v reference. On a Moteuino (Uno) the following code takes in values from 0000-4095 and I see a voltage 0-10v:

Code: Select all#include <SPI.h>

char inbyte[5];
uint16_t bright;
const int DAC_CSN = 2;
byte MSB;
byte LSB;

void setup (){
    Serial.begin(115200);
    delay(10);
    Serial.println("Setup start");
    pinMode(DAC_CSN, OUTPUT);
    digitalWrite(DAC_CSN,HIGH);
    SPI.begin();
    SPI.setBitOrder(MSBFIRST);

    // Moteuino
    // SPI.setClockDivider(SPI_CLOCK_DIV32);

    // ESP8266
    SPI.setClockDivider(SPI_CLOCK_DIV16);

    SPI.setDataMode(SPI_MODE0);
}

void loop(){
    if (Serial.available() > 3) {
        inbyte[0] = Serial.read();
        inbyte[1] = Serial.read();
        inbyte[2] = Serial.read();
        inbyte[3] = Serial.read();
        inbyte[4] = '\0';
        bright = atoi(inbyte);
        Serial.print("Received: ");
        Serial.println(bright);
        MSB = highByte (bright);
        LSB = lowByte (bright);
        digitalWrite(DAC_CSN,LOW);
        SPI.transfer(MSB);
        SPI.transfer(LSB);
        digitalWrite(DAC_CSN,HIGH);
    }
}


But using this with the ESP8266 the output values aren't consistent. 1023 gives ~5v, as does 2047. Then 2048 gives 0. 4095 gives ~10, then if I go back to 2047 it gives ~10 instead of 5! Do I need to do something different with the bit shifting and transfer?

I thought it might have to do with SPI.setDataMode being currently unimplemented but the ESP8266 is cpol=0, cpha=0 by default, no?