Problem reading that SPI data in Slave Mode - FRDM-K22F

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem reading that SPI data in Slave Mode - FRDM-K22F

ソリューションへジャンプ
1,661件の閲覧回数
simonbour
Contributor I

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*/

ラベル(2)
0 件の賞賛
返信
1 解決策
1,380件の閲覧回数
Robin_Shen
NXP TechSupport
NXP TechSupport

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)

dspi slave SDK2.4.0 FRDM-K22F.png
If you have two FRDM-K22F boards, you can direct test them.
The readme file will show you how to test these examples.

readme.png

Please refer the images show below and download the latest MCUXpresso SDK.

1 Select and Build MCUXpresso SDK.png2 Download SDK.png3 Download SDK Archive.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,381件の閲覧回数
simonbour
Contributor I

Thank you Robin. Just switched to MCUXpresso and downloaded the latest SDK. Worked out of the box.

Best,

Simon.

0 件の賞賛
返信
1,381件の閲覧回数
Robin_Shen
NXP TechSupport
NXP TechSupport

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)

dspi slave SDK2.4.0 FRDM-K22F.png
If you have two FRDM-K22F boards, you can direct test them.
The readme file will show you how to test these examples.

readme.png

Please refer the images show below and download the latest MCUXpresso SDK.

1 Select and Build MCUXpresso SDK.png2 Download SDK.png3 Download SDK Archive.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信