void spi_bytes_read(uint8_t *pbuffer, uint32_t length)
{
uint8_t write_value = FLASH_SPI_DUMMY_BYTE;
#if defined(SPI_TRANS_DMA)
dma_reset(DMA2_CHANNEL3);
dma_reset(DMA2_CHANNEL4);
dma_default_para_init(&dma_init_struct);
dma_init_struct.buffer_size = length;
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;//存储器到外设 写
dma_init_struct.memory_base_addr = (uint32_t)&write_value;
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
dma_init_struct.memory_inc_enable = FALSE;
dma_init_struct.peripheral_base_addr = (uint32_t)(&SPI4->dt);
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
dma_init_struct.peripheral_inc_enable = FALSE;
dma_init_struct.priority = DMA_PRIORITY_VERY_HIGH;
dma_init_struct.loop_mode_enable = FALSE;
dma_init(DMA2_CHANNEL4, &dma_init_struct);
dma_init_struct.buffer_size = length;
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;//外设到存储器 读
dma_init_struct.memory_base_addr = (uint32_t)pbuffer;
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
dma_init_struct.memory_inc_enable = TRUE;
dma_init_struct.peripheral_base_addr = (uint32_t)(&SPI4->dt);
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
dma_init_struct.peripheral_inc_enable = FALSE;
dma_init_struct.priority = DMA_PRIORITY_VERY_HIGH;
dma_init_struct.loop_mode_enable = FALSE;
dma_init(DMA2_CHANNEL3, &dma_init_struct);
/* 使能DMA通道 */
dma_channel_enable(DMA2_CHANNEL3, TRUE);
dma_channel_enable(DMA2_CHANNEL4, TRUE);
//使能spi dma发送和接收请求
spi_i2s_dma_transmitter_enable(SPI4, TRUE);
spi_i2s_dma_receiver_enable(SPI4, TRUE);
/* enable transfer full data intterrupt */
//开启dma数据流传输完成中断
dma_interrupt_enable(DMA2_CHANNEL3, DMA_FDT_INT, TRUE);
/* dma2 channel3 interrupt nvic init */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
nvic_irq_enable(DMA2_Channel3_IRQn, 1, 0);
}
void DMA2_Channel3_IRQHandler(void)
{
if(dma_flag_get(DMA2_FDT3_FLAG) != RESET)
{
/* 1.清中断标志 */
dma_flag_clear(DMA2_FDT3_FLAG);
/* 2.禁能 DMA 传输完成中断 */
dma_interrupt_enable(DMA2_CHANNEL3, DMA_FDT_INT, FALSE);
/* 3.禁能 SPI RX DMA 请求 */
spi_i2s_dma_receiver_enable(SPI4, FALSE);
/* 4.禁能 DMA Stream */
dma_channel_enable(DMA2_CHANNEL3, FALSE);
/* 6.通知应用程序 RX 传输完成 */
g_rx_flag=1;
}
}
我这样配置dma接收中断是错误的,有哪位大牛指点一下我该怎么配置吗 |