在线时间7 小时
UID263776
ST金币0
蝴蝶豆0
注册时间2010-1-14
初级会员
- 最后登录
- 2019-4-28
|
楼主 |
发表于 2011-2-21 15:06:59
|
显示全部楼层
a0a.1 0b0c
回复:STM32 DMA控制SPI1不成功
谢谢你的回复,我是通过示波器看的,没输出 ,发送完中断也北触发,相关的中断服务函数和I/O口的配置如下:
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);
} |
|