Regarding FLEX IO SPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Regarding FLEX IO SPI

464 Views
RishikeshB
Contributor II

Hello NXP 

I am trying the FLEXIO SPI example and i am checking the waveform on oscilloscope but i am not getting any output where should i check the output

 

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "clockMan1.h"
#include "pin_mux.h"
#include "dmaController1.h"
#include "flexio_spi1.h"
#include "flexio_spi2.h"
#if CPU_INIT_CONFIG
#include "Init_Config.h"
#endif

volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */

#include <stdint.h>
#include <stdbool.h>

/* Declare transfer size */
#define TRANSFER_SIZE 16u

/* Struct that defines RX and TX buffer arrays */
typedef struct
{
uint8_t txBuffer[TRANSFER_SIZE];
uint8_t rxBuffer[TRANSFER_SIZE];
} spi_buffer_t;

/*!
* @brief Initialize the SPI buffer with different values for TX/RX
*
* @Param spiBuffer Pointer to the buffer that will be initialized
* @Param master True if the buffer is used with the master device,
* False if not
*/
void InitSPIBuffer(spi_buffer_t * spiBuffer, bool master)
{
uint8_t cnt;
/* Fill the buffers */
for(cnt = 0U; cnt < TRANSFER_SIZE; cnt++)
{
/* If the master flag is set, then the txBuffer will take the value of the counter,
* else the value will be (TRANSFER_SIZE - Counter).
* This approach is taken to make the data transfer more visible.
*/
spiBuffer->txBuffer[cnt] = ((master == true) ? (cnt) : (TRANSFER_SIZE - cnt));
spiBuffer->rxBuffer[cnt] = 0U;
}
}

/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - __start (startup asm routine)
* - __init_hardware()
* - main()
* - PE_low_level_init()
* - Common_Init()
* - Peripherals_Init()
*/
int main(void)
{

/* Allocate the memory necessary for the FlexIO state structures */
flexio_device_state_t flexIODeviceState;
flexio_spi_master_state_t flexIOSPIState_Master, flexIOSPIState_Slave;
/* Declare the master and slave buffers */
spi_buffer_t masterBuffer, slaveBuffer;
volatile bool isTransferOk = true;
uint8_t cnt;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Initialize and configure clocks
* - Setup system clocks, dividers
* - Configure FlexIO clock, Port clocks
* - see clock manager component for more details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

/* Initialize pins
* - Init FlexIO pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

/* Init FlexIO device */
FLEXIO_DRV_InitDevice(INST_FLEXIO_SPI1, &flexIODeviceState);
/* Call the init function for FlexIO SPI driver */
FLEXIO_SPI_DRV_MasterInit(INST_FLEXIO_SPI1, &flexio_spi1_MasterConfig0, &flexIOSPIState_Master);
/* Initialize Slave instance of the FlexIO SPI driver */
FLEXIO_SPI_DRV_SlaveInit(INST_FLEXIO_SPI2, &flexio_spi2_SlaveConfig0, &flexIOSPIState_Slave);


/* Initialize master and slave buffers */
InitSPIBuffer(&masterBuffer, true);
InitSPIBuffer(&slaveBuffer, false);

/* Signal to the Slave FlexIO SPI driver to start listening. Set the buffers and transfer size */
FLEXIO_SPI_DRV_SlaveTransfer(&flexIOSPIState_Slave, slaveBuffer.txBuffer, slaveBuffer.rxBuffer, TRANSFER_SIZE);

/* Start the transmission of data */
FLEXIO_SPI_DRV_MasterTransferBlocking(&flexIOSPIState_Master,
masterBuffer.txBuffer,
masterBuffer.rxBuffer,
TRANSFER_SIZE,
1000UL);

/* Check if transfer is completed with no errors */
for (cnt = 0U; cnt < TRANSFER_SIZE; cnt++)
{
/* If the values are not equal, break the loop and set isTransferOk to false */
if((masterBuffer.txBuffer[cnt] != slaveBuffer.rxBuffer[cnt]) || (masterBuffer.rxBuffer[cnt] != slaveBuffer.txBuffer[cnt]))
{
isTransferOk = false;
break;
}
}

/* Cast isTransferOk to avoid "set but not used" warnings */
(void)isTransferOk;

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

0 Kudos
1 Reply

455 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi RishikeshB,

Did you follow the guide of FLEXIO SPI RTM3.0.3 flexio_spi_s32k148?(file:///C:/NXP/S32DS_ARM_v2.2/S32DS/software/S32SDK_S32K1xx_RTM_3.0.0/doc/html_S32K148/flexio_spi_s3...

Make sure Hardware Wiring, what's the value of isTransferOk after running the example?

FLEXIO SPI RTM3.0.3 flexio_spi_s32k148.png

Have you try to capture the SPI data by using logic analyzer? (It's rather strange why I can measure the waveform, but you can't. Maybe you should go to this thread and make sure the oscilloscope and S32K148EVB are working properly.)


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos