意图:用定时器控制DMA的通道3,通过SPI1去做LED屏的显示刷新(LED是串行接口)。但目前SPI始终不出数据来,时钟有。 代码如下: /******************************************************************************* Configures DMA & SPI1 *******************************************************************************/ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Extern variables ----------------------------------------------------------*/ extern UINT8 DisplayCells; extern UINT8 DisplayBufferA[4][160]; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name : ConfigureDMA * Description : is used for displaying * Input : None. * Return : None. *******************************************************************************/ void ConfigureDMA(void) { UINT32 DestBaseAddr; SPI_InitTypeDef SPI_InitStructure; DMA_InitTypeDef DMA_InitStructure; DestBaseAddr = (UINT32)&SPI1->DR; SPI_DeInit(SPI1); //set default SPI_Cmd(SPI1, DISABLE); SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; //SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //SPI Clock Polarity(时钟悬空时高) SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_Init(SPI1, &SPI_InitStructure); //choose SPI1 //SPI_CalculateCRC() SPI1->CR1 &= (u16)0xDFFF; // Disable CRC SPI_Cmd(SPI1, ENABLE); // SPI_SendData(SPI1,0x5a); DMA_DeInit(DMA_Channel3); //DMA channel 3 configuration for display text DMA_InitStructure.DMA_PeripheralBaseAddr= DestBaseAddr; DMA_InitStructure.DMA_MemoryBaseAddr = (UINT32)DisplayBufferA; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //Memory to Peripheral DMA_InitStructure.DMA_BufferSize = 16 * DisplayCells; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize= DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //single times mode DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA_Channel3, &DMA_InitStructure); SPI_DMACmd(SPI1, SPI_DMAReq_Tx, ENABLE); DMA_ITConfig(DMA_Channel3, DMA_IT_TC, ENABLE); //DMA_Channel3 Transfer complete interrupt mask DMA_Cmd(DMA_Channel3, ENABLE); //DMA_Channel3 Transfer enable } /****************************** end(DMA Configures)***************************/ 我是入门小弟,忘大家多多指点 |
RE:STM32 DMA控制SPI1不成功
回复:STM32 DMA控制SPI1不成功
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; //choose config pint
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //port speed is 50Mhz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //push-pull output mode
GPIO_Init(GPIOA, &GPIO_InitStructure); //initialization GPIOB
/*******************************************************************************
Configures DMA & SPI1
*******************************************************************************/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
extern UINT8 DisplayCells;
extern UINT8 DisplayBufferA[4][160];
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : ConfigureSPI1
* Description : is used for displaying
* Input : None.
* Return : None.
*******************************************************************************/
void ConfigureSPI1( void )
{
SPI_InitTypeDef SPI_InitStructure;
SPI_DeInit(SPI1); //set default
SPI_Cmd(SPI1, DISABLE);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //SPI Clock Polarity(时钟悬空时高)
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_Init(SPI1, &SPI_InitStructure); //choose SPI1
SPI_CalculateCRC(SPI1, DISABLE); // Disable CRC SPI1->CR1 &= (u16)0xDFFF; SPI_Cmd(SPI1, ENABLE);
SPI_Cmd(SPI1, ENABLE);
SPI_SendData(SPI1,0x5a);
}
/*******************************************************************************
* Function Name : ConfigureDMA
* Description : is used for displaying
* Input : None.
* Return : None.
*******************************************************************************/
void ConfigureDMA(void)
{
DMA_InitTypeDef DMA_InitStructure;
UINT32 DestBaseAddr = (UINT32)&SPI1->DR;;
DMA_DeInit(DMA_Channel3); //DMA channel 3 configuration for display text
DMA_InitStructure.DMA_PeripheralBaseAddr= DestBaseAddr;
DMA_InitStructure.DMA_MemoryBaseAddr = (UINT32)DisplayBufferA;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //Memory to Peripheral
DMA_InitStructure.DMA_BufferSize = 16 * DisplayCells;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize= DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //single times mode
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
DMA_Init(DMA_Channel3, &DMA_InitStructure);
SPI_DMACmd(SPI1, SPI_DMAReq_Tx, ENABLE);
DMA_ITConfig(DMA_Channel3, DMA_IT_TC, ENABLE); //DMA_Channel3 Transfer complete interrupt mask
DMA_Cmd(DMA_Channel3, ENABLE); //DMA_Channel3 Transfer enable
}
/****************************** end(DMA Configures)***************************/
/*******************************************************************************
* Function Name : DMAChannel3_IRQHandler
* Description : This function handles DMA Stream 3 interrupt request.
* Input : None
* Return : None
* Created By : 何宣见(hexuanjian2005@126.com)
* Created date : 2011.02.11
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMAChannel3_IRQHandler(void)
{
DMA_ClearFlag( DMA_FLAG_TC3);
DMA_ClearITPendingBit( DMA_FLAG_TC3 );
DMA_Cmd(DMA_Channel3,DISABLE);
}
RE:STM32 DMA控制SPI1不成功
RE:STM32 DMA控制SPI1不成功
回复:STM32 DMA控制SPI1不成功
谢谢各位好心人,我是写了的啊,用SPI_SendData写是可以的,波形正确,但是在定时器中断中通过DMA输出的时候就只有时钟没数据啊,具体代码是:
/* Extern variables ----------------------------------------------------------*/
extern UINT8 DisplayCells;
extern UINT8 DisplayBufferA[4][160];
/*******************************************************************************
* Function Name : TIM3_IRQHandler
* Description : This function handles TIM3 global interrupt request.
* Input : None
* Return : None
* Created By : 何宣见(hexuanjian2005@126.com)
* Created date : 2011.02.11
*-------------------------------------------------------------------------------
*******************************************************************************/
void TIM3_IRQHandler(void)
{
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_ClearITPendingBit(TIM3,TIM_FLAG_Update);
ConfigureDMA();
}
这样是不是就循环启动了DMA控制的SPI传输了?望大家指点!
另外这个传输完中断也没来,是不是SPI传输没有启动成功?
/*******************************************************************************
* Function Name : DMAChannel3_IRQHandler
* Description : This function handles DMA Stream 3 interrupt request.
* Input : None
* Return : None
* Created By : 何宣见(hexuanjian2005@126.com)
* Created date : 2011.02.11
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMAChannel3_IRQHandler(void)
{
/*判断是否是dma1 channel3 发送完成中断*/
if(DMA_GetITStatus(DMA_FLAG_TC3)==SET)
{
DMA_ClearITPendingBit(DMA_FLAG_TC3);/*清dma1 channel4中断标志*/
}
}
RE:STM32 DMA控制SPI1不成功
回复:STM32 DMA控制SPI1不成功
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
.......
/***********************************DMAx************************************/
NVIC_InitStructure.NVIC_IRQChannel = DMAChannel3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
究竟是为什么?高步,明白哦!望大家帮我看下啊!还有就是DMA配置中的存储器到存储器现也开启了( DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;),但是不能触发DMA开始SPI传输
RE:STM32 DMA控制SPI1不成功
RE:STM32 DMA控制SPI1不成功