1 Reply Latest reply on Sep 28, 2019 11:18 PM by ShipingW_81

    about  PSoC6  SPI

    JeHa_3912621

      外部中断里调用AFE4900_Reg_Read程序无法正常运行。在准循环里面调用没有问题。

       

      static uint32_t AFE4900_Reg_Read( unsigned char mRegAddr )

      {

          uint32_t masterStatus;

          uint32_t timeOut = 1000UL;

          union VarU32 uAFE4900;

           

          txBuffer[0] = mRegAddr;

          txBuffer[1] = 0;

          txBuffer[2] = 0;

          txBuffer[3] = 0;

         

          /*Write packet to read status */

          Cy_SCB_SPI_WriteArrayBlocking(mSPI_HW, txBuffer, 4 );

         

          do

          {

              masterStatus  = Cy_SCB_SPI_GetSlaveMasterStatus(mSPI_HW);

              //Cy_SysLib_Delay(CY_SCB_WAIT_1_UNIT);

              timeOut--;

             

          }while ( (masterStatus != (CY_SCB_SPI_MASTER_DONE)) && (timeOut > 0UL) );

         

          /* If masterStatus is CY_SCB_SPI_MASTER_DONE check number of bytes in Rx FIFO and set the status. */

          if(masterStatus == CY_SCB_SPI_MASTER_DONE)

          {

              if( 4 == Cy_SCB_SPI_GetNumInRxFifo(mSPI_HW) )

              {

                  Cy_SCB_SPI_ReadArray( mSPI_HW, rxBuffer, 4 );

                  uAFE4900.mU8[3] = 0;

                  uAFE4900.mU8[2] = rxBuffer[1];

                  uAFE4900.mU8[1] = rxBuffer[2];

                  uAFE4900.mU8[0] = rxBuffer[3];

              }

          }

          else

          {

              handle_error();

          }

         

          /* CLear Master status and Tx FIFO status. */

          Cy_SCB_SPI_ClearSlaveMasterStatus(mSPI_HW, Cy_SCB_SPI_GetSlaveMasterStatus(mSPI_HW));

          Cy_SCB_SPI_ClearTxFifoStatus(mSPI_HW, CY_SCB_SPI_TX_INTR_MASK );

          Cy_SCB_SPI_ClearTxFifo(mSPI_HW);

         

           /* Clear Rx FIFO status. */

          Cy_SCB_SPI_ClearRxFifoStatus(mSPI_HW, CY_SCB_SPI_RX_INTR_MASK);

          Cy_SCB_SPI_ClearRxFifo(mSPI_HW);

         

          return uAFE4900.mU32;    

      }

       

      void Isr_switch(void)

      {

          union VarU32 uData;

          /* Clears the triggered pin interrupt */

      Cy_GPIO_ClearInterrupt( KIT_BTN1_PORT, KIT_BTN1_NUM );

      NVIC_ClearPendingIRQ( SysInt_Switch_cfg.intrSrc );

       

       

          /* Toggle the LED */

          Cy_GPIO_Inv( GPIO_PRT13, 7u );   

          sSys.uIR  = AFE4900_Reg_Read( 42 );

          //sSys.uAmbinet = AFE4900_Reg_Read( 42 );

          //sSys.uRed = AFE4900_Reg_Read( 44 );

          sSys.uIR = samptrans( sSys.uIR );

          sSys.uAmbinet = samptrans( sSys.uAmbinet );

          sSys.uRed = samptrans( sSys.uRed );

          Queue_Push(  sMsg8.pFile, 0x55 );

          Queue_Push(  sMsg8.pFile, 0xAA );

         

          //Queue_Push(  sMsg8.pFile, CountData++ );

          //uData.mU32 = sSys.uIR;  

          //Queue_Push(  sMsg8.pFile, uData.mU8[2] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[1] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[0] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[3] );

         

          //uData.mU32 = sSys.uAmbinet;  

          //Queue_Push(  sMsg8.pFile, uData.mU8[2] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[1] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[0] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[3] );

         

          //uData.mU32 = sSys.uRed;  

          //Queue_Push(  sMsg8.pFile, uData.mU8[2] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[1] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[0] );

          //Queue_Push(  sMsg8.pFile, uData.mU8[3] );   

      }