AnsweredAssumed Answered

SPI Interfacing KL25Z with TI CC1101

Question asked by Gustavo Leal on Jan 24, 2017
Latest reply on Jan 27, 2017 by Gustavo Leal

I'm working on a custom board using a MKL25Z128 and a TI CC1101 radio connected via SPI.

I'm having trouble getting the SPI communication between the KL25Z (master) and the CC1101 (slave) using KSDK 2.0.0.

I wrote the CC1101 driver based on other drivers I found (for the Arduino and mbed), but I can't integrate the SPI_ReadData and SPI_WriteData functions into it. The pins are already muxed as SPI.

I've implemented some software SPI routines for testing, and they work, but I want to use the hardware SPI.

As an example, the following is a snippet from the code that's supposed to read a register from the CC1101 and return it:

#define cc1101_Select() GPIO_ClearPinsOutput(SS_PIN_BASE, 1U << SS_PIN)
#define cc1101_Deselect() GPIO_SetPinsOutput(SS_PIN_BASE, 1U << SS_PIN)
#define wait_Miso() while(GPIO_ReadPinInput(MISO_PIN_BASE, MISO_PIN)) // Wait for MISO to go low

uint8_t cc1101_readReg(uint8_t regAddr, uint8_t regType)
   uint8_t addr, val;
   addr = regAddr | regType;
   val = SPI_ReadData(SPI0);
return val;

When I run it, the function usually returns 0 or the MISO pin never goes low.


The same code works using with these software SPI functions instead of KSDK's (with the pins configured as GPIO):

void SPIWrite(uint8_t data)
        /*send MSB first */

     static uint8_t i, c;
     c = data;
     for(i=0; i<8; i++)
     if((c & 0x80) == 0x80)
          GPIO_SetPinsOutput(GPIOC, 1U << 6);
          GPIO_ClearPinsOutput(GPIOC, 1U << 6);

     GPIO_SetPinsOutput(GPIOC, 1U << 5);
     c = c << 1;
     GPIO_ClearPinsOutput(GPIOC, 1U << 5);
uint8_t SPIRead(void)
     /* software SPI read, MSB read first */
     static uint8_t i, data;

     for(i=0; i<8; i++)
          data = data << 1;
          GPIO_SetPinsOutput(GPIOC, 1U << 5);
          if(GPIO_ReadPinInput(GPIOC, 7)){
               data = data+1;
          GPIO_ClearPinsOutput(GPIOC, 1U << 5);
     return data;


How should I do this using the KSDK SPI driver?