I m having a little difficulty trying to return a register value from a SPI device connected to an LPC5411 board using the fsl_spi.c driver. From looking at the scope I seem to have clock and MOSI signals but I don't think I m getting anything back on the MISO line. I have attached the screen grabs of the scope. I have been working with examples provided by the following sdk. SDK_2.2.1_LPCXpresso54114. I m a little uncertain if slave code in the example spi_polling_transfer.c is necessary when talking to an external device. My assumption is that i can just use the SPI_MasterTransferBlocking() function to send a byte value and the device just returns the requested register value. The code is as follows. Note: I m using a GPIO pin for the slave select line where its pulled low when writing and pulled high when finished writing to device. So I have a few questions.
• If I m not using slave select using masterConfig.sselNum but instead use a GPIO pin, does the fsl_spi need to know this?,
• Can a single byte value be sent via SPI_MasterTransferBlocking() and should this automatically fill the rxData array or is a dummy byte necessary?
• Can slave code be ignored? Is the SPI_SlaveInit() code necessary?
Any help would be greatly appreciated. Thanks.
#define EXAMPLE_SPI_MASTER SPI0
#define EXAMPLE_SPI_MASTER_IRQ FLEXCOMM0_IRQn
#define EXAMPLE_SPI_MASTER_CLK_SRC kCLOCK_Flexcomm0
#define EXAMPLE_SPI_MASTER_CLK_FREQ CLOCK_GetFreq(kCLOCK_Flexcomm0)
#define EXAMPLE_SPI_SLAVE SPI0
#define EXAMPLE_SPI_SLAVE_IRQ FLEXCOMM0_IRQn
#define EXAMPLE_SPI_SSEL 2
#define BUFFER_SIZE (16)
static uint8_t srcBuff[2];
static uint8_t destBuff[BUFFER_SIZE];
int main(void)
{
spi_master_config_t userConfig = {0};
uint32_t srcFreq = 0;
uint32_t i = 0;
uint32_t err = 0;
spi_transfer_t xfer = {0};
status_t xferStatus = kStatus_Success;
// uint32_t i = 0U;
// uint32_t err = 0U;
// status_t xferStatus = kStatus_Success;
/* Init the boards */
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0);
RESET_PeripheralReset(kFC0_RST_SHIFT_RSTn);
BOARD_InitPins();
BOARD_BootClockFROHF48M();
BOARD_InitDebugConsole();
GPIO_Configuration();
userConfig.enableLoopback = false;
userConfig.enableMaster = true;
userConfig.polarity = kSPI_ClockPolarityActiveHigh;
userConfig.phase = kSPI_ClockPhaseFirstEdge;
userConfig.direction = kSPI_MsbFirst;
userConfig.baudRate_Bps = 500000U;
SPI_MasterGetDefaultConfig(&userConfig);
srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ;
SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq);
srcBuff[0] = 0x0F;
srcBuff[1] = 0x00;
/*Start Transfer*/
xfer.txData = srcBuff;
xfer.rxData = destBuff;
xfer.dataSize = sizeof(destBuff);
while(1)
{
SPI_CS_Low();
xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
SPI_CS_High();
if( kStatus_Success == xferStatus )
{
testVal++;
}
for(uint32_t i = 100000; i != 0; i--);
}
while (1)
{
}
}
void SPI_CS_Low(){
//Enable CS for pressure sensor.
const gpio_pin_config_t port0_pin10_gpio_config = {kGPIO_DigitalOutput,0,};
GPIO_PinInit(GPIO, PORT0_IDX, PIN10_IDX, &port0_pin10_gpio_config);
}
void SPI_CS_High(){
//Enable CS for pressure sensor.
const gpio_pin_config_t port0_pin10_gpio_config = {kGPIO_DigitalOutput,1,};
GPIO_PinInit(GPIO, PORT0_IDX, PIN10_IDX, &port0_pin10_gpio_config);
}