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.

请教:cc1310 SPI示例中为啥主机与从机为啥没有连接成功?新手求help

代码是TI的示例:

MASTER

#define SPI_TASK_STACK_SIZE 1024
#define SPI_TASK_PRIORITY 2
#define SPITASKSTACKSIZE 768
static uint8_t SPITaskStack[SPITASKSTACKSIZE];
static PIN_Handle pinHandle;
static PIN_State pinState;
PIN_Config SPIpinTable[] = {
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_SPI0_MOSI | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
Board_SPI0_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, // IOID_15 Ensure SPI slave 0 is not selected
Board_SPI1_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, // IOID_18 Ensure SPI slave 1 is not selected
PIN_TERMINATE
};

static void taskFxn(UArg a0, UArg a1)
{
SPI_Handle handle;
SPI_Params params;
SPI_Transaction transaction;
uint8_t txBuf[] = "Hello World"; // Transmit buffer
//uint8_t rxBuf[11]; // Receive buffer
// Init SPI and specify non-default parameters
SPI_Params_init(&params);
params.bitRate = 1000000;
params.frameFormat = SPI_POL1_PHA1;
params.mode = SPI_MASTER;
// Configure the transaction
transaction.count = sizeof(txBuf);
transaction.txBuf = txBuf;
transaction.rxBuf = NULL;
// Open the SPI and perform the transfer
handle = SPI_open(Board_SPI0, &params);

SPI_transfer(handle, &transaction);
PIN_setOutputValue(pinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1));
}

SALVE

PIN_Config SPIpinTable[] = {
//Board_SPI0_CLK | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_SPI0_MOSI | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
Board_SPI0_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, // IOID_15 Ensure SPI slave 0 is not selected
Board_SPI1_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, // IOID_18 Ensure SPI slave 1 is not selected
PIN_TERMINATE
};

static void taskFxn(UArg a0, UArg a1)
{
SPI_Handle handle;
SPI_Params params;
SPI_Transaction transaction;
uint8_t rxBuf[11]; // Receive buffer
// Init SPI and specify non-default parameters
SPI_Params_init(&params);
params.bitRate = 1000000;
params.frameFormat = SPI_POL1_PHA1;
params.mode = SPI_SLAVE;
// Configure the transaction
transaction.count = 11;
transaction.txBuf = NULL;
transaction.rxBuf = rxBuf;
// Open the SPI and perform the transfer
handle = SPI_open(Board_SPI0, &params);
SPI_transfer(handle, &transaction);
PIN_setOutputValue(pinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1));
}