这两个函数配置有哪些问题么?
对比了官方demo,除了内部是灵活配置的dma,其他没找到哪些地方不一样。
void spi3_init(void)
{
gpio_init_type gpio_initstructure;
spi_init_type spi_init_struct;
dma_init_type dma_init_struct;
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_DMA2_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_SPI3_PERIPH_CLOCK, TRUE);
gpio_pin_remap_config(SPI3_GMUX_0011, TRUE);
/* sck */
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
gpio_initstructure.gpio_pins = GPIO_PINS_10;
gpio_init(GPIOC, &gpio_initstructure);
/* miso */
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
gpio_initstructure.gpio_pins = GPIO_PINS_11;
gpio_init(GPIOC, &gpio_initstructure);
/* mosi */
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
gpio_initstructure.gpio_pins = GPIO_PINS_12;
gpio_init(GPIOC, &gpio_initstructure);
dma_reset(DMA2_CHANNEL1);
dma_default_para_init(&dma_init_struct);
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE; //内存数据的宽度
dma_init_struct.memory_inc_enable = TRUE; //内存地址递增打开
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE; //外设数据的宽度
dma_init_struct.peripheral_inc_enable = FALSE; //外设地址递增关闭
dma_init_struct.priority = DMA_PRIORITY_MEDIUM; //中等优先级
dma_init_struct.loop_mode_enable = FALSE; //不循环
dma_init_struct.peripheral_base_addr=(uint32_t)&(SPI3->dt); //外设地址
dma_init_struct.memory_base_addr=(uint32_t)spi3_tx_buffer; //内存地址
dma_init_struct.direction=DMA_DIR_MEMORY_TO_PERIPHERAL; //外设地址为源地址
dma_init_struct.buffer_size=32;
dma_init(DMA2_CHANNEL1, &dma_init_struct);
dma_channel_enable(DMA2_CHANNEL1, TRUE);
dma_flexible_config(DMA2, FLEX_CHANNEL1, DMA_FLEXIBLE_SPI3_TX);
spi_init_struct.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX;
spi_init_struct.master_slave_mode = SPI_MODE_MASTER;
spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_8;
spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_HIGH;
spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
spi_init(SPI3, &spi_init_struct);
spi_enable(SPI3, TRUE);
spi_i2s_dma_transmitter_enable(SPI3,TRUE);
}
void LCD_SendByte(uint8_t dat)
{
volatile uint8_t dummy_data;
ST7789_CS_LOW;
while (spi_i2s_flag_get(SPI3, SPI_I2S_TDBE_FLAG) == RESET && spi_i2s_flag_get(SPI3, SPI_I2S_BF_FLAG) == SET)
{
// 等待主机数据发送完毕
}
spi_i2s_data_transmit(SPI3, dat);
while (spi_i2s_flag_get(SPI3, SPI_I2S_RDBF_FLAG) == RESET && spi_i2s_flag_get(SPI3, SPI_I2S_BF_FLAG) == SET)
{
// 等待主机数据接收完毕
}
dummy_data = spi_i2s_data_receive(SPI3);
ST7789_CS_HIGH;
}
|
很好的资源,学习啦~~