Other Parts Discussed in Thread: CC3220SF
I am attempting to establish basic SPI communication between the CC3220SF-LAUNCHXL (SPI master) and an external sensor (Adafruit LIS3MDL) using SPI_transfer(). I am building an application in FreeRTOS which uses Simplelink SDK version 2.10.00.04.
I am successfully transmitting a device ID read command (0xCF) to the external sensor. On the logic analyzer, the sensor is responding with the expected value (0x3D). However, the read buffer is receiving a value of 0xE3. I can send transfer over and over and the value is consistently 0xE3.
Is there some basic configuration (software or hardware) that I could have wrong here?
Spi Config (index CC3220SF_LAUNCHXL_SPI1):
{ .baseAddr = GSPI_BASE, .intNum = INT_GSPI, .intPriority = (~0), .spiPRCM = PRCM_GSPI, .csControl = SPI_SW_CTRL_CS, .csPolarity = SPI_CS_ACTIVELOW, .pinMode = SPI_4PIN_MODE, .turboMode = SPI_TURBO_OFF, .scratchBufPtr = &spiCC3220SDMAscratchBuf[CC3220SF_LAUNCHXL_SPI1], .defaultTxBufValue = 0, .rxChannelIndex = UDMA_CH6_GSPI_RX, .txChannelIndex = UDMA_CH7_GSPI_TX, .minDmaTransferSize = 100, .mosiPin = SPICC32XXDMA_PIN_07_MOSI, .misoPin = SPICC32XXDMA_PIN_06_MISO, .clkPin = SPICC32XXDMA_PIN_05_CLK, .csPin = SPICC32XXDMA_PIN_NO_CONFIG }
SPI_open call:
SPI_Params_init(&xSpiParams); xSpiParams.transferMode = SPI_MODE_BLOCKING; xSpiParams.transferTimeout = SPI_WAIT_FOREVER; xSpiParams.transferCallbackFxn = NULL; xSpiParams.mode = SPI_MASTER; xSpiParams.bitRate = 1000000; // xSpiParams.bitRate = 500000; xSpiParams.dataSize = 8; xSpiParams.frameFormat = SPI_POL0_PHA0; // xSpiParams.frameFormat = SPI_POL1_PHA1; xSpiHandle = SPI_open(CC3220SF_LAUNCHXL_SPI1, &xSpiParams);
SPI Read code:
static int32_t prlSpiRead(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len) { int32_t lRetVal = 0; SPI_Transaction xSpiTransaction = {0}; SPI_Handle xSpiHandle = *((SPI_Handle*) handle); memset(xSpiTxBuff, 0xA5, 100); memset(xSpiRxBuff, 0x00, 100); GPIO_write(CC3220_LIS3MDL_SPI_CS_PIN, 0); xSpiTxBuff[0] = (reg | 0xC0); //read + auto increment xSpiTransaction.count = 1+len; // 1 command byte + number of expected bytes xSpiTransaction.txBuf = (void*) xSpiTxBuff; xSpiTransaction.rxBuf = (void*) xSpiRxBuff; SPI_transfer(xSpiHandle, &xSpiTransaction); GPIO_write(CC3220_LIS3MDL_SPI_CS_PIN, 1); memcpy(bufp, &xSpiRxBuff[1], len); if(SPI_TRANSFER_COMPLETED != xSpiTransaction.status) { lRetVal = -1; } return lRetVal; }