小弟最近在调试ADC+DMA工作模式,ADC使用单通道中断模式,AD通道使用AN3,DMA使用通道0。在使用中发现DMA在接收到指定长度数据后可以触发中断,但是设置的目的数组内没有数据存入,下面是相关配置代码,请大家帮忙看看,谢谢。
//主函数
int main ( void )
{
/* Initialize all MPLAB Harmony modules, including application(s). */
SYS_Initialize ( NULL );
/**************配置DMA传输ADC**************/
SYS_DMA_Channel0Setup(SYS_DMA_CHANNEL_OP_MODE_AUTO);
SYS_DMA_Channel0TransferAdd();
PLIB_DMA_ChannelXINTSourceFlagClear(DMA_ID_0, DMA_CHANNEL_0, DMA_INT_DESTINATION_DONE);
PLIB_DMA_ChannelXINTSourceEnable(DMA_ID_0, DMA_CHANNEL_0, DMA_INT_DESTINATION_DONE);
SYS_DMA_Channel0Enable();
/**************配置ADC**************/
DRV_ADC0_Open(); //打开ADC
DRV_TMR0_Start(); //开始定时器触发
while ( true )
{
/* Maintain state machines of all polled MPLAB Harmony modules. */
SYS_Tasks ( );
}
/* Execution should not come here during normal operation */
return ( EXIT_FAILURE );
}
//DMA配置部分
void SYS_DMA_Channel0TransferAdd(void)
{
/* Set the source and destinaton addresses (addresses are converted from virtual to physical) */
PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&ADCDATA3); //&ADCDATA3 0xBF84B20C
PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&adc_str[0]);
/* Set the source and destination sizes */
PLIB_DMA_ChannelXSourceSizeSet(DMA_ID_0, DMA_CHANNEL_0, 2);
PLIB_DMA_ChannelXDestinationSizeSet(DMA_ID_0, DMA_CHANNEL_0, 10*2);
/* Set the number of bytes per transfer */
PLIB_DMA_ChannelXCellSizeSet(DMA_ID_0, DMA_CHANNEL_0, 2);
}
//中断部分如下
void __ISR(_DMA0_VECTOR, ipl1AUTO) _IntHandlerSysDmaCh0(void)
{
/* Clear the interrupt flag */
PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_DMA_0);
/* TODO: Add code as needed */
/*
if (PLIB_DMA_ChannelXINTSourceFlagGet(DMA_ID_0, DMA_CHANNEL_0, DMA_INT_DESTINATION_HALF_FULL))
{
PLIB_DMA_ChannelXINTSourceFlagClear(DMA_ID_0, DMA_CHANNEL_0, DMA_INT_DESTINATION_HALF_FULL);
info1 = adc_str[2];
}
*/
if (PLIB_DMA_ChannelXINTSourceFlagGet(DMA_ID_0, DMA_CHANNEL_0, DMA_INT_DESTINATION_DONE))
{
PLIB_DMA_ChannelXINTSourceFlagClear(DMA_ID_0, DMA_CHANNEL_0, DMA_INT_DESTINATION_DONE);
BSP_LEDToggle(BSP_LED_2);;//测试是否进入中断
}
} |