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.

CC2640R2F: LAUNCHXL-CC2640R2:

Part Number: CC2640R2F

Hello, 

we are reading data from one slave device, my master is cc2640r2, but getting Garbage value at master side  can you suggest how to read and write data between master and slave

Requirement for reading data from slave  
1] ADDR_FIRST_DATA_BYTE    0xCF
2] NB_DATA_BYTES           14
 
3] To read N data bytes, N+1 transfers are required.
This is my Understanding 

#define SPI_MSG_LENGTH     14
#define MASTER_MSG             0xCF

unsigned char masterRxBuffer[SPI_MSG_LENGTH];
unsigned char masterTxBuffer[SPI_MSG_LENGTH];

/* Open SPI as master (default) */
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.bitRate = 10000000;
masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
/* Copy message to transmit buffer */
//strncpy((char *) masterTxBuffer, MASTER_MSG, SPI_MSG_LENGTH);
// memccpy((void *)masterTxBuffer, (const void *)MASTER_MSG,SPI_MSG_LENGTH);
memmove((void *)masterTxBuffer, (const void *)MASTER_MSG, SPI_MSG_LENGTH);
for (i = 0; i < MAX_LOOP; i++) {

/* Initialize master SPI transaction structure */
masterTxBuffer[sizeof(MASTER_MSG) - 1] = (i % 10) + '0';
memset((void *) masterRxBuffer, 0, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = (void *) masterTxBuffer;
transaction.rxBuf = (void *) masterRxBuffer;

/* Toggle user LED, indicating a SPI transfer is in progress */
GPIO_toggle(Board_GPIO_LED1);

/* Perform SPI transfer */
transferOK = SPI_transfer(masterSpi, &transaction);
if (transferOK) {
Display_printf(display, 0, 0, "Master received: %s", masterRxBuffer);
}
else {
Display_printf(display, 0, 0, "Unsuccessful master SPI transfer");
}

/* Sleep for a bit before starting the next SPI transfer */
sleep(3);
}

SPI_close(masterSpi);
 
**
we want to read data from slave by using this address  0xCF To read N data bytes, N+1 transfers are required.
  • Hello Akshay,

    I believe that you are loosely following the spimaster example.  You will need to make sure that your slave device can understand the frame format set by the master CC2640R2F device.  You may also want to fill the rest of MASTER_MSG with blank/buffer data that fills in SPI_MSG_LENGTH for which the slave should be sending data back to the master.  You should follow the SPI specification expected from the slave device's datasheet and use a logic analyzer or oscilloscope to make sure that the CLK, MISO, and MOSI lines are acting in accordance with your expectations and to further confirm what is being sent/received.  I also recommend that you use a slightly lower bit rate while testing.  You can refer to the SPI TI Drivers Runtime APIs for more guidance and examples, along with resourcing past E2E threads.

    Regards,
    Ryan