/* 利用STM32的SPI的DMA功能扩展更多的输出端口 芯片: STM32F103xx SN74AHC595 固件库: ST官方 3.61版本 */ #define GPIOB_SET_High(x) GPIO_SetBits(GPIOB, (GPIO_Pin_0 24) & 0x000000FF; SPI2_Buffer_Tx[1] = (hc595_port_out >> 16) & 0x000000FF; SPI2_Buffer_Tx[2] = (hc595_port_out >> 8) & 0x000000FF; SPI2_Buffer_Tx[3] = (hc595_port_out >> 0) & 0x000000FF; DMA1_Channel4->CNDTR = 4; DMA1_Channel5->CNDTR = 4; DMA_Cmd(DMA1_Channel4, ENABLE); DMA_Cmd(DMA1_Channel5, ENABLE); } 演示例子 #include "stm32f10x.h" #include "hw_config.h" #define SPI2_Buffer_Size 4 __IO uint8_t SPI2_Buffer_Tx[SPI2_Buffer_Size]; __IO uint8_t SPI2_Buffer_Rx[SPI2_Buffer_Size]; /** ****************************************************************************** * @file STM32F10x_Driver_Template/Project/src/main.c * @author wjandsq@gmail.com * @version V1.0.2 * @date 11/25/2013 * @brief Main program body ****************************************************************************** * @copy * * Copyright (c) 2010-2013 http://www.daxia.com * */ int main(void) { RCC_Configuration(); GPIO_Configuration(); SPI_Configuration(); NVIC_Configuration(); while(1){ if(Flag_IO_Update == TRUE){ Flag_IO_Update = FALSE; SPIx_DMA_Start(0xFFFFFFFF);// 扩展32端口输出 } } } |