This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CC2640R2F: CC2640R2F SPI Slave receive first data wrong

Part Number: CC2640R2F

Tool/software: Code Composer Studio

CCS import projcec:

C:\ti\simplelink_cc2640r2_sdk_2_30_00_28\examples\rtos\CC2640R2_LAUNCHXL\drivers\spislave

SPI master main code:(not cc2640r2f)

spi_init();//CPOL=0, CPHA=1

cs_low();//CS connect to CC2640R2_LAUNCHXL_SPI_MASTER_READY of CC2640R2F

delay_ms(100);

spi_send_recv(master_tx, master_rx, 30);//master_tx[30]={0,1,2,3,...,28,29}

delay_ms(100);

cs_high();

SPI Slave main code:

//CC2640R2_LAUNCHXL.h
#define CC2640R2_LAUNCHXL_SPI0_MISO             IOID_6          /* RF1.20 */
#define CC2640R2_LAUNCHXL_SPI0_MOSI             IOID_3          /* RF1.18 */
#define CC2640R2_LAUNCHXL_SPI0_CLK              IOID_2          /* RF1.16 */
#define CC2640R2_LAUNCHXL_SPI0_CSN              PIN_UNASSIGNED

typedef enum CC2640R2_LAUNCHXL_GPIOName {
    CC2640R2_LAUNCHXL_SPI_MASTER_READY = 0,
    CC2640R2_LAUNCHXL_SPI_SLAVE_READY,

    CC2640R2_LAUNCHXL_GPIOCOUNT
} CC2640R2_LAUNCHXL_GPIOName;

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

//CC2640R2_LAUNCHXL.c
GPIO_PinConfig gpioPinConfigs[] = {
    IOID_0 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
    IOID_1 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
};

const PIN_Config BoardGpioInitTable[] = {
    CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,  /* SPI master out - slave in */
    CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,  /* SPI master in - slave out */
    CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,  /* SPI clock */

    PIN_TERMINATE
};

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

//spislave.c
#define SPI_MSG_LENGTH  (30)
#define SEND_MSG      ("Hello from slaver, msg#: 1")

uint8_t RxBuffer[SPI_MSG_LENGTH];
uint8_t TxBuffer[SPI_MSG_LENGTH];

void transferCompleteFxn(SPI_Handle handle, SPI_Transaction *transaction)
{
    sem_post(&Sem);
}

void *masterThread(void *arg0)
{
    SPI_Handle      Spi;
    SPI_Params      spiParams;
    SPI_Transaction transaction;
    bool            transferOK;
    int32_t         status;

    GPIO_setConfig(Board_SPI_MASTER_READY, GPIO_CFG_INPUT);
    status = sem_init(&Sem, 0, 0);
    if (status != 0) {
        while(1);
    }

    SPI_Params_init(&spiParams);
    spiParams.frameFormat = SPI_POL0_PHA1;
    spiParams.mode = SPI_SLAVE;
    spiParams.transferCallbackFxn = transferCompleteFxn;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    Spi = SPI_open(CC2640R2_LAUNCHXL_SPI0, &spiParams);
    if (Spi == NULL) {
        while (1);
    }

    strncpy((char *)TxBuffer, SEND_MSG, SPI_MSG_LENGTH);
    memset((void *) RxBuffer, 0, SPI_MSG_LENGTH);

    while (GPIO_read(Board_SPI_MASTER_READY)) {}

    transaction.count = SPI_MSG_LENGTH;
    transaction.txBuf = (void *) TxBuffer;
    transaction.rxBuf = (void *) RxBuffer;
    transferOK = SPI_transfer(Spi, &transaction);
    if (transferOK) {
        sem_wait(&Sem);
    }
    else {
        while(1);
    }

    SPI_close(Spi);
    while(1);
}

Logic analyzer:(MOSI is not connected to logic analyzer)

Result:

SPI Master Sent:master_tx[30]={0,1,2,3,...,28,29}

                   Received:master_rx[30]="\0ello from slaver, msg#: 1"     //why first byte is 0x00,others bytes are correct

SPI Slave Sent: tx[30] = "Hello from slaver, msg#: 1"

                 Received: rx[30] = {0,1,2,3,...,28,29}        //Correct

 

Why SPI Master receive first byte is 0x00,where am I wrong

  • Hi,

    I can not see any obvious errors in your code that can explain this.
    Have you put a breakpoint after memset((void *) RxBuffer, 0, SPI_MSG_LENGTH) and verified that TxBuffer is copied correctly?
    If you repeat the sequence do your first byte also become zero the second time?

    I have just run spimaster + spislave example in the 2.40 SDK and everything looks fine (first byte is ok).

    Best Regards,
    R.M
  • 1. Here is the screenshot that I put a breakpoint after memset((void *) RxBuffer, 0, SPI_MSG_LENGTH) and verified that TxBuffer is copied correctly

    2. If I repeat the sequence, my first byte is always 0x00,and other bytes are always correct

    Maybe my project configuration is not correctly.Because hardware is not Launchpad and mcu is CC2640R2FRSM and the mcu package of  example project is different package with mine

  • Hi,

    It's difficult to say what the problem here is.
    If you do not physically connect your SPI master MISO line, do you still see that first byte is output 0 with logic analyzer? I'm thinking that your SPI Master might force the MISO line low for some reason in the beginning.

    Best Regards,
    R.M
  • I think that this is the same case that I experienced.


    e2e.ti.com/.../743831

  • Closing this thread due to lack of feedback