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/CC2642R: SPI

Part Number: CC2642R


Tool/software: Code Composer Studio

I urgently need your help. I am totally new for  TI CCS programming and I am currently developing SPI communication from the SDK example of SPI_Master. In the example the SPI_MASTER uses three pins for MOSI,MISO and Clock. So, for the CS I want to use one pin to be controlled by the software and I used "Board_SPI_MASTER_READY" which is DIO-15. Observing on the output it seems that the master write is working but I am not getting any response from the slave device which is FM25V05-G. Here I have attached my code.

/*
* Copyright (c) 2015-2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* ======== empty.c ========
*/

/* For usleep() */
#include <unistd.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include <pthread.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
// #include <ti/drivers/I2C.h>
// #include <ti/drivers/SDSPI.h>
#include <ti/drivers/SPI.h>
// #include <ti/drivers/UART.h>
// #include <ti/drivers/Watchdog.h>

/* Board Header file */
#include "Board.h"

/* FRAM OPCODES*/
#define WREN 0x06 // Write Enable Opcode
#define WRIDI 0x04 // Write Disable Opcode
#define RDSR 0x05 // Read Status Register Opcode
#define WRSR 0x01 // Write Status Register Opcode
#define READ 0x03 // Read Opcode
#define WRITE 0x02 // Write Opcode
#define FSTRD 0x0B // Fast Read Opcode
#define SlEEP 0xB9 // Enter Sleep Mode
#define RDID 0x9F // Read Device ID

SPI_Handle spi;
SPI_Transaction spiTransaction;
SPI_Params spiParams;

void FM25L512_Write_En(uint8_t Opcode1)
{
uint8_t transmitBuffer[1];
uint8_t receiveBuffer[1];

memset(transmitBuffer,0,sizeof(transmitBuffer));
memset(receiveBuffer,0,sizeof(receiveBuffer));
transmitBuffer[0] = Opcode1;

spiTransaction.count = sizeof(transmitBuffer);
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;

SPI_transfer(spi, &spiTransaction);

}

void FM25L512_Write_SPI( uint8_t Opcode1, uint8_t MSBAddr,uint8_t LSBAddr, uint8_t Data)
{
uint8_t transmitBuffer[4];
uint8_t receiveBuffer[4] ;
memset(transmitBuffer,0,sizeof(transmitBuffer));
memset(receiveBuffer,0,sizeof(receiveBuffer));

transmitBuffer[0] = Opcode1;
transmitBuffer[1] = MSBAddr;
transmitBuffer[2] = LSBAddr;
transmitBuffer[3] = Data;
spiTransaction.count = sizeof(transmitBuffer);
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;

SPI_transfer(spi, &spiTransaction);


}


uint8_t FM25L512_SPI_Read(uint8_t Opcode1, uint8_t MSBAddr,uint8_t LSBAddr)
{
uint8_t transmitBuffer[4];
uint8_t receiveBuffer[4];
uint8_t SReadMsg = 0x00;
memset(transmitBuffer,0,sizeof(transmitBuffer));
memset(receiveBuffer,0,sizeof(receiveBuffer));
transmitBuffer[0] = Opcode1;
transmitBuffer[1] = MSBAddr;
transmitBuffer[2] = LSBAddr;

spiTransaction.count = sizeof(transmitBuffer);
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;

SPI_transfer(spi, &spiTransaction);
SReadMsg = receiveBuffer[3];

return SReadMsg;
}

uint8_t FM25L512_Read_SR(uint8_t Opcode)
{
uint8_t transmitBuffer[2];
uint8_t receiveBuffer[2];
uint8_t SRMsg = 0x00;

memset(transmitBuffer,0,sizeof(transmitBuffer));
memset(receiveBuffer,0,sizeof(receiveBuffer));
transmitBuffer[0] = Opcode;

spiTransaction.count = sizeof(transmitBuffer);
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;

SPI_transfer(spi, &spiTransaction);
SRMsg = receiveBuffer[1];

return SRMsg;

}

/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{

// GPIO initialization

GPIO_init();
GPIO_setConfig(Board_SPI_MASTER_READY, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_HIGH);
GPIO_write(Board_SPI_MASTER_READY, 1);

/* Call driver init functions */


SPI_init();

/* Configure the LED pin */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);


SPI_Params_init(&spiParams); // Initialize SPI parameters
spiParams.dataSize = 8; // 8-bit data size


spi = SPI_open(Board_SPI0, &spiParams);
if (spi == NULL) {
while (1); // SPI_open() failed
}


// SPI Transaction with CS

// Write Enable


GPIO_write(Board_SPI_MASTER_READY, 0);

__delay_cycles(0.05);// Delay for the CS to get ready

FM25L512_Write_En(WREN);

GPIO_write(Board_SPI_MASTER_READY, 1);

__delay_cycles(10);


// Data Write

GPIO_write(Board_SPI_MASTER_READY, 0);
__delay_cycles(0.05);

FM25L512_Write_SPI(WRITE,0x00,0x00,0x07);
__delay_cycles(0.05);

GPIO_write(Board_SPI_MASTER_READY, 1);

__delay_cycles(10);

// Data Read
__delay_cycles(10);

GPIO_write(Board_SPI_MASTER_READY, 0);
__delay_cycles(100);

FM25L512_SPI_Read(READ,0x00,0x00);
__delay_cycles(10);

GPIO_write(Board_SPI_MASTER_READY, 1);
__delay_cycles(10);

while (1) {

usleep(100000);
GPIO_toggle(Board_GPIO_LED0);
}

}

  • -When posting code, please use the "Insert code using the syntax highlighter"

    - Please post a logic analyzer plot of the SPI traffic.

  • * ======== empty.c ========
    */
    
    /* For usleep() */
    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    #include <string.h>
    #include <time.h>
    #include <pthread.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    // #include <ti/drivers/I2C.h>
    // #include <ti/drivers/SDSPI.h>
    #include <ti/drivers/SPI.h>
    // #include <ti/drivers/UART.h>
    // #include <ti/drivers/Watchdog.h>
    
    /* Board Header file */
    #include "Board.h"
    
    /* FRAM OPCODES*/
    #define WREN 0x06 // Write Enable Opcode
    #define WRIDI 0x04 // Write Disable Opcode
    #define RDSR 0x05 // Read Status Register Opcode
    #define WRSR 0x01 // Write Status Register Opcode
    #define READ 0x03 // Read Opcode
    #define WRITE 0x02 // Write Opcode
    #define FSTRD 0x0B // Fast Read Opcode
    #define SlEEP 0xB9 // Enter Sleep Mode
    #define RDID 0x9F // Read Device ID
    
    SPI_Handle spi;
    SPI_Transaction spiTransaction;
    SPI_Params spiParams;
    
    void FM25L512_Write_En(uint8_t Opcode1)
    {
    uint8_t transmitBuffer[1];
    uint8_t receiveBuffer[1];
    
    memset(transmitBuffer,0,sizeof(transmitBuffer));
    memset(receiveBuffer,0,sizeof(receiveBuffer));
    transmitBuffer[0] = Opcode1;
    
    spiTransaction.count = sizeof(transmitBuffer);
    spiTransaction.txBuf = (void *)transmitBuffer;
    spiTransaction.rxBuf = (void *)receiveBuffer;
    
    SPI_transfer(spi, &spiTransaction);
    
    }
    
    void FM25L512_Write_SPI( uint8_t Opcode1, uint8_t MSBAddr,uint8_t LSBAddr, uint8_t Data)
    {
    uint8_t transmitBuffer[4];
    uint8_t receiveBuffer[4] ;
    memset(transmitBuffer,0,sizeof(transmitBuffer));
    memset(receiveBuffer,0,sizeof(receiveBuffer));
    
    transmitBuffer[0] = Opcode1;
    transmitBuffer[1] = MSBAddr;
    transmitBuffer[2] = LSBAddr;
    transmitBuffer[3] = Data;
    spiTransaction.count = sizeof(transmitBuffer);
    spiTransaction.txBuf = (void *)transmitBuffer;
    spiTransaction.rxBuf = (void *)receiveBuffer;
    
    SPI_transfer(spi, &spiTransaction);
    
    
    }
    
    
    uint8_t FM25L512_SPI_Read(uint8_t Opcode1, uint8_t MSBAddr,uint8_t LSBAddr)
    {
    uint8_t transmitBuffer[4];
    uint8_t receiveBuffer[4];
    uint8_t SReadMsg = 0x00;
    memset(transmitBuffer,0,sizeof(transmitBuffer));
    memset(receiveBuffer,0,sizeof(receiveBuffer));
    transmitBuffer[0] = Opcode1;
    transmitBuffer[1] = MSBAddr;
    transmitBuffer[2] = LSBAddr;
    
    spiTransaction.count = sizeof(transmitBuffer);
    spiTransaction.txBuf = (void *)transmitBuffer;
    spiTransaction.rxBuf = (void *)receiveBuffer;
    
    SPI_transfer(spi, &spiTransaction);
    SReadMsg = receiveBuffer[3];
    
    return SReadMsg;
    }
    
    uint8_t FM25L512_Read_SR(uint8_t Opcode)
    {
    uint8_t transmitBuffer[2];
    uint8_t receiveBuffer[2];
    uint8_t SRMsg = 0x00;
    
    memset(transmitBuffer,0,sizeof(transmitBuffer));
    memset(receiveBuffer,0,sizeof(receiveBuffer));
    transmitBuffer[0] = Opcode;
    
    spiTransaction.count = sizeof(transmitBuffer);
    spiTransaction.txBuf = (void *)transmitBuffer;
    spiTransaction.rxBuf = (void *)receiveBuffer;
    
    SPI_transfer(spi, &spiTransaction);
    SRMsg = receiveBuffer[1];
    
    return SRMsg;
    
    }
    
    /*
    * ======== mainThread ========
    */
    void *mainThread(void *arg0)
    {
    
    // GPIO initialization
    
    GPIO_init();
    GPIO_setConfig(Board_SPI_MASTER_READY, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_HIGH);
    GPIO_write(Board_SPI_MASTER_READY, 1);
    
    /* Call driver init functions */
    
    
    SPI_init();
    
    /* Configure the LED pin */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
    
    
    SPI_Params_init(&spiParams); // Initialize SPI parameters
    spiParams.dataSize = 8; // 8-bit data size
    
    
    spi = SPI_open(Board_SPI0, &spiParams);
    if (spi == NULL) {
    while (1); // SPI_open() failed
    }
    
    
    // SPI Transaction with CS
    
    // Write Enable
    
    
    GPIO_write(Board_SPI_MASTER_READY, 0);
    
    __delay_cycles(0.05);// Delay for the CS to get ready
    
    FM25L512_Write_En(WREN);
    
    GPIO_write(Board_SPI_MASTER_READY, 1);
    
    __delay_cycles(10);
    
    
    // Data Write
    
    GPIO_write(Board_SPI_MASTER_READY, 0);
    __delay_cycles(0.05);
    
    FM25L512_Write_SPI(WRITE,0x00,0x00,0x07);
    __delay_cycles(0.05);
    
    GPIO_write(Board_SPI_MASTER_READY, 1);
    
    __delay_cycles(10);
    
    // Data Read
    __delay_cycles(10);
    
    GPIO_write(Board_SPI_MASTER_READY, 0);
    __delay_cycles(100);
    
    FM25L512_SPI_Read(READ,0x00,0x00);
    __delay_cycles(10);
    
    GPIO_write(Board_SPI_MASTER_READY, 1);
    __delay_cycles(10);
    
    while (1) {
    
    usleep(100000);
    GPIO_toggle(Board_GPIO_LED0);
    }
    
    }

  • Still waiting for a SPI plot showing your issue.
  • Do you have an update on this case? I have to have SPI plots to be able to help.