Other Parts Discussed in Thread: AFE4300
Tool/software: Code Composer Studio
Hello,
I'm trying to make SPI communication work between CC1310 (as master) and an AFE4300 sensor (as slave). I'm using the CC1310 Launchpad and CCS 8.2.0.
My current code is (inside a thread, building on the empty project from the Resource Explorer):
GPIO_init(); SPI_init(); SPI_Handle spiHandle; SPI_Params spiParams; SPI_Transaction transaction; uint8_t txBuf[3]; uint8_t rxBuf[3]; txBuf[0]=0b00100011; txBuf[1]=0b00000000; txBuf[2]=0b00000000; uint8_t transmission[3]; bool transferOK = false; SPI_Status transactionStatus; uint8_t receiveBuf[3]; /* RESET PROCEDURE FOR AFE4300 */ usleep(100000); GPIO_write(Board_GPIO_AFE_RST,0); usleep(100000); GPIO_write(Board_GPIO_AFE_RST,1); usleep(100000); /* SPE pin of AFE4300 is permanently pulled down because we have only one master-slave SPI connection. We don't need to pull the SPE pin down in order to communicate. */ /* INITIALIZATION OF SPI PARAMS */ SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA1; // AFE4300 uses POL0_PHA1 as mode: idle state of SCLK is LOW, Data is changed on rising edge and sampled on falling edge spiParams.mode = SPI_MASTER; // CC1310 is transmitting as master spiParams.transferMode = SPI_MODE_BLOCKING; // blocking mode: we only use one thread, so callback function would only cause unnecessary overhead spiParams.bitRate = 4000000; // supported bit rate by AFE4300: <= 4MHz spiParams.dataSize = 8; spiHandle = SPI_open(Board_SPI1, &spiParams); transaction.count = 3; transaction.txBuf = (void *) txBuf; transaction.rxBuf = (void *) rxBuf; transferOK = SPI_transfer(spiHandle, &transaction); transactionStatus = transaction.status; SPI_close(spiHandle);
Now this isn't working. When I run the program, it sets transferOK as true and transactionStatus as TRANSFER_COMPLETED, but the results in rxBuf are rubbish. Looking at the SPI lines, I see something like this:
Obviously, there's no real clock signal and the MOSI signal doesn't make sense either.
Weirdly, when I take a far too huge value for transaction.count, it suddenly produces something looking like a clock signal, though the width is off and the MOSI signal doesn't make sense at all either:
First I was using Board_SPI0, but after taking a deeper look into the Board.h files etc. I though it might cause problems because it's used for flashing. Also, the AFE4300 wants the CLK line to be low when idle and the CLK pin of SPI0 is configured to be high at default, so it stays high except when calling SPI_transfer(), which I thought might be causing problems. I then switched to Board_SPI1, by making the following changes to the code:
- in CC1310_LAUNCHXL.h, I changed the pins to:
#define CC1310_LAUNCHXL_SPI1_MISO IOID_15 /* SPI for AFE */
#define CC1310_LAUNCHXL_SPI1_MOSI IOID_22
#define CC1310_LAUNCHXL_SPI1_CLK IOID_21
those pins are currently not connected to the AFE4300, but that shouldn't alter the signals that can be measured via Logic Analyzer.
- in CC1310_LAUNCHXL.c, I added the following lines to PIN-Config BoardGpioInitTable[] right before PIN_TERMINATE:
CC1310_LAUNCHXL_SPI1_MOSI | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED, /* SPI master out - slave in */
CC1310_LAUNCHXL_SPI1_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */
CC1310_LAUNCHXL_SPI1_CLK | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED, /* SPI clock */
That didn't help though.
Right now I'm out of ideas how I might be using the SPI module wrong. Could you please help me?
Best regards, Alissa