Other Parts Discussed in Thread: LAUNCHXL-CC26X2R1,
Hi all,
I want to connect one ADS127L01 to my LAUNCHXL-CC26X2R1 through SPI. At first, I want just read registers in ADS127L01 to test SPI connection. (ID register at address 00h)
I wrote my code based on spimaster example on SDK.
here is my code.
#define THREADSTACKSIZE (1024) #define SPI_MSG_LENGTH (1) static Display_Handle display; uint16_t masterRxBuffer[SPI_MSG_LENGTH]; uint16_t masterTxBuffer[SPI_MSG_LENGTH]; //unsigned char uint32_t i; /* * ======== 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; // uint32_t i; bool transferOK; int32_t status; /* Open SPI as master (default) */ SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA1; spiParams.bitRate = 200000; spiParams.dataSize = 8; spiParams.mode = SPI_MASTER; masterSpi = SPI_open(CONFIG_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"); } /* Copy message to transmit buffer */ for (i = 0; i < 100000; i++) { /* Initialize master SPI transaction structure */ masterTxBuffer[0] = 0x2000; transaction.count = SPI_MSG_LENGTH; transaction.txBuf = (void *) masterTxBuffer; transaction.rxBuf = (void *) masterRxBuffer; /* Perform SPI transfer */ transferOK = SPI_transfer(masterSpi, &transaction); if (transferOK) { Display_printf(display, 0, 0, "Master received: %d ",masterRxBuffer[0]); } else { Display_printf(display, 0, 0, "Unsuccessful master SPI transfer"); } /* Sleep for a bit before starting the next SPI transfer */ sleep(1); } 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(); /* Open the display for output */ display = Display_open(Display_Type_UART, NULL); if (display == NULL) { /* Failed to open display driver */ while (1); } 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); }
But masterRxBuffer is not as expected (x3h as mentioned in datasheet).
I connected 4 pins ( SCLK, MOSI, MISO, CS) from ADS127L01 to LAUNCHXL-CC26X2R1 and START to 1 and FORMAT to 0. what else should I do?
SDK version for spimaster example : SimpleLink CC13x2 26x2 SDK (5.30.01.01)
code composer studio version : 11.1.0.00011
Thanks in advance