HC32F460 SPI用作从设备接收数据,为什么只能进一次中断,请大佬们帮我看下程序
static void Spi_Config(void)
{
stc_spi_init_t stcSpiInit;
stc_irq_regi_conf_t stcIrqRegiConf;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcSpiInit);
MEM_ZERO_STRUCT(stcIrqRegiConf);
/* Configuration peripheral clock */
PWC_Fcg1PeriphClockCmd(SPI_UNIT_CLOCK, Enable);
/* Configuration SPI pin */
PORT_SetFunc(SPI_SCK_PORT, SPI_SCK_PIN, SPI_SCK_FUNC, Disable);
PORT_SetFunc(SPI_NSS_PORT, SPI_NSS_PIN, SPI_NSS_FUNC, Disable);
PORT_SetFunc(SPI_MOSI_PORT, SPI_MOSI_PIN, SPI_MOSI_FUNC, Disable);
// PORT_SetFunc(SPI_MISO_PORT, SPI_MISO_PIN, SPI_MISO_FUNC, Disable);
/* Configuration SPI structure */
stcSpiInit.enClkDiv = SpiClkDiv2;
stcSpiInit.enFrameNumber = SpiFrameNumber1;
stcSpiInit.enDataLength = SpiDataLengthBit8;
stcSpiInit.enFirstBitPosition = SpiFirstBitPositionMSB;
stcSpiInit.enSckPolarity = SpiSckIdleLevelLow;
stcSpiInit.enSckPhase = SpiSckOddSampleEvenChange;
stcSpiInit.enReadBufferObject = SpiReadReceiverBuffer;
stcSpiInit.enWorkMode = SpiWorkMode4Line;
stcSpiInit.enTransMode = SpiTransFullDuplex;
stcSpiInit.enCommAutoSuspendEn = Disable;
stcSpiInit.enModeFaultErrorDetectEn = Disable;
stcSpiInit.enParitySelfDetectEn = Disable;
stcSpiInit.enParityEn = Disable;
stcSpiInit.enParity = SpiParityEven;
//#ifdef SPI_MASTER_MODE
// stcSpiInit.enMasterSlaveMode = SpiModeMaster;
// stcSpiInit.stcDelayConfig.enSsSetupDelayOption = SpiSsSetupDelayCustomValue;
// stcSpiInit.stcDelayConfig.enSsSetupDelayTime = SpiSsSetupDelaySck1;
// stcSpiInit.stcDelayConfig.enSsHoldDelayOption = SpiSsHoldDelayCustomValue;
// stcSpiInit.stcDelayConfig.enSsHoldDelayTime = SpiSsHoldDelaySck1;
// stcSpiInit.stcDelayConfig.enSsIntervalTimeOption = SpiSsIntervalCustomValue;
// stcSpiInit.stcDelayConfig.enSsIntervalTime = SpiSsIntervalSck6PlusPck2;
// stcSpiInit.stcSsConfig.enSsValidBit = SpiSsValidChannel0;
// stcSpiInit.stcSsConfig.enSs0Polarity = SpiSsLowValid;
//#endif
#ifdef SPI_SLAVE_MODE
stcSpiInit.enMasterSlaveMode = SpiModeSlave;
stcSpiInit.stcSsConfig.enSsValidBit = SpiSsValidChannel0;
stcSpiInit.stcSsConfig.enSs0Polarity = SpiSsLowValid;
#endif
SPI_Init(SPI_UNIT, &stcSpiInit);
/* SPI1 rx interrupt */
stcIrqRegiConf.enIntSrc = SPI_RX_INT_SOURCE;
stcIrqRegiConf.enIRQn = Int006_IRQn;
stcIrqRegiConf.pfnCallback = &SpiRx_IrqCallback;
/* Registration IRQ */
// enIrqResign(Int006_IRQn);
enIrqRegistration(&stcIrqRegiConf);
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
NVIC_EnableIRQ(stcIrqRegiConf.enIRQn);
}
static void SpiRx_IrqCallback(void)
{
if (u8RxIndex < u16BufferLen)
{
u8RxBuffer[u8RxIndex++] = SPI_ReceiveData8(SPI_UNIT);
}
else
{
SPI_IrqCmd(SPI_UNIT, SpiIrqReceive, Disable);
}
}
int32_t main(void)
{
/* BSP initialization */
BSP_CLK_Init();
BSP_GPIO_Init();
Spi_Config();
/* Get tx buffer length */
Spi_DmaConfig();
while (1)
{
SPI_IrqCmd(SPI_UNIT, SpiIrqReceive, Enable);
SPI_Cmd(SPI_UNIT, Enable);
while (u8RxIndex < u16BufferLen)
{
}
SPI_IrqCmd(SPI_UNIT, SpiIrqReceive, Disable);
SPI_Cmd(SPI_UNIT, Disable);
}
} |