Hi All,
I recently started to play with the FRDM-K22F devboard. I used the KSDK v1.3 documentation and managed to print data through the UART, set interruptions through one of the push buttons, and toggle the on board LED, but I cannot get the SPI bus to read data as a Slave. I based the code on this sample from the K64 board (https://community.nxp.com/docs/DOC-103944) and also read the KSDK manual. Everything seems to checkout on paper.
Experimental setup:
- KSDK v1.3
- FRDM-K22F devboard
- Arduino UNO (set as Master, sending 0x55 in 1 second intervals. Clock phase/polarity checked with scope)
- Kinetis code (see main.c below)
I tried, both SPI instances, and they hang at the DSPI_DRV_SlaveTransferBlocking() function. Then switched to the non-blocking variant and printed the Error output which prints "4" or "busy".
This should work "out of the box", I have no idea where to go from here.
#include "fsl_device_registers.h"
#include "board.h"
#include "pin_mux.h"
#include "fsl_clock_manager.h"
#include "fsl_debug_console.h"#include "fsl_dspi_slave_driver.h"
#include "fsl_dspi_hal.h"#include <stdio.h>
//SPI input buffer
uint8_t spiSinkBuffer;int main(void)
{/* enable clock for PORTs */
CLOCK_SYS_EnablePortClock(PORTA_IDX);
CLOCK_SYS_EnablePortClock(PORTB_IDX);
CLOCK_SYS_EnablePortClock(PORTC_IDX);
CLOCK_SYS_EnablePortClock(PORTE_IDX);
/* Init board clock */
BOARD_ClockInit();/*Debug UART init */
dbg_uart_init();
printf("\nPress SW2 to Toggle LED. \r\n");// Configure pin (sw2) interrupt
switchPins[0].config.interrupt = kPortIntFallingEdge;
// Initialize GPIO driver
GPIO_DRV_Init(switchPins, ledPins);//SPI Config
configure_spi_pins(SPI0_IDX);// Interrupt driven
dspi_slave_state_t dspiSlaveState;// update configs
dspi_slave_user_config_t slaveUserConfig;
slaveUserConfig.dataConfig.clkPhase = kDspiClockPhase_SecondEdge;
slaveUserConfig.dataConfig.clkPolarity = kDspiClockPolarity_ActiveHigh;
slaveUserConfig.dataConfig.bitsPerFrame = 8;
slaveUserConfig.dataConfig.direction = kDspiMsbFirst;
slaveUserConfig.dummyPattern = DSPI_DEFAULT_DUMMY_PATTERN;
// init the slave (interrupt driven)
DSPI_DRV_SlaveInit(SPI0_IDX, &dspiSlaveState, &slaveUserConfig);// Main loop
while(1)
{
GPIO_SW_DELAY;
//printf("IN\n\r");
//Blocking Transfer
/*
dspi_status_t Error = DSPI_DRV_SlaveTransferBlocking(SPI0_IDX, //spi instance
NULL, //send buffer address
&spiSinkBuffer, //received buffer address
1, //number of bytes to send and receive
OSA_WAIT_FOREVER); //timeout OSA_WAIT_FOREVER = blocking
*/
//Non-blocking Transfer
dspi_status_t Error = DSPI_DRV_SlaveTransfer(SPI0_IDX, //spi instance
NULL, //send buffer address
&spiSinkBuffer, //received buffer address
1); //number of bytes to send and receive
if (Error == kStatus_DSPI_Success)
{
//Send over UART
//dspiSlaveState.isTransferInProgress = 0;
printf("SPI Buffer: 0x%X\n\r",spiSinkBuffer);
}printf("Error Code %d\n\r",Error);
}
return 0;
}//Define PORTC_IRQHandler (sw2)
void PORTC_IRQHandler()
{
static uint8_t count = 0;
GPIO_DRV_ClearPinIntFlag (kGpioSW2); // Clear IRQ flag
GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_RED); // Toggle blue LED
printf("0x%X\n\r",count++);
GPIO_SW_DELAY;
}
/*EOF*/
Solved! Go to Solution.
Hi simonbour,
Please download the latest MCUXpresso SDK_2.4.0 FRDM-K22F, then you will find several dspi slave examples.(...\FRDM-K22F\boards\frdmk22f\driver_examples\dspi)
If you have two FRDM-K22F boards, you can direct test them.
The readme file will show you how to test these examples.
Please refer the images show below and download the latest MCUXpresso SDK.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you Robin. Just switched to MCUXpresso and downloaded the latest SDK. Worked out of the box.
Best,
Simon.
Hi simonbour,
Please download the latest MCUXpresso SDK_2.4.0 FRDM-K22F, then you will find several dspi slave examples.(...\FRDM-K22F\boards\frdmk22f\driver_examples\dspi)
If you have two FRDM-K22F boards, you can direct test them.
The readme file will show you how to test these examples.
Please refer the images show below and download the latest MCUXpresso SDK.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------