本帖最后由 sihhepl 于 2017-6-19 22:17 編輯
200元酬謝,請各位大俠幫我調下程序,謝謝啦!我的QQ:79422195,請標注“51黑DMA”
我使用cc2530的DMA channel 1將接收到的串口(uart0)數據存儲在uartRxBuf內,程序如下。在中斷函數中,根據DMAIRQ的DMAIF1位是否置1來判斷是否傳輸完成DATA_COUNT字節的數據。如果DATA_COUNT為1,則程序沒有問題,接收數據正常,如果DATA_COUNT大于1,則程序不能產生中斷。請各位大俠幫我看下程序,謝謝啦!
#define HAL_URX0_DMA_CH 1 #define DATA_COUNT 10 uint8 uartRxBuf[15] = {0}; void HalDma_uart( void ) { halDMADesc_t *ch; ch = HAL_DMA_GET_DESC1234(HAL_URX0_DMA_CH) ch->srcAddrH = HI_UINT16(&X_U0DBUF); ch->srcAddrL = LO_UINT16(&X_U0DBUF); ch->dstAddrH = HI_UINT16(uartRxBuf); ch->dstAddrL = LO_UINT16(uartRxBuf); ch->vLen = 0x00;// Use fixed length DMA transfercount ch->lenH = HI_UINT16(DATA_COUNT); ch->lenL = LO_UINT16(DATA_COUNT); ch->wordSize =HAL_DMA_WORDSIZE_BYTE;// Perform 1-byte transfers ch->tMode =HAL_DMA_TMODE_SINGLE;// Single byte transfer per DMA trigger ch->trig = HAL_DMA_TRIG_URX0;// DMA trigger =USARTx RX complete ch->srcInc = HAL_DMA_SRCINC_0;// Do not incrementsource pointer, points to USART U0BUF register. ch->destInc = HAL_DMA_DSTINC_1;// Increment destinationpointer by 1 byte address after each transfer. ch->irqMask = HAL_DMA_IRQMASK_DISABLE;// Enable DMAinterrupt to the CPU ch->m8 = HAL_DMA_M8_USE_8_BITS;// Use all 8bits for transfer count ch->priority =HAL_DMA_PRI_HIGH;// DMA memory access has low priority /* The DMAconfiguration data structure may reside at any location in * unified memoryspace, and the address location is passed to the DMA * through DMA1CFGH:DMA1CFGL. */ HAL_DMA_CLEAR_IRQ(HAL_URX0_DMA_CH);
HAL_DMA_SET_ADDR_DESC1234( ch );
HAL_DMA_ARM_CH(HAL_URX0_DMA_CH); // Arm DMAchannel 1 //apply 45 NOP's forloading DMA configuration asm("NOP");asm("NOP");//45clk periods //Enable the DMAinterrupt (IEN1.DMAIE = IEN0.EA = 1), //and clear potentialpending DMA interrupt requests (IRCON.DMAIF = 0) IEN0 |= 0x80; IEN1 |= 0x01; IRCON &= ~0x02; // Enable UARTx RX U0CSR |= 0x40; } |