用DMA SPI傳輸19200*16bit到另一個STM32
使能傳輸完成中斷,在中斷中拉GPIOx=1
在開始傳輸的時候GPIOx=0,所以低寬度就是一次DMA SPI的傳輸時間
只是我是用21MHz的 我用示波器量到低寬度=21.62ms ,
如果用計算的時間兜不起來這會是什麼原因??
void DMA1_SPI2_RX(void)
{
RCC->AHB1ENR |= 1<<21; //enable DMA1 Clk
DMA1_Stream3->PAR = (u32)&SPI2->DR; //Peripheral address
DMA1_Stream3->M0AR =(u32)&SPI_raw_data; //Memory address
DMA1_Stream3->NDTR = 160*120; //number of data
DMA1_Stream3->CR |= 0<<6; //Peripheral to Memory
DMA1_Stream3->CR |= 0<<8; //disable Circular mode
DMA1_Stream3->CR |= 0<<9; //DISABLE Peripheral increment mode
DMA1_Stream3->CR |= 1<<10; //ENABLE Memory increment mode
DMA1_Stream3->CR |= 1<<11; //Peripheral data size 16bit
DMA1_Stream3->CR |= 1<<13; //Memory data size 16bit
DMA1_Stream3->CR |= 2<<16; //Priority level 2
DMA1_Stream3->CR |= 0<<21; //Peripheral burst transfer configuration
DMA1_Stream3->CR |= 0<<23; //Memory burst transfer configuration
DMA1_Stream3->CR |= 0<<25; //selection Channel0
DMA1_Stream3->CR |= 1<<4; //Transfer complete interrupt enable
DMA1_Stream3->CR |= 1<<0;
MY_NVIC_Init(0,2,DMA1_Stream3_IRQn ,2);
}
void DMA1_Stream3_IRQHandler(void)
{
TP2=1;
DMA1->LIFCR |= 3<<26; // clear flag
}
void DMA1_SPI2_RX_Enable(void)
{
DMA1_Stream3->CR |= 1<<0;
TP2=0;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>