I'm trying to interface with an MCP40821 using SPI from an AVR. Using these pin maps:

#define SCK     PB7
#define MOSI    PB5
#define CS      PB4
#define LDAC    PC7

With these register settings:

void SetupSPI()
    DDRB  |= true << SCK | true << MOSI | true << CS;
    DDRC  |= true << LDAC;
    PORTC |= true << LDAC;
    PORTB |= true << CS;
    SPCR  |= true << SPIE | true << SPE | true << MSTR | true << CPOL | true << CPHA;
    SPSR  |= true << SPI2X;

I'm then transmitting the data using a buffer and an interrupt.

#define SHDN    12
void SendSPIData()
    if (SPIBytesTransferred < SPIPayloadBytes)
        SPDR = SPITxBuffer[SPIBytesTransferred++];
        DACReady = true;

void SetDAC(uint16_t value)
    if (!DACReady) return;
    DACReady = false;
    value |= true << SHDN;

    SPIPayloadBytes = DAC_SPI_BYTES;
    SPIBytesTransferred = 0;
    SPITxBuffer[0] = value >> 8;
    SPITxBuffer[1] = value;

    SendSPIData(); //Kick-off transfer

    SendSPIData(); //Send next byte

This all seems to look fine, using my logic analyser I can see the two byte commands go out successfully.

However, the DAC doesn't seem to respond and I'm not sure what else I need to do.

Logic Analyser

  • \$\begingroup\$ Your chip select is always low... some chips (I haven't checked this one) require an explicit down-going edge on their chip select. I would check that first. \$\endgroup\$
    – vicatcu
    Mar 9, 2020 at 18:52
  • \$\begingroup\$ What response were you expecting? And do you need to pulse LDAC according to the (should be linked in the question) datasheet? \$\endgroup\$ Mar 9, 2020 at 18:58
  • \$\begingroup\$ @BrianDrummond I was expecting the DAC value to change, no response back. Will give pulsing LDAC and CS a try tomorrow, thanks \$\endgroup\$ Mar 9, 2020 at 20:16
  • \$\begingroup\$ What's a "MCP40821"? The only hit I get on Google is this very post. MCP4821? MCP4801? \$\endgroup\$
    – Lundin
    Mar 10, 2020 at 7:40

1 Answer 1


Follow the image below. You need to pulse LDAC and CS needs a falling edge as was stated in the comments.

enter image description here

  • \$\begingroup\$ That sorted it, I thought LDAC was being handled by the peripheral \$\endgroup\$ Mar 10, 2020 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.