TC397 SPI_DMA_1_KIT_TC397_TFT demo 中 关于SPI

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Bertxu
Level 3
Level 3
250 sign-ins 10 replies posted 100 sign-ins

hi,

请问当SPI Master 或slave传输数据时   使用 IfxQspi_SpiMaster_getStatus到的状态为busy时,有没有办法清除掉此状态? 2.现在发送数据和接收数据时,有时正常,有时处于busy状态,发送接收数据失败,出现此问题的原因?

多谢!

0 Likes
1 Solution
Jeremy_Z
Moderator
Moderator
Moderator
1000 replies posted 250 sign-ins 100 likes received

Hi @Bertxu ,

我觉得可能跟硬件有关,代码保持原样,同时将Master和Slave各个引脚连接后,用示波器或者逻辑分析仪看一下MTSR脚的的变化过程。

BR,

Jeremy

View solution in original post

0 Likes
6 Replies
Jeremy_Z
Moderator
Moderator
Moderator
1000 replies posted 250 sign-ins 100 likes received

Hi @Bertxu ,

1)请问当SPI Master 或slave传输数据时   使用 IfxQspi_SpiMaster_getStatus到的状态为busy时,有没有办法清除掉此状态?

-- 没有,因为这个信号量用于同步传输过程是否完成。

2)你的意思是TC397 SPI_DMA_1_KIT_TC397_TFT工程运行过程跟预期不一致?

BR,

Jeremy

0 Likes
Bertxu
Level 3
Level 3
250 sign-ins 10 replies posted 100 sign-ins

TC397 SPI_DMA_1_KIT_TC397_TFT 使用此demo时,我们把slave端在code中移除,只留master端,物理连接也把master与slave端断开,此时让master 端发送数据,现在spi的clock用示波器能量到,但MOSI对应的pin只能量到3V不变化,理论上有发送数据就应该能量到data pin的变化,这是什么原因造成的?

看log 没发现异常:如下

08:55:22.884]收←◆1A 55 55 55 55 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 2A 77 FF FF FF FF

1A,2A--------触发中断时发的(IfxQspi_SpiMaster_exchange执行此函数)

55 55 55 55 为发送数据。

77 77 77 77 77 77 ........(SpiMaster busy时的等待)

FF FF FF FF  为 Master接收数据

对应的code:


/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "SPI_DMA.h"
#include "IfxPort.h"
#include "ASCLIN_UART.h"
#include <Qspi/SpiSlave/IfxQspi_SpiSlave.h>
#include "Bsp.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define QSPI2_MASTER &MODULE_QSPI2 /* SPI Master Hardware module */
#define QSPI3_SLAVE &MODULE_QSPI3 /* SPI Slave Hardware module */

#define LED_D110 &MODULE_P13,3 /* LED D110 Port, Pin definition */

#define ISR_PRIORITY_QSPI2_TX 1 /* Define the QSPI2 transmit interrupt priority */
#define ISR_PRIORITY_QSPI2_RX 2 /* Define the QSPI2 receive interrupt priority */
#define ISR_PRIORITY_QSPI2_ER 10 /* Define the QSPI2 error interrupt priority */

#define ISR_PRIORITY_QSPI3_TX 3 /* Define the QSPI3 transmit interrupt priority */
#define ISR_PRIORITY_QSPI3_RX 4 /* Define the QSPI3 receive interrupt priority */
#define ISR_PRIORITY_QSPI3_ER 11 /* Define the QSPI3 error interrupt priority */

#define ISR_PRIORITY_DMA_CH1 50 /* Define the DMA channel1 interrupt priority */
#define ISR_PRIORITY_DMA_CH2 51 /* Define the DMA channel2 interrupt priority */
#define ISR_PRIORITY_DMA_CH3 52 /* Define the DMA channel3 interrupt priority */
#define ISR_PRIORITY_DMA_CH4 53 /* Define the DMA channel4 interrupt priority */

#define ISR_PROVIDER_QSPI2 IfxSrc_Tos_cpu0 /* Define the QSPI2 interrupt provider */
#define ISR_PROVIDER_QSPI3 IfxSrc_Tos_cpu0 /* Define the QSPI3 interrupt provider */

#define ISR_PROVIDER_DMA_CH1 IfxSrc_Tos_cpu0 /* Define the DMA Channel1 interrupt provider */
#define ISR_PROVIDER_DMA_CH2 IfxSrc_Tos_cpu0 /* Define the DMA Channel2 interrupt provider */
#define ISR_PROVIDER_DMA_CH3 IfxSrc_Tos_cpu0 /* Define the DMA Channel3 interrupt provider */
#define ISR_PROVIDER_DMA_CH4 IfxSrc_Tos_cpu0 /* Define the DMA Channel4 interrupt provider */

#define MASTER_CHANNEL_BAUDRATE 1000000 /* Master channel baud rate */
#define GPIOp220 &MODULE_P22,0
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
qspiDma g_qspiDma; /* Global handle for QSPI communication */
uint32 k;
/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
static void initQSPI2Master(void);
static void initQSPI2MasterChannel(void);
static void initQSPI2MasterBuffers(void);
static void initQSPI3Slave(void);
static void initQSPI3SlaveBuffers(void);
static void initQSPI(void);
static void initLED(void);

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
IFX_INTERRUPT(QSPI2ErrorISR, 0, ISR_PRIORITY_QSPI2_ER); /* SPI Master Error Interrupt definition */
IFX_INTERRUPT(QSPI3ErrorISR, 0, ISR_PRIORITY_QSPI3_ER); /* SPI Slave Error Interrupt definition */
IFX_INTERRUPT(DMAChn1ISR, 0, ISR_PRIORITY_DMA_CH1); /* DMA Channel 1 Interrupt definition */
IFX_INTERRUPT(DMAChn2ISR, 0, ISR_PRIORITY_DMA_CH2); /* DMA Channel 2 Interrupt definition */
IFX_INTERRUPT(DMAChn3ISR, 0, ISR_PRIORITY_DMA_CH3); /* DMA Channel 3 Interrupt definition */
IFX_INTERRUPT(DMAChn4ISR, 0, ISR_PRIORITY_DMA_CH4); /* DMA Channel 4 Interrupt definition */

/* Handle QSPI2 Error interrupt */
void QSPI2ErrorISR(void)
{
IfxCpu_enableInterrupts();
IfxQspi_SpiMaster_isrError(&g_qspiDma.spiMaster);
}

/* Handle QSPI3 Error interrupt */
void QSPI3ErrorISR(void)
{
IfxCpu_enableInterrupts();
IfxQspi_SpiSlave_isrError(&g_qspiDma.spiSlave);
}


/* Handle DMA Channel 1 interrupt */
void DMAChn1ISR(void)
{
IfxCpu_enableInterrupts();
IfxQspi_SpiMaster_isrDmaTransmit(&g_qspiDma.spiMaster);
send_ASCLIN_UART_message(0x1a);
Arry_send_ASCLIN_UART_message(SPI_BUFFER_SIZE,&g_qspiDma.qspiBuffer.spiMasterTxBuffer[0]);
}


/* Handle DMA Channel 2 interrupt */
void DMAChn2ISR(void)
{
IfxCpu_enableInterrupts();
IfxQspi_SpiMaster_isrDmaReceive(&g_qspiDma.spiMaster);
send_ASCLIN_UART_message(0x2a);

}


/* Handle DMA Channel 3 interrupt */
void DMAChn3ISR(void)
{
IfxCpu_enableInterrupts();
IfxQspi_SpiSlave_isrDmaTransmit(&g_qspiDma.spiSlave);
send_ASCLIN_UART_message(0x33);
}


/* Handle DMA Channel 4 interrupt */
void DMAChn4ISR(void)
{
IfxCpu_enableInterrupts();
IfxQspi_SpiSlave_isrDmaReceive(&g_qspiDma.spiSlave);
send_ASCLIN_UART_message(0x44);
Arry_send_ASCLIN_UART_message(SPI_BUFFER_SIZE,&g_qspiDma.qspiBuffer.spiSlaveRxBuffer[0]);
}

/* This function initializes QSPI2 in master mode */
static void initQSPI2Master(void)
{
IfxQspi_SpiMaster_Config spiMasterConfig; /* Define the Master Configuration */

IfxQspi_SpiMaster_initModuleConfig(&spiMasterConfig, QSPI2_MASTER); /* Initialize it with default values */

const IfxQspi_SpiMaster_Pins qspi2Masterpins = {
&IfxQspi2_SCLK_P15_3_OUT, IfxPort_OutputMode_pushPull, /* SCLK Pin (CLK) */
&IfxQspi2_MTSR_P15_5_OUT, IfxPort_OutputMode_pushPull, /* Master Transmit Slave Receive Pin (MOSI) */
&IfxQspi2_MRSTA_P15_4_IN, IfxPort_InputMode_pullDown, /* Master Receive Slave Transmit Pin (MISO) */
IfxPort_PadDriver_cmosAutomotiveSpeed3 /* Pad driver mode */
};
spiMasterConfig.pins = &qspi2Masterpins; /* Assign Master Pins */

spiMasterConfig.dma.useDma = TRUE;
spiMasterConfig.dma.txDmaChannelId = IfxDma_ChannelId_1;
spiMasterConfig.dma.rxDmaChannelId = IfxDma_ChannelId_2;

spiMasterConfig.base.txPriority = ISR_PRIORITY_DMA_CH1;
spiMasterConfig.base.rxPriority = ISR_PRIORITY_DMA_CH2;
spiMasterConfig.base.erPriority = ISR_PRIORITY_QSPI2_ER;
spiMasterConfig.base.isrProvider = ISR_PROVIDER_QSPI2;

/* Initialize the QSPI Master module using the user configuration */
IfxQspi_SpiMaster_initModule(&g_qspiDma.spiMaster, &spiMasterConfig);
}

/* This function initializes QSPI2 channel. */
static void initQSPI2MasterChannel(void)
{
IfxQspi_SpiMaster_ChannelConfig spiMasterChannelConfig; /* Define the Master Channel Configuration */

IfxQspi_SpiMaster_initChannelConfig(&spiMasterChannelConfig, &g_qspiDma.spiMaster); /* Initialize it with default values */

spiMasterChannelConfig.base.baudrate = MASTER_CHANNEL_BAUDRATE; /* Set SCLK frequency to 1 MHz */

const IfxQspi_SpiMaster_Output qspi2SlaveSelectQspi3 = {
&IfxQspi2_SLSO0_P15_2_OUT, IfxPort_OutputMode_pushPull, /* Slave Select Pin (CS) */
IfxPort_PadDriver_cmosAutomotiveSpeed1 /* Pad driver mode */
};
spiMasterChannelConfig.sls.output = qspi2SlaveSelectQspi3;
// spiMasterChannelConfig.mode=IfxQspi_SpiMaster_Mode_short;

 

/* Initialize the QSPI Master channel using the user configuration */
IfxQspi_SpiMaster_initChannel(&g_qspiDma.spiMasterChannel, &spiMasterChannelConfig);
//spiMasterChannelConfig.mode == IfxQspi_SpiMaster_Mode_longContinuous;

}

/* This function initializes Master SW buffers */
static void initQSPI2MasterBuffers(void)
{
for (uint32 i = 0; i < SPI_BUFFER_SIZE; i++)
{
/* Fill the SPI Master TX Buffer */
g_qspiDma.qspiBuffer.spiMasterTxBuffer[i] = 0x55;//(uint8)(i + 1);
/* Clear the SPI Master RX Buffer */
g_qspiDma.qspiBuffer.spiMasterRxBuffer[i] = 0;
}
}
/* This function initializes Master SW buffers */
static void clearQSPI2MasterBuffers(void)
{
for (uint32 i = 0; i < SPI_BUFFER_SIZE; i++)
{
/* Fill the SPI Master TX Buffer */

/* Clear the SPI Master RX Buffer */
g_qspiDma.qspiBuffer.spiMasterRxBuffer[i] = 0;
}
}
/* This function initializes QSPI3 in Slave mode */
static void initQSPI3Slave(void)
{
IfxQspi_SpiSlave_Config spiSlaveConfig; /* Define the Slave Configuration */

IfxQspi_SpiSlave_initModuleConfig(&spiSlaveConfig, QSPI3_SLAVE); /* Initialize it with default values */

/* Enable DMA mode*/
spiSlaveConfig.dma.useDma = TRUE;
/* Set SPI slave DMA channels */
spiSlaveConfig.dma.txDmaChannelId = IfxDma_ChannelId_3;
spiSlaveConfig.dma.rxDmaChannelId = IfxDma_ChannelId_4;

/* Configure SPI slave interrupts */
spiSlaveConfig.base.txPriority = ISR_PRIORITY_DMA_CH3;
spiSlaveConfig.base.rxPriority = ISR_PRIORITY_DMA_CH4;
spiSlaveConfig.base.erPriority = ISR_PRIORITY_QSPI2_ER;
spiSlaveConfig.base.isrProvider = ISR_PROVIDER_QSPI2;

const IfxQspi_SpiSlave_Pins qspi3Slavepins = {
&IfxQspi3_SCLKA_P02_7_IN, IfxPort_InputMode_pullDown, /* SCLK Pin (CLK) */
&IfxQspi3_MTSRA_P02_6_IN, IfxPort_InputMode_pullDown, /* Master Transmit Slave Receive Pin (MOSI) */
&IfxQspi3_MRST_P02_5_OUT, IfxPort_OutputMode_pushPull, /* Master Receive Slave Transmit Pin (MISO) */
&IfxQspi3_SLSIA_P02_4_IN, IfxPort_InputMode_pullDown, /* Slave Select Pin (CS) */
IfxPort_PadDriver_cmosAutomotiveSpeed3 /* Pad driver mode */
};

/* Assign Slave Pins */
spiSlaveConfig.pins = &qspi3Slavepins;

/* Initialize QSPI Slave module */
IfxQspi_SpiSlave_initModule(&g_qspiDma.spiSlave, &spiSlaveConfig);
}

/* Initialize Slave SW buffers */
static void initQSPI3SlaveBuffers(void)
{
for (uint32 i = 0; i < SPI_BUFFER_SIZE; i++)
{
/* Fill the SPI Slave TX Buffer */
g_qspiDma.qspiBuffer.spiSlaveTxBuffer[i] = (uint8)(i + 0x64);
/* Clear the SPI Slave RX Buffer */
g_qspiDma.qspiBuffer.spiSlaveRxBuffer[i] = 0;
}
}

/* This function initializes the LED */
static void initLED(void)
{
/* Set the port pin 13.3 (to which the LED D110 is connected) to output push-pull mode */
IfxPort_setPinModeOutput(LED_D110, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinModeOutput(GPIOp220, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
/* Turn off the LED (LED is low-level active) */
// IfxPort_setPinLow(GPIOp220);
IfxPort_setPinHigh(LED_D110);
}

/* This function initializes the QSPI modules */
static void initQSPI(void)
{
/* Firstly initialize the Slave */
//initQSPI3Slave();
// initQSPI3SlaveBuffers();

/* Secondly initialize the Master */
initQSPI2Master();
initQSPI2MasterChannel();
initQSPI2MasterBuffers();
}

/* This function initializes the SPI and the LED called from Cpu0_Main */
void initPeripherals(void)
{
init_ASCLIN_UART();
initLED();
initQSPI();

}


/* This function ensures the QSPI communication between Master and Slave and checks whether
* the data transfer was correct or not
*/
void transferData(void)
{

uint32 data=0x91929394 ;//=0x6762;
uint32 i;
uint32 error = 0;


IfxPort_setPinHigh(GPIOp220);
IfxQspi_SpiMaster_exchange(&g_qspiDma.spiMasterChannel, &g_qspiDma.qspiBuffer.spiMasterTxBuffer[0],
&g_qspiDma.qspiBuffer.spiMasterRxBuffer[0], SPI_BUFFER_SIZE);
// waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 1000)); /* Wait 500 milliseconds */
//
while(IfxQspi_SpiMaster_getStatus(&g_qspiDma.spiMasterChannel) == SpiIf_Status_busy)
{
send_ASCLIN_UART_message(0x77);
}
Arry_send_ASCLIN_UART_message(SPI_BUFFER_SIZE,&g_qspiDma.qspiBuffer.spiMasterRxBuffer[0]);
IfxPort_setPinLow(GPIOp220);



/* Switch on the LED D110 in case of no errors (LED is low-level active) */
if(error == 0)
{
IfxPort_setPinLow(LED_D110);
}
}

0 Likes
lock attach
Attachments are accessible only for community members.
Bertxu
Level 3
Level 3
250 sign-ins 10 replies posted 100 sign-ins

请帮忙看一下,在没有连接Slave端时,测量Master端的clock 和data信号(图片如附件),如下是否正常?

 

0 Likes
Jeremy_Z
Moderator
Moderator
Moderator
1000 replies posted 250 sign-ins 100 likes received

Hi @Bertxu ,

看起来黄色是Clock信号, 绿色是data信号,感觉data信号的电平有点怪怪的。

你是在KIT_TC397上测试的吗?

BR,

Jeremy

0 Likes
lock attach
Attachments are accessible only for community members.

是在kit_tc397 的EVB上测试的,slave端不连接,使用的demo  code,SPI demo code SPI的配置Master是使用是:

const IfxQspi_SpiMaster_Pins qspi2Masterpins = {
&IfxQspi2_SCLK_P15_3_OUT, IfxPort_OutputMode_pushPull, /* SCLK Pin (CLK) */
&IfxQspi2_MTSR_P15_5_OUT, IfxPort_OutputMode_pushPull, /* Master Transmit Slave Receive Pin (MOSI) */
&IfxQspi2_MRSTA_P15_4_IN, IfxPort_InputMode_pullDown, /* Master Receive Slave Transmit Pin (MISO) */
IfxPort_PadDriver_cmosAutomotiveSpeed3 /* Pad driver mode */
};

当我们使用例外一组SPI的配置Master ,测量出来得波形图看起来比较正常,波形图如附件:这可能是原因造成的呢?

const IfxQspi_SpiMaster_Pins qspi2Masterpins = {
&IfxQspi0_SCLK_P20_13_OUT, IfxPort_OutputMode_pushPull, /* SCLK Pin (CLK) */
&IfxQspi0_MTSR_P20_14_OUT, IfxPort_OutputMode_pushPull, /* Master Transmit Slave Receive Pin (MOSI) */
&IfxQspi0_MRSTA_P20_12_IN, IfxPort_InputMode_pullDown, /* Master Receive Slave Transmit Pin (MISO) */
IfxPort_PadDriver_cmosAutomotiveSpeed2 /* Pad driver mode */
};

 

0 Likes
Jeremy_Z
Moderator
Moderator
Moderator
1000 replies posted 250 sign-ins 100 likes received

Hi @Bertxu ,

我觉得可能跟硬件有关,代码保持原样,同时将Master和Slave各个引脚连接后,用示波器或者逻辑分析仪看一下MTSR脚的的变化过程。

BR,

Jeremy

0 Likes