我知道这个话题(DMA & SPI)已经在微芯片论坛的众多线程中讨论过了,实际上我已经阅读了关键字“ dma“并阅读关于dma & spi的所有主题。在PIC32上通过DMA接收SPI数据
,我仍然坚持我的问题,我希望有人能帮助我:)
这是问题所在。
我的芯片是PIC32MX775F512H。 我想通过DMA接收(只接收)使用SPI的数据。 由于您不能在SPI中接收数据,并且只有在写入SPIBUF(SPI1ABUF)时,SPI内核才开始翻转SPI时钟,因此我试图使用2个DMA通道接收数据。 DMA_CHANNEL1发送部分。 DMA_CHANNEL2用于接收部分。
我复制从http://www.microchip.com/forums/tm.aspx?tree=true&high=&m=562453&mpage=1#
粘贴代码,并试图使它没有任何的运气工作。它只接收几个字节(5或6)。
对于这两个dma通道,我都设置了事件启用标志为DMA_EV_BLOCK_DONE,没有发生中断。
你有什么想法吗?
这里是我使用的代码:
int Spi_recv_via_DMA(SPI_simple_master_class* SPI_Port, int8u *in_bytes, int16u num_bytes2)
{
DmaChannel dmaTxChn=DMA_CHANNEL1;
DmaChannel dmaRxChn=DMA_CHANNEL2;
SpiChannel spiTxChn=SPI_Port->channel;
int8u dummy_input;
DmaChnOpen(dmaTxChn, DMA_CHN_PRI3, DMA_OPEN_DEFAULT);
DmaChnOpen(dmaRxChn, DMA_CHN_PRI3, DMA_OPEN_DEFAULT);
DmaChnSetEventControl(dmaTxChn, DMA_EV_START_IRQ_EN | DMA_EV_START_IRQ(_SPI1A_RX_IRQ));
DmaChnSetEventControl(dmaRxChn, DMA_EV_START_IRQ_EN | DMA_EV_START_IRQ(_SPI1A_RX_IRQ));
DmaChnClrEvFlags(dmaTxChn, DMA_EV_ALL_EVNTS);
DmaChnClrEvFlags(dmaRxChn, DMA_EV_ALL_EVNTS);
DmaChnSetEvEnableFlags(dmaRxChn, DMA_EV_BLOCK_DONE);
DmaChnSetEvEnableFlags(dmaTxChn, DMA_EV_BLOCK_DONE);
//SpiChnClrTxIntFlag(spiTxChn);
//SpiChnClrRxIntFlag(spiTxChn);
DmaChnSetTxfer(dmaTxChn, tx_dummy_buffer, (void *)&SPI1ABUF, num_bytes2, 1, 1);
DmaChnSetTxfer(dmaRxChn, (void *)&SPI1ABUF, in_bytes, 1, num_bytes2, 1);
while ((SPI1ASTAT & SPIRBE) == 0)
dummy_input = SPI1ABUF;
SPI1ASTAT &= ~SPIROV;
DmaRxIntFlag = 0;
DmaChnEnable(dmaRxChn);
DmaChnStartTxfer(dmaTxChn, DMA_WAIT_NOT, 0);
while(!DmaRxIntFlag);
return 1;
}
与这两个中断处理程序:
// handler for the DMA channel 1 interrupt
void __ISR(_DMA1_VECTOR, ipl5) DmaHandler1(void)
{
int evFlags; // event flags when getting the interrupt
//LED_On(LED_CFG);
INTClearFlag(INT_SOURCE_DMA(DMA_CHANNEL1)); // acknowledge the INT controller, we're servicing int
evFlags=DmaChnGetEvFlags(DMA_CHANNEL1); // get the event flags
if(evFlags&DMA_EV_BLOCK_DONE)
{ // just a sanity check. we enabled just the DMA_EV_BLOCK_DONE transfer done interrupt
DmaTxIntFlag = 1;
DmaChnClrEvFlags(DMA_CHANNEL1, DMA_EV_BLOCK_DONE);
}
// LED_Off(LED_CFG);
}
void __ISR(_DMA2_VECTOR, ipl5) DmaHandler2(void)
{
int evFlags; // event flags when getting the interrupt
INTClearFlag(INT_SOURCE_DMA(DMA_CHANNEL2)); // acknowledge the INT controller, we're servicing int
evFlags=DmaChnGetEvFlags(DMA_CHANNEL2); // get the event flags
if(evFlags&DMA_EV_BLOCK_DONE)
{ // just a sanity check. we enabled just the DMA_EV_BLOCK_DONE transfer done interrupt
DmaRxIntFlag = 1;
DmaChnClrEvFlags(DMA_CHANNEL2, DMA_EV_BLOCK_DONE);
}
}
所以我最终在该行永远等待:而(!DmaRxIntFlag);
我在中断向量中放置了断点,它们从不被调用。
这是几个寄存器不断持续等待时的状态:
DMACON 0x0000C800
DMASTAT 00000001
我使用SPI1A端口,所以SPI1ABUF和_SPI1A_RX_IRQ
DCH1SPTR 0x5的
DCH1SSIZ 0x2B
DCH2DPTR 0x6
DCH2DSI ž0x2B访问
DCH2CON 0x00008083
DCH2ECON 0x1B10
DCH2INT 0x00800C4
DCH2SSA 0x1F805820
DCH2DSA 0x00000620
通道1是用来传输
频道2,用于接收
SPI连接的另一端是什么类型的器件?我不得不假设它已经处于发送数据的模式中了? –