Part Number: TCAN4550
Other Parts Discussed in Thread: CC1352R,
Greetings! I am trying to set up SPI connection between CC1352R and TCAN4550 using spimaster example of CC13x2_26x2 SDK v3.10.01.11. To test the connection, I want to read TCAN4550 0x0000 register which contains device ID information (0x54, 0x43, 0x41, 0x4E according to datasheet, p.45).
The problem is - whatever CC1352R transfers to TCAN4550, it always reads 0xc8 or 0x89 value, if TCAN is turned on and not sleeping. So there is some response, but the way of communication seems to be incorrect. Can someone pleas help to set the SPI?
The code is listed below:
/*
* ======== spimaster.c ========
*/
#include <stddef.h>
#include <stdint.h>
#include <string.h>
/* POSIX Header files */
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
#include <ti/display/Display.h>
/* Example/Board Header files */
#include "Board.h"
#define THREADSTACKSIZE (1024)
#define SPI_MSG_LENGTH (4)
#define MAX_LOOP (10)
static Display_Handle display;
unsigned char masterRxBuffer[4];
unsigned char masterTxBuffer[4];
/*
* ======== masterThread ========
* Master SPI sends a message to slave while simultaneously receiving a
* message from the slave.
*/
void *masterThread(void *arg0)
{
SPI_Handle masterSpi;
SPI_Params spiParams;
SPI_Transaction transaction;
bool transferOK;
const char MASTER_MSG[SPI_MSG_LENGTH] = {0x41, 0x00, 0x00, 0x01};
/* Open SPI as master */
spiParams.frameFormat = SPI_POL0_PHA1;
spiParams.bitRate = 4000000;
spiParams.mode = SPI_MASTER;
SPI_Params_init(&spiParams);
masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
if (masterSpi == NULL) {
Display_printf(display, 0, 0, "Error initializing master SPI\n");
while (1);
}
else {
Display_printf(display, 0, 0, "Master SPI initialized\n");
}
strncpy((char *) masterTxBuffer, MASTER_MSG, SPI_MSG_LENGTH);
memset((void *) masterRxBuffer, 0, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = (void *) masterTxBuffer;
transaction.rxBuf = (void *) masterRxBuffer;
transferOK = SPI_transfer(masterSpi, &transaction);
if (transferOK) {
Display_printf(display, 0, 0, "Master received: %x", masterRxBuffer[0]);
Display_printf(display, 0, 0, "Master received: %x", masterRxBuffer[1]);
Display_printf(display, 0, 0, "Master received: %x", masterRxBuffer[2]);
Display_printf(display, 0, 0, "Master received: %x", masterRxBuffer[3]);
}
else {
Display_printf(display, 0, 0, "Unsuccessful master SPI transfer");
}
SPI_close(masterSpi);
Display_printf(display, 0, 0, "\nDone");
return (NULL);
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
pthread_t thread0;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
int detachState;
/* Call driver init functions. */
Display_init();
GPIO_init();
SPI_init();
/* Configure the LED pins */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Open the display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
/* Failed to open display driver */
while (1);
}
/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the SPI master example");
Display_printf(display, 0, 0, "This example requires external wires to be "
"connected to the header pins. Please see the Board.html for details.\n");
/* Create application threads */
pthread_attr_init(&attrs);
detachState = PTHREAD_CREATE_DETACHED;
/* Set priority and stack size attributes */
retc = pthread_attr_setdetachstate(&attrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
while (1);
}
retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
while (1);
}
/* Create master thread */
priParam.sched_priority = 1;
pthread_attr_setschedparam(&attrs, &priParam);
retc = pthread_create(&thread0, &attrs, masterThread, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
return (NULL);
}
