cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 6

MiKi_3184011
New Contributor II

I don't know why this is frustrating me so much but i'm ridiculously new to PSoC and SPI.  This function works on a previous generation of PSoC i played with but now i would like to use it with the PSoC 6 API.  Any help translating would be appreciated since it seems to be too much for me today......lol

unsigned char SPI_Read(unsigned char* data,

                       unsigned char bytesNumber)

{

    while(~SPIM_ADC_ReadTxStatus() & SPIM_ADC_STS_SPI_DONE){CyDelayUs(2);}

    SPIM_ADC_ClearRxBuffer();

    for (int i = 0; i < bytesNumber; i++){

        SPIM_ADC_WriteTxData(0x00);

    }

    while(~SPIM_ADC_ReadTxStatus() & SPIM_ADC_STS_SPI_DONE){CyDelayUs(2);}

    if(SPIM_ADC_GetRxBufferSize()){

        for (int i = 0; i < bytesNumber; i++){

            data = SPIM_ADC_ReadRxData();

        }

    }

    return bytesNumber;

}

0 Likes
1 Solution
MiKi_3184011
New Contributor II

This works.  Any recommendations on optimization or preffered options sincerely appreciated.

unsigned char SPI_Read(unsigned char* data, unsigned char bytesNumber)

{

Cy_SysLib_DelayUs(20);

    while(~Cy_SCB_SPI_GetTxFifoStatus(KIT_SPI_HW) & Cy_SCB_SPI_IsTxComplete(KIT_SPI_HW)){Cy_SysLib_DelayUs(2);}

    Cy_SCB_SPI_ClearRxFifo(KIT_SPI_HW);

    for (int i = 0; i < bytesNumber; i++){

    Cy_SCB_SPI_Write(KIT_SPI_HW, 0x00);

    }

    Cy_SysLib_DelayUs(20);

    while(~Cy_SCB_SPI_GetTxFifoStatus(KIT_SPI_HW) & Cy_SCB_SPI_IsTxComplete(KIT_SPI_HW)){Cy_SysLib_DelayUs(2);}

    if(Cy_SCB_SPI_GetNumInRxFifo(KIT_SPI_HW)){

        for (int i = 0; i < bytesNumber; i++){

            data = Cy_SCB_SPI_Read(KIT_SPI_HW);

        }

    }

    return bytesNumber;

}

View solution in original post

0 Likes
1 Reply
MiKi_3184011
New Contributor II

This works.  Any recommendations on optimization or preffered options sincerely appreciated.

unsigned char SPI_Read(unsigned char* data, unsigned char bytesNumber)

{

Cy_SysLib_DelayUs(20);

    while(~Cy_SCB_SPI_GetTxFifoStatus(KIT_SPI_HW) & Cy_SCB_SPI_IsTxComplete(KIT_SPI_HW)){Cy_SysLib_DelayUs(2);}

    Cy_SCB_SPI_ClearRxFifo(KIT_SPI_HW);

    for (int i = 0; i < bytesNumber; i++){

    Cy_SCB_SPI_Write(KIT_SPI_HW, 0x00);

    }

    Cy_SysLib_DelayUs(20);

    while(~Cy_SCB_SPI_GetTxFifoStatus(KIT_SPI_HW) & Cy_SCB_SPI_IsTxComplete(KIT_SPI_HW)){Cy_SysLib_DelayUs(2);}

    if(Cy_SCB_SPI_GetNumInRxFifo(KIT_SPI_HW)){

        for (int i = 0; i < bytesNumber; i++){

            data = Cy_SCB_SPI_Read(KIT_SPI_HW);

        }

    }

    return bytesNumber;

}

View solution in original post

0 Likes
Top labels