PSoC 6 SPI communication with ad7177_2

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
user_349366
Level 1
Level 1

Good morning everyone.
I am sorry if such a topic has already appeared. I have a problem with SPI communication in PSoC 6. I need to communicate PSoC 6 with 32bit ad7177-2 voltmeter. I prepared the program based on the data sheet and materials from Analog Devices (https://wiki.analog.com/resources/tools-software/uc-drivers/ad717x). A lot of things are already done by the manufacturer. For my part, I need to adapt the prepared libraries to the Cypress platform. I described the write and read communication based on the examples of SPI Master and SPI Slave. At the moment it seems to me that the program sends data to the ADC but cannot receive the answer.

I use Cy_SCB_SPI_GetNumInRxFifo(mSPI_HW) function inside SPI_read function to get informaction about number of received bits but I constantly received 0 bits.

I attached the program as an attachment. Please help.

Best regards

Łukasz

0 Likes
1 Solution
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi Lukasz,

For you to receive the data from the slave you should send the data from the master but you are using only spi_read due to which you are unable to receive.

I have shared the snippet of the example code below which you can use in  your project.

static uint32_t ReadStatusPacket(void)

{

    uint8_t dummyTxBuf[TX_PACKET_SIZE] = {DUMMY_VALUE, DUMMY_VALUE, DUMMY_VALUE, DUMMY_VALUE, DUMMY_VALUE};

    uint32_t status = TRANSFER_ERROR;

    uint32_t masterStatus;

    /* Timeout 1 sec (one unit is 1 milli second) */

    uint32_t timeOut = 1000UL;

      

    /*Write packet to read status */

    Cy_SCB_SPI_WriteArrayBlocking(mSPI_HW, dummyTxBuf, TX_PACKET_SIZE);

   

    /* Wait until master completes transfer or time out has occured.

       If time out occurs handle the error. */

    do

    {

        masterStatus  = Cy_SCB_SPI_GetSlaveMasterStatus(mSPI_HW);

        Cy_SysLib_Delay(CY_SCB_WAIT_1_UNIT);

        timeOut--;

}

if(masterStatus == CY_SCB_SPI_MASTER_DONE)

    { 

        if(TX_PACKET_SIZE == Cy_SCB_SPI_GetNumInRxFifo(mSPI_HW))

        {

            /* Read data from Rx FIFO. */

            Cy_SCB_SPI_ReadArray(mSPI_HW, statusRxBuf, TX_PACKET_SIZE);

          

We hope our information is clear kindly come back if you have any queries.

Regards

Alakananda

Alakananda

View solution in original post

0 Likes
3 Replies
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi Lukasz,

For you to receive the data from the slave you should send the data from the master but you are using only spi_read due to which you are unable to receive.

I have shared the snippet of the example code below which you can use in  your project.

static uint32_t ReadStatusPacket(void)

{

    uint8_t dummyTxBuf[TX_PACKET_SIZE] = {DUMMY_VALUE, DUMMY_VALUE, DUMMY_VALUE, DUMMY_VALUE, DUMMY_VALUE};

    uint32_t status = TRANSFER_ERROR;

    uint32_t masterStatus;

    /* Timeout 1 sec (one unit is 1 milli second) */

    uint32_t timeOut = 1000UL;

      

    /*Write packet to read status */

    Cy_SCB_SPI_WriteArrayBlocking(mSPI_HW, dummyTxBuf, TX_PACKET_SIZE);

   

    /* Wait until master completes transfer or time out has occured.

       If time out occurs handle the error. */

    do

    {

        masterStatus  = Cy_SCB_SPI_GetSlaveMasterStatus(mSPI_HW);

        Cy_SysLib_Delay(CY_SCB_WAIT_1_UNIT);

        timeOut--;

}

if(masterStatus == CY_SCB_SPI_MASTER_DONE)

    { 

        if(TX_PACKET_SIZE == Cy_SCB_SPI_GetNumInRxFifo(mSPI_HW))

        {

            /* Read data from Rx FIFO. */

            Cy_SCB_SPI_ReadArray(mSPI_HW, statusRxBuf, TX_PACKET_SIZE);

          

We hope our information is clear kindly come back if you have any queries.

Regards

Alakananda

Alakananda
0 Likes

I still do not know how to properly prepare SPI_write and SPI_read functions to match this project. Can you help?

0 Likes

Hi Lukasz,

Can you please refer to the below thread

PSoC 6 - SPI with two devices

Regards

Alakananda

Alakananda
0 Likes