0
\$\begingroup\$

I'm trying to interface MCP4728 with STM32F0. The commands are transmitted by controller and same are received successfully by DAC MCP4728. I2C transmit function also returns HAL_OK on I2C transmission. But, the corresponding channel is not getting activated with the count I've entered. Also, I've tied the LDAC pin of DAC permanently to low so that output gets updated continuously.

Can anyone help me with this issue? I need to get output on DAC on count sent by microcontroller.

EDIT 1: I've done the coding according to the the commands given in datasheet. These functions successfully return HAL_OK. Also, I've found the binary equivalent of the commands form datasheet and verified the same on DSO.

EDIT 2: This the the waveform captured. Exactly the data sent in below functions. Blue is clock pulse, yellow is data. enter image description here

Note: I've used a union for sending data as my max data size is 12 bits but I2C commands of STM32 allows only 8bits to transmit.

Is there any method or step I'm missing due to which I'm not getting output?

EDIT 3: Whatever i send in command, only 9 bits are transferred. 8 bits of slave address and 1 acknowledge bit. Further data is not being passed. Is there any mistake in I2C?

void SelectVref(uint8_t Channel,DACChannel* AnalogChannel,uint8_t Vref)
{
    uint8_t ret1;
    uint8_t TxFrame[10];
    AnalogChannel[Channel].VRef=Vref;
    TxFrame[0]=(DAC_mcp4728_VREFWRITE)|((AnalogChannel[0].VRef)<<3)|((AnalogChannel[1].VRef)<<2)|
                            ((AnalogChannel[2].VRef)<<1)|(AnalogChannel[3].VRef);
    //ret = HAL_I2C_Master_Transmit(&hi2c2,DAC_mcp4728_ID,TxFrame,1,10);
    ret1 = HAL_I2C_Master_Transmit_DMA(&hi2c2,DAC_mcp4728_ID,TxFrame,sizeof(TxFrame));
}

void SelectGain(uint8_t Channel,DACChannel* AnalogChannel,uint8_t Gain)
{
    uint8_t ret2;
    uint8_t TxFrame[10];
    AnalogChannel[Channel].Gain=Gain;
    TxFrame[0]=(DAC_mcp4728_GAINWRITE)|((AnalogChannel[0].Gain)<<3)|((AnalogChannel[1].Gain)<<2)|
                            ((AnalogChannel[2].Gain)<<1)|(AnalogChannel[3].Gain);
    //ret = HAL_I2C_Master_Transmit(&hi2c2,DAC_mcp4728_ID,TxFrame,1,10);
    ret2 = HAL_I2C_Master_Transmit_DMA(&hi2c2,DAC_mcp4728_ID,TxFrame,sizeof(TxFrame));
}

void WriteAnalogVal(uint8_t Channel,DACChannel* AnalogChannel,uint16_t AnalogCount)
{
    uint8_t ret3;
    uint8_t TxFrame[10];
    AnalogChannel[Channel].AnalogCount.AnalogCntIn16=AnalogCount;
    
    TxFrame[0]=AnalogChannel[0].AnalogCount.AnalogCntIn8[HI];
    TxFrame[1]=AnalogChannel[0].AnalogCount.AnalogCntIn8[LO];
    TxFrame[2]=AnalogChannel[1].AnalogCount.AnalogCntIn8[HI];
    TxFrame[3]=AnalogChannel[1].AnalogCount.AnalogCntIn8[LO];
    TxFrame[4]=AnalogChannel[2].AnalogCount.AnalogCntIn8[HI];
    TxFrame[5]=AnalogChannel[2].AnalogCount.AnalogCntIn8[LO];
    TxFrame[6]=AnalogChannel[3].AnalogCount.AnalogCntIn8[HI];
    TxFrame[7]=AnalogChannel[3].AnalogCount.AnalogCntIn8[LO];
    
    
    //ret = HAL_I2C_Master_Transmit(&hi2c2,DAC_mcp4728_ID,TxFrame,8,100);
    ret3 = HAL_I2C_Master_Transmit_DMA(&hi2c2,DAC_mcp4728_ID,TxFrame,sizeof(TxFrame));
    
}![enter image description here](https://i.sstatic.net/s3vON.jpg)
\$\endgroup\$
11
  • \$\begingroup\$ Hrishikesh Dixit - Hi, What troubleshooting have you done? What test equipment do you have? Which parts of your project are "believed good" (e.g. tested in earlier prototypes etc.) and which parts are "new and untested"? For example, I would look at the I2C bus (preferably with an oscilloscope to look at the "analog quality", but a logic analyser would give some clues). Then you can analyse what you capture there, to help guide you whether the problem is with the STM32 code and what it sends to the DAC, or elsewhere. Please edit the question to add those details to your question. Thanks. \$\endgroup\$
    – SamGibson
    Jan 18, 2021 at 15:52
  • \$\begingroup\$ @SamGibson, Sir, I've updated code and some more info. Do let me know if any more data required. Thanks. \$\endgroup\$
    – Fatpanda
    Jan 18, 2021 at 16:16
  • \$\begingroup\$ As with any embedded project, the code is only a means to drive the hardware. What is showing up on the SCL/SDA lines? I'd start there. Understanding what your code is actually putting on the line will tell you whether the DAC behavior is expected or aberrant. \$\endgroup\$
    – M D
    Jan 18, 2021 at 16:27
  • \$\begingroup\$ @MD SCL and SCL shows exactly what is expected. I can share snaps in a short while. \$\endgroup\$
    – Fatpanda
    Jan 18, 2021 at 16:31
  • 1
    \$\begingroup\$ The commands [...] are received successfully by DAC MCP4728 - I highly doubt that, and you don't know that either. HAL_OK only tells you that the CPU thinks the transmission worked. It says nothing at all about whether the DAC received it or accepted it! SCL and [SDA] shows exactly what is expected. You'll get those correct and HAL_OK with nothing but pull-up resistors connected to the I2C pins on the ST32F0! The DAC can be absent for all I know, you'll get same results on the MCU side of things. \$\endgroup\$ Jan 18, 2021 at 20:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.