I am attempting to interface a TM4C-1294NCPDT microcontroller with a CC1101 radio using SPI. My launchpad is the EK-TM4C1294XL. My compiler is CCS 6.0.1. The radio board (CC1101EM 3.0) is connected to the board via the EM Adapter BoosterPack such that I have the following connections:
|
CC1101 Name |
TM4C1294 Name |
TM4C1294 Port/Pin |
Purpose |
|
CSn |
GPIO |
PP5 |
Radio control (Hi/Lo) |
|
SCLK |
SCLK |
PQ0 |
Clock |
|
SI |
SSI3TX/SSI3XDAT0 |
PQ2/A3 |
MOSI |
|
SO |
SSI3RX/SSI3XDAT1 |
PQ3/A2 |
MISO |
I used the gpiointerrupt_TivaTM4C1294NCPDT example from the "Getting Started" menu to start with, and added "Board_initSPI();" (which links toEK_TM4C1294XL_initSPI()) to the beginning of my main program.
My current task is to write to a single configuration register on the CC1101 (I am using the channel number register), and then read the value back to verify that my writing steps work correctly. Unfortunately the value I read back is always either F0 or 0F, or 1E or E1, or C3 or 3C, or 78 or 87, regardless of what I have written to the configuration register.
This is my reading/writing function:
//Includes
#include "cc1101_functions.h"
#include <inc/hw_memmap.h>
#include <inc/hw_gpio.h>
/* Write to the cc1101 */
uint8 cc1101Write(void)
{
uint32_t pui32DataTx[16];
uint32_t pui32DataRx[16];
uint32_t ui32Index;
uint32_t dummy;
/*All transactions start with a header byte containing a R/W bit, a burst access bit,
and a 6-bit address*/
//Setting addresses, headers, and data to be sent
int address = CC1101_CHANNR; //where in the CC1101 is being written to
uint8_t header_write = (0x00 | address); //Set up header for writing
uint8_t header_read = (0x80 | address); //Set up header for reading
//Set up data to be written
pui32DataTx[0]=header_write;
//Data to be written, set up for easy expansion later
for(ui32Index=1; ui32Index<2;ui32Index++)
{
pui32DataTx[ui32Index]= 0x05;
}
//Pull the CSn low
GPIOPinWrite(GPIO_PORTP_BASE|GPIO_O_STATUS,GPIO_PIN_5,0x00);
//Wait until the MISO pin goes low
while (GPIOPinRead(GPIO_PORTQ_BASE|GPIO_O_STATUS, GPIO_PIN_3));
//When not busy, write header for writing data to MOSI Pin
while(SSIBusy(SSI3_BASE)){} //Wait for SSI to not be busy
SSIDataPut(SSI3_BASE, pui32DataTx[0]); //Write header for writing data
SSIDataGet(SSI3_BASE, &dummy); //Read dummy values
//When not busy, write data to MOSI Pin
while(SSIBusy(SSI3_BASE)){} //Wait for SSI to not be busy
SSIDataPut(SSI3_BASE, pui32DataTx[1]); //Write data
SSIDataGet(SSI3_BASE, &dummy); //Read dummy value
//When not busy, write header for reading data from MISO Pin
while(SSIBusy(SSI3_BASE)){} //Wait for SSI to not be busy
SSIDataPut(SSI3_BASE, header_read); //write header for reading data
SSIDataGet(SSI3_BASE, &dummy); //read dummy value
//When not busy, read data from MISO pin
while(SSIBusy(SSI3_BASE)){} //wait for SSI to be ready
SSIDataPut(SSI3_BASE, 0x65); //Write dummy value
SSIDataGet(SSI3_BASE, &pui32DataRx[0]); //Read value
pui32DataRx[ui32Index] &= 0x00FF; //Mask unnecessary bits
//Pull CSN high
GPIOPinWrite(GPIO_PORTP_BASE|GPIO_O_STATUS,GPIO_PIN_5,0x20);
//Read the chip status byte on the MISO pin
return (GPIOPinRead(GPIO_PORTQ_BASE|GPIO_O_STATUS, GPIO_PIN_3));
}
My main function looks like this:
int main(void)
{
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initUART();
Board_initSPI();
cc1101Write();
/* Start BIOS */
BIOS_start();
return (0);
}
And SPI Initialization looks like this:
/*
* ======== EK_TM4C1294XL_initSPI ========
*/
void EK_TM4C1294XL_initSPI(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ);
/* SSI3 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
SSIDisable(SSI3_BASE);
// Set IO clock as SSI clock source
//
SSIClockSourceSet(SSI3_BASE, SSI_CLOCK_SYSTEM);
GPIOPinConfigure(GPIO_PQ0_SSI3CLK);
//GPIOPinConfigure(GPIO_PQ1_SSI3FSS); -->This is configured as a GPIO output pin
GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0);
GPIOPinConfigure(GPIO_PQ3_SSI3XDAT1);
GPIOPinTypeSSI(GPIO_PORTQ_BASE, GPIO_PIN_0 | GPIO_PIN_1 |GPIO_PIN_2 | GPIO_PIN_3);
EK_TM4C1294XL_initDMA();
SPI_init();
SSIEnable(SSI3_BASE);
}


