像往常一样,论坛软件不允许我张贴。我必须拆分它,不能嵌入图像。悲伤:请手动点击附件。第一幅图像显示了带有正确数据的READ,但不希望出现间隙。(SPI-MOSI=SPI-SDO(TX),SPI-MISO=SPI-SDI(RX))正确的数据是0x3C,0x3F,0x78,0x6D,……如SPI RX Pin所示,在第二图像中显示了其他实验方法(使用TX作为DMA触发器)。逻辑分析仪“看到”正确的BYTEX03C,0x3F,0x78,0x6D…在SPI总线上,但是DMA将把附加的0xff作为第一个字节放入存储器。NULLW特性的文档说“对DMADST的每次写入都向DMASRC发起一个虚拟写入”。在第一幅图像中,可以正确地看到,在SPI-MOS上可以看到“对DMASRC的写入”。我(第0频道)。因此,在SPI-RX和伪写到SP-TX之间有一个“1”字节的“移位”。在第二个图像中,可以看出这种移位是2字节,这可能是由于错误的DMA触发条件。但我不知道哪一个是CORRET。下面的代码用于进行512字节的传输。NTYRX使用SPI RX或SPI TX作为DMA触发器,这个定义也用于SPI初始化,选择DMA触发器(SPI中断位)SPI初始化(部分)现在的问题是,是否有任何想法,我可以在DX触发时消除RX、O上的间隙问题。r在TX上进行DMA触发时,如何解决附加字节的问题。在这两种情况下,我的DMA触发器配置可能都是错误的,但我不知道哪里出错。最终的目标只是以8Mhz的速度进行传输。
以上来自于百度翻译
以下为原文
As usual the forum software does not allow me to post. I have to split it and cannot embed the images.sad: Please click the attachments manually.
The first image shows the READ with correct data, but undesired gap.
(SPI-MOSI = SPI-SDO (TX) , SPI-MISO = SPI-SDI (RX) )
The correct data is 0x3C, 0x3F, 0x78, 0x6D, ... as seen on the SPI RX pin
The other experimental method (using TX as DMA trigger) is shown in the second image. The Logic Analyzer "sees" the correct bytes
0x3c, 0x3F, 0x78, 0x6D ... on the SPI bus, but the DMA will place an additional 0xff as the first byte into the memory.
The documentation for the NULLW feature says "A dummy write is initiated to DMASRC for every write to DMADST".
In the first image, this can be seen correctly, the "write to DMASRC" can bee seen on the SPI-MOSI (channel 0). Thus there is a "shift" of +1 byte between SPI-RX and the dummy write to SPI-TX.
In the second image it can be seen that this shift is +2 bytes, likely due to a wrong DMA trigger condition.
But I have no idea which one is corret.
The following code is used to do the 512 byte transfer.
The #define DMA_INT_RX either uses SPI RX or SPI TX as DMA trigger.
This #define is also used for SPI initializiation choose the DMA trigger (SPI interrupt bit)
DMACON = 0x0001;
DMAH= 0x2800;
DMAL= 0x0000;
DMACH0 = 0;
DMACH0bits.TRMODE=0; //Transfer mode
DMACH0bits.SAMODE=0; //Source address fix
DMACH0bits.DAMODE=1; // dest incr
DMACH0bits.NULLW=1; // null write
DMACH0bits.SIZE=1; // byte
DMAINT0= 0x00;
// for CHSEL see FRM Table 5-1
#ifdef DMA_INT_RX // this one for
DMAINT0bits.CHSEL = DMA_TRIG_SRC_SPI2_RECEIVE; //Trigger on SPI2 Receive
_SPI2RXIF = 0;
#else
DMAINT0bits.CHSEL = DMA_TRIG_SRC_SPI2_TRANSMIT; //Trigger on SPI2 Transmit
_SPI2TXIF = 0;
#endif
DMADST0= (WORD) pBuf;
DMASRC0= (unsigned int)&SPI2BUFL;
DMACNT0= wCount;
// Clearing Channel 0 Interrupt Flag;
IFS0bits.DMA0IF = false;
//Enable DMA
DMACONbits.DMAEN = 1;
DMACH0bits.CHEN = 1;
#if 0
DMACH0bits.CHREQ = 1; // to start dma, same as below
#else
SPI2BUFL = 0x0; // to start dma
#endif
// real application will not wait for DMA to finish, this is only for testing
while (! DMAINT0bits.DONEIF);
while (!SPI2STATLbits.SRMT); // still busy, wait until really done
DMACONbits.DMAEN = 0;
SPI initialization (partial)
SPI2CON1bits.MODE16 = 0; // byte mode
SPI2CON1bits.MSTEN = 1; //SPI master, CS is set manually
SPI2CON1bits.CKP = 0;
SPI2CON1bits.CKE = 1;
SPI2CON1bits.ENHBUF = 0;
SPI2STATbits.SPIROV = 0; // clear the Receive overflow flag
SPI2BRGLbits.BRG = 0; // 8 Mhz @ 32 Mhz cpu
SPI2CON1bits.MCLKEN = 0;
SPI2CON1Hbits.IGNROV = 1;
#ifdef DMA_INT_RX
SPI2IMSKLbits.SPIRBFEN = 1; // interrupt if rx full
#else
SPI2IMSKLbits.SPITBEN = 1; // interrupt if tx empty
#endif
SPI2CON1Lbits.SPIEN = 1; // enable SPI2 peripheral
The question now is, whether there are any ideas how I can either remove the problem with the gaps while DMA triggering on RX, or how I can fix the problem with the additional byte while DMA triggering on TX.
In both cases my DMA trigger configuration might be wrong, but I have no more idea where I'm going wrong.
The ultimate goal is simply to do the transfer with full 8 Mhz speed.