1
\$\begingroup\$

I am using DAC60508 with my STM32F7, 60508 is 12 bits precision, and with 24 bits command-length, SPI interface. After initialize the SPI, I send 3 bytes separately, and I use a oscilloscope to check the wave of SCL, SDI, CS, it seems right, but I can’t detect any output votage. This SPI2 code demonstrated working with another thermal chip.

        static void MX_SPI2_Init(void)
         {
          LL_SPI_InitTypeDef SPI_InitStruct;

          LL_GPIO_InitTypeDef GPIO_InitStruct;

          /* Peripheral clock enable */
          LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);

          /**SPI2 GPIO Configuration  
          PC2   ------> SPI2_MISO
          PC3   ------> SPI2_MOSI
          PB10   ------> SPI2_SCK 
          */
          GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
          GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
          GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
          GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
          GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
          GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
          LL_GPIO_Init(GPIOC, &GPIO_InitStruct);

          GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
          GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
          GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
          GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
          GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
          GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
          LL_GPIO_Init(GPIOC, &GPIO_InitStruct);

          GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
          GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
          GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
          GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
          GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
          GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
          LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

          /* SPI2 parameter configuration*/
          SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
          SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
          SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
          SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
          SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
          SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
          SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV256;
          SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
          SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
          SPI_InitStruct.CRCPoly = 7;
          LL_SPI_Init(SPI2, &SPI_InitStruct);

        //  LL_SPI_SetStandard(SPI2, LL_SPI_PROTOCOL_MOTOROLA);

        //  LL_SPI_EnableNSSPulseMgt(SPI2);

        }

        LL_SPI_SetRxFIFOThreshold(SPI2, LL_SPI_RX_FIFO_TH_QUARTER );   
         while(1)
         {  
              LL_GPIO_ResetOutputPin(SPI2_NSS_GPIO_Port,SPI2_NSS_Pin); //CS
             SPI_SendByte(0x08);    //Output 0 Address       
             SPI_SendByte(0xff);    //Data MSB 8 bits
             SPI_SendByte(0xf0);    //Data LSB 4 bits
             delay_us(120);            
             LL_GPIO_SetOutputPin(SPI2_NSS_GPIO_Port,SPI2_NSS_Pin);  // CS
             delay_ms(50);
         }

        unsigned char SPI_SendByte(unsigned char byte)
        {
            while(LL_SPI_IsActiveFlag_TXE(SPI2)==RESET);
          LL_SPI_TransmitData8(SPI2,byte);

        //  while(! (LL_SPI_IsActiveFlag_RXNE(SPI2)));
        //  return LL_SPI_ReceiveData8(SPI2);
        }

enter image description here enter image description here DAC60508 Datasheet

\$\endgroup\$
6
  • \$\begingroup\$ I have an idea - If you are sure the command is correct, try sending first byte high (0xFF) and check if the SPI mode you are using corresponds to the timing diagram that can be found on page 29 of the datasheet. See if data is already there on falling edge of the clock. For (0x08) your first 4 bits are 0 and you cannot check it that well. Although it does seem correct. \$\endgroup\$ Commented Mar 25, 2019 at 8:34
  • \$\begingroup\$ Thank you Atizs. I tried the writing first byte oxff, it seems corresponding with the timing diagram from page 29, I cant find anywhere which is different. you can see the 2nd picture, data is right in each falling edge. \$\endgroup\$
    – Ye Shiwei
    Commented Mar 25, 2019 at 9:19
  • \$\begingroup\$ With SPI, always suspect clock settings before anything else. Clock polarity seems correct but what about clock phase? Why LL_SPI_PHASE_2EDGE and not LL_SPI_PHASE_1EDGE ? \$\endgroup\$
    – Lundin
    Commented Mar 25, 2019 at 9:55
  • \$\begingroup\$ @Lundin The phase seems correct as well. Since CKPOL = 0 (i.e. clock is low on idle), 1EDGE means that the data will be sampled on the rising edge (first transition) and 2EDGE means that the data will be sampled on the falling edge (second transition). Just as shown in the datasheet p.29. \$\endgroup\$ Commented Mar 25, 2019 at 10:11
  • \$\begingroup\$ @Rohat Kılıç, Thank you Rohat,you are right \$\endgroup\$
    – Ye Shiwei
    Commented Mar 26, 2019 at 0:42

1 Answer 1

1
\$\begingroup\$

Thank you for all your reply,I have sovled this question. The communication is right,the problem is that i didnt initialize all register,when i do this,the problem disappears.But I just initialize all registers for default value except one, because that one does not has a defalut value,it writes 0x---.So the reason maybe from this register. BR.

\$\endgroup\$

Your Answer

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

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