This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DAC81416: DAC 81416 coding problem- sclk and cs

Part Number: DAC81416
Other Parts Discussed in Thread: DAC61416

Hi i am trying to interface between teensy and dac81416. my spi code:

_spi_settings = SPISettings(spi_clock_hz, MSBFIRST, SPI_MODE0);

    pinMode(cs_pin, OUTPUT);
    //digitalWrite(_rst_pin, HIGH);

    _spi->begin();
}

inline void DAC61416::cs_on() {
    digitalWrite(cs_pin, LOW);
}

inline void DAC61416::cs_off() {
    digitalWrite(cs_pin, HIGH);
}

int DAC61416::init() {
    // soft-reset , por is initiated
 write_reg(R_TRIGGER, (0x001A));
   

    // set SPICONFIG: DEV_PWDN=0, FSDO=1
   uint16_t def = TEMPALM_EN(1) | DACBUSY_EN(0) | CRCALM_EN(1) | DEV_PWDWN(0) | CRC_EN(0) | SDO_EN(1) | FSDO(1) | (0x2 << 6);
    write_reg(R_SPICONFIG, def);

  // write_reg(R_SPICONFIG, 0x0A84);
   
    // reading SPICONFIG back
    return (read_reg(R_SPICONFIG) == def ? 0 : -1);

}

void DAC61416::write_reg(uint8_t reg, uint16_t wdata) {
    uint8_t lsb = ((uint16_t)wdata >> 0) & 0xFF;
    uint8_t msb = ((uint16_t)wdata >> 8) & 0xFF;

    _spi->beginTransaction(_spi_settings);
   cs_on();
    delayMicroseconds(1);
    _spi->transfer(reg);
    _spi->transfer(msb);
    _spi->transfer(lsb);
    tcsh_delay();
    cs_off();
    _spi->endTransaction();
}
//the steps necessary to write to the DAC:
//written a dac_write function that uses 3 8-bit SPI writes to write the 8-bit address,
//and splits the 16-bit data into a 8-bit msb and 8-bit lsb.
 
uint16_t DAC61416::read_reg(uint8_t reg) {
   uint8_t buf[3]; // 15-0

    _spi->beginTransaction(_spi_settings);
    cs_on();
    _spi->transfer( (RREG | reg) );
    _spi->transfer(0xff);
    _spi->transfer(0xff);
    tcsh_delay();
    cs_off();

    cs_on();
    buf[0] = _spi->transfer(0x00);
    buf[1] = _spi->transfer(0x00);
    buf[2] = _spi->transfer(0x00);
    tcsh_delay();
    cs_off();
   
    _spi->endTransaction();

    // check buf[0]

    uint16_t res = ((buf[1] << 8) | buf[2]);
    return (res);
i am trying to give SCLK three 8 bits as its 24 bit frame, is this correct ?
and also the CS is not at all going low. but i have coded right.(figure 1) 
Is this something that has to do with the spi clock hertz ? because when i change it i can see spikes in the chip select pin(figure2)
can you please tell me how much hertz should i give to it ?