Assistance Needed with SPI Communication Between IMXRT1064 (Slave) and SAMA5D4 (Master)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Assistance Needed with SPI Communication Between IMXRT1064 (Slave) and SAMA5D4 (Master)

跳至解决方案
1,050 次查看
Jayaganesh
Contributor II

Dear Community,

I am currently working on SPI communication between an IMXRT1064 EVK (configured as the slave) and a SAMA5D4 (configured as the master). On the IMXRT1064, I am using LPSPI1 with the following pin configurations:

  • CLK: GPIO_SD_B0_00
  • CS: GPIO_SD_B0_01
  • MOSI: GPIO_SD_B0_02
  • MISO: GPIO_SD_B0_03

Issue:

When connecting the wires as follows:

  • Master MOSI to Slave MOSI
  • Master MISO to Slave MISO
  • Master SCK to Slave SCK
  • Master CS to Slave CS

The slave only receives and prints 5 zeros (0x00) as output, even though the master is sending 5 bytes (1, 2, 3, 4, 5). Similarly, when the slave sends the same sequence (1, 2, 3, 4, 5) to the master, the master receives only zeros (0x00).

However, if I modify the connections as follows:

  • Master MOSI connected to Slave MISO
  • Master MISO unconnected

The slave correctly receives the data (1, 2, 3, 4, 5) from the master. But, if I additionally connect the master’s MISO pin to the slave’s MOSI pin, the data becomes corrupted on both ends, and neither the master nor the slave receives the correct values.

Additional Concerns:

I suspect there might be an issue with the LPSPI clock configuration on the IMXRT1064. The clock frequency seems to remain fixed at 600 MHz, even when I change the clock divider value. I am unsure whether the LPSPI clock is enabled properly.

Request:

  1. Could you please help me resolve the SPI communication issue?
  2. Could you guide me on verifying and enabling the LPSPI clock configuration on the IMXRT1064?

For reference, I have attached the relevant code below. I would appreciate any insights or suggestions to resolve this issue as soon as possible.

Code:


#include "fsl_device_registers.h"

#include "fsl_debug_console.h"

#include "fsl_lpspi.h"

#include "pin_mux.h"

#include "board.h"

 

#include "fsl_common.h"

#if ((defined FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT))

#include "fsl_intmux.h"

#endif

/*******************************************************************************

* Definitions

******************************************************************************/

/* Slave related */

#define EXAMPLE_LPSPI_SLAVE_BASEADDR (LPSPI1)

#define EXAMPLE_LPSPI_SLAVE_IRQN (LPSPI1_IRQn)

#define EXAMPLE_LPSPI_SLAVE_PCS_FOR_INIT (kLPSPI_Pcs0)

#define EXAMPLE_LPSPI_SLAVE_PCS_FOR_TRANSFER (kLPSPI_SlavePcs0)

 

/* Select USB1 PLL PFD0 (720 MHz) as lpspi clock source */

#define EXAMPLE_LPSPI_CLOCK_SOURCE_SELECT (2U)

/* Clock divider for master lpspi clock source */

#define EXAMPLE_LPSPI_CLOCK_SOURCE_DIVIDER (60U)

#define TRANSFER_SIZE 5U /*! Transfer dataSize */

 

/*******************************************************************************

* Prototypes

******************************************************************************/

/* LPSPI user callback */

void LPSPI_SlaveUserCallback(LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData);

 

/*******************************************************************************

* Variables

******************************************************************************/

uint8_t slaveRxData[TRANSFER_SIZE] = {0U};

uint8_t slaveTxData[TRANSFER_SIZE] = {0U};

 

lpspi_slave_handle_t g_s_handle;

volatile bool isTransferCompleted = false;

 

/*******************************************************************************

* Code

******************************************************************************/

 

void LPSPI_SlaveUserCallback(LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData)

{

if (status == kStatus_Success)

{

PRINTF("This is LPSPI slave transfer completed callback. \r\n");

PRINTF("It's a successful transfer. \r\n\r\n");

}

 

if (status == kStatus_LPSPI_Error)

{

PRINTF("This is LPSPI slave transfer completed callback. \r\n");

PRINTF("Error occurred in this transfer. \r\n\r\n");

}

 

isTransferCompleted = true;

}

 

/*!

* @brief Main function

*/

int main(void)

{

BOARD_ConfigMPU();

BOARD_InitBootPins();

BOARD_InitBootClocks();

BOARD_InitDebugConsole();

 

/*Set clock source for LPSPI*/

CLOCK_SetMux(kCLOCK_LpspiMux, EXAMPLE_LPSPI_CLOCK_SOURCE_SELECT);

CLOCK_SetDiv(kCLOCK_LpspiDiv, EXAMPLE_LPSPI_CLOCK_SOURCE_DIVIDER);

// int clockfreq = CLOCK_GetDiv(kCLOCK_LpspiDiv);

// int clockfreq = CLOCK_GetFreq(kCLOCK_CpuClk);

uint32_t clockfreq = CLOCK_GetFreq(kCLOCK_Lpspi1);

 

//PRINTF("LPSPI board to board polling example.\r\n");

 

uint32_t i;

lpspi_slave_config_t slaveConfig;

lpspi_transfer_t slaveXfer;

 

/*Slave config*/

LPSPI_SlaveGetDefaultConfig(&slaveConfig);

slaveConfig.whichPcs = EXAMPLE_LPSPI_SLAVE_PCS_FOR_INIT;

 

for (i = 0U; i < TRANSFER_SIZE; i++)

{

slaveTxData[i] = i+1;

}

 

LPSPI_SlaveInit(EXAMPLE_LPSPI_SLAVE_BASEADDR, &slaveConfig);

 

LPSPI_SlaveTransferCreateHandle(EXAMPLE_LPSPI_SLAVE_BASEADDR, &g_s_handle, LPSPI_SlaveUserCallback, NULL);

 

while (1)

{

PRINTF("\r\n Slave is running...\r\n");

PRINTF("\r\n Clock freq:- %d\r\n",clockfreq);

 

/* Reset the receive buffer */

for (i = 0U; i < TRANSFER_SIZE; i++)

{

slaveRxData[i] = 0U;

}

 

/* Set slave transfer ready to receive data */

isTransferCompleted = false;

 

slaveXfer.txData = slaveTxData;

slaveXfer.rxData = slaveRxData;

slaveXfer.dataSize = TRANSFER_SIZE;

slaveXfer.configFlags = EXAMPLE_LPSPI_SLAVE_PCS_FOR_TRANSFER | kLPSPI_SlaveByteSwap;

 

/* Slave start receive */

LPSPI_SlaveTransferNonBlocking(EXAMPLE_LPSPI_SLAVE_BASEADDR, &g_s_handle, &slaveXfer);

 

while (!isTransferCompleted)

{

}

 

/* Set slave transfer ready to send back data */

// isTransferCompleted = false;

//

// slaveXfer.txData = slaveRxData;

// slaveXfer.rxData = NULL;

// slaveXfer.dataSize = TRANSFER_SIZE;

// slaveXfer.configFlags = EXAMPLE_LPSPI_SLAVE_PCS_FOR_TRANSFER | kLPSPI_SlaveByteSwap;

//

// /* Slave start send */

// LPSPI_SlaveTransferNonBlocking(EXAMPLE_LPSPI_SLAVE_BASEADDR, &g_s_handle, &slaveXfer);

//

// while (!isTransferCompleted)

// {

// }

 

/* Print out receive buffer */

PRINTF("\r\n Slave received:");

for (i = 0U; i < TRANSFER_SIZE; i++)

{

/* Print 16 numbers in a line */

if ((i & 0x0FU) == 0U)

{

PRINTF("\r\n ");

}

PRINTF(" %02X", slaveRxData[i]);

}

PRINTF("\r\n");

}

}

 

0 项奖励
回复
1 解答
1,018 次查看
Habib_MS
NXP Employee
NXP Employee

Hello @Jayaganesh,
In order to support you better, can you provide me the frame of all LPSPI signals?
Also, as mentioned in the table 14-5 called "System Clock Frequency Values" in the RM, the maximum clock source of LPSPI is 132MHz. Please take in mind this value. At the same time, the function called "CLOCK_GetFreq" that you are currently using in your code, receives an enum called "clock_name_t" instead "clock_ip_name_t" that is the enum of "kCLOCK_Lpspi1".


In the other hand, The SDK (version 2.16) offers the example called "lpspi_loopback" where you can corroborate if your board is working as expected, also if you have two RT1060's boards, you can use the SDK (version 2.16) example called "lpspi_interrupt_b2b_master" with "lpspi_interrupt_b2b_slave". I highly recommend see the readme of the example that you will use. Where is inside the folder called "doc", as shown in the next image:

Habib_MS_0-1734645213070.png

BR
Habib

在原帖中查看解决方案

0 项奖励
回复
3 回复数
961 次查看
Jayaganesh
Contributor II

Thank You Habib for the previous support, i have another doubt! How to set lpspi2 clock to 10mhz or lesser! I used PLL2 pfd2 

CLOCK_InitSysPfd(kCLOCK_Pfd2, 35) and clock divider to 7. I got 33mhz as op but i needed even more lesser as i mentioned earlier! I also tried PLL3 pfd1   CLOCK_InitUsb1Pfd(kCLOCK_Pfd1, 35);   but there was no change in clk value and i also checked by changing 35 to 12, etc! So guide me to set lpspi2 clock to 10mhz or less asap.  
0 项奖励
回复
917 次查看
Habib_MS
NXP Employee
NXP Employee

Hello again @Jayaganesh,
In order to set lpspi2 clock to 10 Mhz or lesser I can see two ways:
1. Modify the dividers what are involucrate in the flow clock.
2. Use Config tools. MCUXpresso Ecosystem offers config tools, where is an integrated suite of configuration tools, is designed to guide customers from first evaluation to production software development.
This link has many trainings that could help you to learn more about how use config tools, also in the same link you can see the file called "MCUXpresso Config Tools User's Guide (IDE)" that could be helpful.
Also, if you experience any issue do not hesitate to let me know.
BR
Habib.

0 项奖励
回复
1,019 次查看
Habib_MS
NXP Employee
NXP Employee

Hello @Jayaganesh,
In order to support you better, can you provide me the frame of all LPSPI signals?
Also, as mentioned in the table 14-5 called "System Clock Frequency Values" in the RM, the maximum clock source of LPSPI is 132MHz. Please take in mind this value. At the same time, the function called "CLOCK_GetFreq" that you are currently using in your code, receives an enum called "clock_name_t" instead "clock_ip_name_t" that is the enum of "kCLOCK_Lpspi1".


In the other hand, The SDK (version 2.16) offers the example called "lpspi_loopback" where you can corroborate if your board is working as expected, also if you have two RT1060's boards, you can use the SDK (version 2.16) example called "lpspi_interrupt_b2b_master" with "lpspi_interrupt_b2b_slave". I highly recommend see the readme of the example that you will use. Where is inside the folder called "doc", as shown in the next image:

Habib_MS_0-1734645213070.png

BR
Habib

0 项奖励
回复