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))
uint8_t cc1101_readReg(uint8_t regAddr, uint8_t regType)
{
uint8_t addr, val;
addr = regAddr | regType;
cc1101_Select();
wait_Miso();
SPI_WriteData(SPI0,addr);
val = SPI_ReadData(SPI0);
cc1101_Deselect();
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)
{
static uint8_t i, c;
c = data;
for(i=0; i<8; i++)
{
if((c & 0x80) == 0x80)
GPIO_SetPinsOutput(GPIOC, 1U << 6);
else
GPIO_ClearPinsOutput(GPIOC, 1U << 6);
GPIO_SetPinsOutput(GPIOC, 1U << 5);
c = c << 1;
GPIO_ClearPinsOutput(GPIOC, 1U << 5);
}
}
uint8_t SPIRead(void)
{
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?
Thanks.