Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > SPI slave how to receive 2bytes of data

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



SPI slave how to receive 2bytes of data
Moderator:
ANCY

Post Reply
Follow this topic



SPI slave how to receive 2bytes of data

anub posted on 08 May 2013 7:43 AM PST
Member
7 Forum Posts

Hello,

I'm trying to receive data over spi, it consist out of an adres and the data.


example:

adres    data

0x01        0x01
0x01        0x02
0x01        0x03
0x01        ...
0x02        0x01
0x02        0x02
and so on
 

The code i use is this, I just have no idea how to read the 'data'


SPIS_Start(SPIS_SPIS_MODE_0 | SPIS_SPIS_MSB_FIRST);
while(1)
{
while((SPI_Status = SPIS_bReadStatus()) == 0); // wait for data to be received

bData = SPIS_bReadRxData();        // read the received data
   

switch ( bData){
    case 0x01:
        SPIS_SetupTxData(0xAA);
       
    break;
   
    case 0x02:
        if (data==0x01){
        enc_enable = 1;
        bool_start = 1;
        bool_stop = 0;       
        }
    else
        if(data==0x02){
        enc_enable = 0;
        bool_start = 0;
        bool_stop = 1;
        }

    break;
....




Re: SPI slave how to receive 2bytes of data

Bob Marlowe posted on 08 May 2013 09:55 AM PST
Top Contributor
1768 Forum Posts

You have to read again with the same procedure as before:

    case 0x02:

while((SPI_Status = SPIS_bReadStatus()) == 0); // wait for data to be received

b2Data = SPIS_bReadRxData(); // read the second received data

        if (b2data==0x01){
enc_enable = 1;
bool_start = 1;
bool_stop = 0;
}
else
if(b2data==0x02){
enc_enable = 0;
bool_start = 0;
bool_stop = 1;
}

 ... and so on
 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20