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/CC2640: How to build the communication between two CC2640 LAUNCHPADs through NPI_SPI ?

Part Number: CC2640

Tool/software: Code Composer Studio

According to the TI official guide 《Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project》,it shows how to add NPI_SPI into simple_peripheral project . However , the code in
《Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project》is SPI SLAVE only ,instead of SPI MASTER. How to configure the code offered in the TI official guide so that it can be used as SPI
MASTER ?

How to build the communication between two CC2640 LAUNCHPADs through NPI_SPI ?

My detail steps are as followed:
1.Using two CC2640 LAUNCHPADs , act as SPI MASTER and SPI SLAVE respectively .Code running on two CC2640 LAUNCHPADs is simple_peripheral project .

2.On the first CC2640 LAUNCHPAD , add NPI_SPI into simple_peripheral project according to 《Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project》.

(1) download the “tl.h” and “tl.c ” file . The path is shown in attachments 6(7) and 6(8).


(2) add NPI_SPI into simple_peripheral project according to 《Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project》.After completed , the result is shown in picture 1.

(3) according to the TI official guide 《NPI》, there has MRDY and SRDY wires . Add predefined symbols "NPI_FLOW_CTRL" in simple_peripheral project , as shown in picture 2.

(4) In npi_tl.c , MRDY_PIN and SRDY_PIN is defined , as shown in picture 3. MRDY_PIN and SRDY_PIN is Board_BUTTON0 and Board_BUTTON1 respectively , as shown in picture 4 .

(5) In NPITLSPI_initializeTransport() function of npi_tl_spi.c , spiParams.mode is SPI_SLAVE . The code is shown as followed:

void NPITLSPI_initializeTransport(Char *tRxBuf, Char *tTxBuf, npiCB_t npiCBack)
{
    SPI_Params spiParams;

    TransportRxBuf = tRxBuf;
    TransportTxBuf = tTxBuf;
    npiTransmitCB = npiCBack;

    // Initialize the SPI driver
    Board_initSPI();
    
    // Configure SPI parameters
    SPI_Params_init(&spiParams);

    // Slave mode
    spiParams.mode = SPI_SLAVE;
    spiParams.bitRate = SPI_SLAVE_BAUD_RATE;
    spiParams.frameFormat = SPI_POL1_PHA1;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    spiParams.transferCallbackFxn = NPITLSPI_CallBack;

    // Attempt to open SPI
    spiHandle = SPI_open(NPI_SPI_CONFIG, &spiParams);
    return;
}

(6) running the code when configuration completed on the first CC2640 LAUNCHPAD .

3.On the second CC2640 LAUNCHPAD , configuring the code to make it serve as SPI MASTER.

(1) configure the spiParams.mode as SPI_MASTER in npi_tl_spi.c .The code is shown as followed:

void NPITLSPI_initializeTransport(Char *tRxBuf, Char *tTxBuf, npiCB_t npiCBack)
{
    SPI_Params spiParams;

    TransportRxBuf = tRxBuf;
    TransportTxBuf = tTxBuf;
    npiTransmitCB = npiCBack;

    // Initialize the SPI driver
    Board_initSPI();
    
    // Configure SPI parameters
    SPI_Params_init(&spiParams);

    // Slave mode
    spiParams.mode = SPI_MASTER;
    spiParams.bitRate = SPI_SLAVE_BAUD_RATE;
    spiParams.frameFormat = SPI_POL1_PHA1;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    spiParams.transferCallbackFxn = NPITLSPI_CallBack;

    // Attempt to open SPI
    spiHandle = SPI_open(NPI_SPI_CONFIG, &spiParams);
    return;
}

(2) In the SimpleBLEPeripheral_TLpacketParser() function of simple_peripheral.c , TLwrite() funtion is executed after TLread() function , the code is shown as followed. However , the code
can not be used as SPI MASTER . How the configure the SimpleBLEPeripheral_TLpacketParser() function , so that the code can serve as SPI MASTER ?

#if defined (NPI_USE_UART) || defined (NPI_USE_SPI)
static void SimpleBLEPeripheral_TLpacketParser(void)
{
  //read available bytes
  uint8_t len = TLgetRxBufLen();
  if (len >= APP_TL_BUFF_SIZE)
  {
    len = APP_TL_BUFF_SIZE;
  }
  TLread(appRxBuf, len);

  // ADD PACKET PARSER HERE
  // for now we just echo...

  TLwrite(appRxBuf, len);
}
#endif //TL

4.Connecting two CC2640 LAUNCHPADs , as shown in picture 5 . Running the code on two CC2640 LAUNCHPADs respectively , but the SPI communication failed . Where am I wrong ?

5.“npi_tl_uart_m.c” file is located in simplelink_cc2640r2_sdk_1_40_00_45 , which is used for NPI UART MASTER . Is there any similar files which used for NPI SPI MASTER ?

6.Attachments
(1) my source code of NPI SPI SLAVE which running on the first CC2640 LAUNCHPAD can be downloaded here :

spi_slave.rar

(2) my source code of NPI MASTER SLAVE which running on the second CC2640 LAUNCHPAD can be downloaded here :

spi_master.rar

(3) TI official guide 《Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project》 can de downloaded here :

(4) TI official guide 《NPI》 can de downloaded here :

(5) the location of simple_peripheral project in my computer is shown as followed:
C:\ti\simplelink_cc2640r2_sdk_1_40_00_45\examples\rtos\CC2640R2_LAUNCHXL\blestack\simple_peripheral

(6) simplelink_cc2640r2_sdk_1_40_00_45 can de downloaded here :

(7) CC2640R2 launchpad can be bought here :

(8) “tl.h” can de downloaded here :


(9) “tl.c” can de downloaded here :

  • Hi Heng,

    As far as I know there is no NPI SPI Master implementation on the TL layer as there is for UART. Is there any special reason why you want to use NPI SPI to setup communication between two CC2640R2F?

    NPI is quite big and not super easy to use, if you simply need to some sort of simple communication between the two platforms you are probably better of using the original SPI driver and putting together a simple packet format.
  • Thanks for your reply .

    The reason why I need to build NPI_SPI communication between two CC2640R2 LAUNCHPADs is that the  NPI_SPI communication between one CC2640R2  and another MCU is needed in our project .

    According to the requirements of  power saving and reliability of SPI communication between   CC2640R2  and another MCU  in our project , the best way is using the NPI_SPI in SDK ,  instead of using the original SPI driver.

    In order to build the  the  NPI_SPI communication between one CC2640R2  and another MCU , the first step is building NPI_SPI communication between two CC2640R2 LAUNCHPADs . The second step is immigrating

    the NPI_SPI_MASTER code into another MCU. 

    NPI is not easy to use , but I have to overcome it .

  • Hi Heng,

    In this case I suspect you are better of creating your own master implementation on the MCU side right away, the protocol itself is not very complicated and you can adapt your implementation to do only what you need it to do.

    Regarding the original SPI driver and power saving, there is examples provided in the driver header file on how to implement standby power savings when using only the SPI driver. The reliability should then be a matter of how you define your own packet frame (including CRC for example).
  • I will try to create my own master implementation on the MCU side right away.
    Thanks a lot.