cancel
Showing results for 
Search instead for 
Did you mean: 

SPI makes stupid things

mof182
Associate II

I'm new with the STM32F767ZI (Nucleo board) and tried to write a SPI driver with DMA access.

It works so far, but I have some stupid things on my log, I can't interprete. Is anybody there, who knows what there is going wrong?

I'd like to send three bytes and everythings works fine so far, but after the last byte the software/hardware added a additional signal on the MISO line.

0693W000001rSE1QAM.png

My SPI configuration:

      SPIConfig.Interface = CSPI_1;

      SPIConfig.u32PortPinSCK = CONFIG_SPI_SCK;

      SPIConfig.u32PortPinMOSI = CONFIG_SPI_MOSI;

      SPIConfig.u32PortPinMISO = CONFIG_SPI_MISO;

      SPIConfig.u32PortPinNSS = CONFIG_SPI_NSS;

      SPIConfig.bMasterMode = true;

      SPIConfig.bNSSSoft = true;

      SPIConfig.bCPHA_1 = false;

      SPIConfig.bCPOL_1 = false;

      SPIConfig.u8ResponseBytesToIgnore = 1;

      SPIConfig.pvDestLeadingBytes = &m_Param.u8Status;

      if(m_SPI.Init(SPIConfig, GLOBALS_INITMODE_STD)

(.......)

uint32_t CSpi::InitSPI(bool_t bCPHA_1, bool_t bCPOL_1) /* Called by CSpi::Init() */

{

/* Variable declarations */

   uint32_t u32RetVal;

/* End - Variable declarations */

/* Variable initialisations */

   u32RetVal = __SAFETY_NO_ERROR__;

/* End - Variable initialisations */

/* Start user code here */

/* Enable the peripheral clock of SPIx */

   if(m_Param.pSPIx == SPI1)

   {

      LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);

   }

   else if(m_Param.pSPIx == SPI2)

   {

      LL_APB2_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);

   }

   else if(m_Param.pSPIx == SPI3)

   {

      LL_APB2_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3);

   }

   else if(m_Param.pSPIx == SPI4)

   {

      LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI4);

   }

   else if(m_Param.pSPIx == SPI5)

   {

      LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI5);

   }

   else if(m_Param.pSPIx == SPI6)

   {

      LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI6);

   }

   else

   {

      u32RetVal = SAFETYERROR(__CSPI_FCT_INIT_SPI__,__CSPI_INDEX_INTERFACE__);

   }

   if(u32RetVal == __SAFETY_NO_ERROR__)

   {

      LL_SPI_SetBaudRatePrescaler(m_Param.pSPIx, LL_SPI_BAUDRATEPRESCALER_DIV32);

      LL_SPI_SetBaudRatePrescaler(m_Param.pSPIx, LL_SPI_BAUDRATEPRESCALER_DIV256);

      LL_SPI_SetTransferDirection(m_Param.pSPIx,LL_SPI_FULL_DUPLEX);

      if(bCPHA_1 == false)

      {

         LL_SPI_SetClockPhase(m_Param.pSPIx, LL_SPI_PHASE_1EDGE);         /* CPHA = 0 */

      }

      else

      {

         LL_SPI_SetClockPhase(m_Param.pSPIx, LL_SPI_PHASE_2EDGE);         /* CPHA = 1 */

      }

      if(bCPOL_1 == false)

      {

         LL_SPI_SetClockPolarity(m_Param.pSPIx, LL_SPI_POLARITY_LOW);      /* CPOL = 0 */

      }

      else

      {

         LL_SPI_SetClockPolarity(m_Param.pSPIx, LL_SPI_POLARITY_HIGH);      /* CPOL = 1 */

      }

      LL_SPI_SetTransferBitOrder(m_Param.pSPIx, LL_SPI_MSB_FIRST);

      LL_SPI_SetDataWidth(m_Param.pSPIx, LL_SPI_DATAWIDTH_8BIT);

      if((m_Param.u16PortPinNSS != 0U)&&(m_Param.u16PortNSS != 0U))

      {

         if(m_Param.bMasterMode == false)

         {

            LL_SPI_SetNSSMode(m_Param.pSPIx, LL_SPI_NSS_HARD_INPUT);

         }

         else

         {

            if(m_Param.bNSSSoft == false)

            {

               LL_SPI_SetNSSMode(m_Param.pSPIx, LL_SPI_NSS_HARD_OUTPUT);

            }

            else

            {

               LL_SPI_SetNSSMode(m_Param.pSPIx, LL_SPI_NSS_SOFT);

            }

         }

         LL_SPI_DisableNSSPulseMgt(m_Param.pSPIx);

      }

      LL_SPI_SetRxFIFOThreshold(m_Param.pSPIx, LL_SPI_RX_FIFO_TH_QUARTER);

      if(m_Param.bMasterMode == true)

      {

         LL_SPI_SetMode(m_Param.pSPIx, LL_SPI_MODE_MASTER);

      }

      else

      {

         LL_SPI_SetMode(m_Param.pSPIx, LL_SPI_MODE_SLAVE);

      }

/* Configure SPI1 DMA transfer interrupts */

/* Enable DMA RX Interrupt */

      LL_SPI_EnableDMAReq_RX(m_Param.pSPIx);

/* Enable DMA TX Interrupt */

      LL_SPI_EnableDMAReq_TX(m_Param.pSPIx);

   }

/* End user code */

/* Return section */

   SAFETY_RETURN(u32RetVal);

/* End return section */

}

Thanks for your help!

Michael

3 REPLIES 3

> I have some stupid things on my log

What stupid things? What log?

Changes in MOSI don't matter as long as there are no clocks. If you disable SPI after transfer it threestates it's pins, so if you want to avoid that, don't disable SPI.

Using any "library" in your code is your responsibility, so get a full understanding of what they do, or simply don't use them.

JW

mof182
Associate II

Hi JW,

thanks for your reply.

I will test, not to disable the SPI after tranfer. We will see, what happens.

My problem is, that I don't know, if the connected device will react to this signal on the MISO line.

Michael

TDK
Guru

> My problem is, that I don't know, if the connected device will react to this signal on the MISO line.

There is nothing invalid about the signal you're showing. The device only registers a bit on MOSI on the rising edge of SCK.

 I realize the pulse is not needed, but it's not hurting anything. This question has come up from time to time.

If you feel a post has answered your question, please click "Accept as Solution".