STM32F302的SPI模块数据不能发送
大家好,帮忙看下哪里出错了。
SPI引脚配置成输出可以正常输出高低电平。配置成SPI3也发送不出数据,CLK引脚没波形。
int main(void)
{
volatile u16 delay_cnt;
RCC_GetClocksFreq(&RCC_InitStructure);
//系统10ms中断
SysTickConfig();
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_Level_3;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_Pin_13, GPIO_AF_5);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_10 | GPIO_Pin_11;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_Pin_10 | GPIO_Pin_11, GPIO_AF_5);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel =SPI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
NVIC_Init(&NVIC_InitStructure);
SPI_I2S_DeInit(SPI2);
SPI_InitStructure.SPI_Mode =SPI_Mode_Master;
SPI_InitStructure.SPI_Direction =SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit =SPI_FirstBit_MSB;
SPI_InitStructure.SPI_DataSize =SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL =SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA =SPI_CPHA_1Edge;
SPI_InitStructure.SPI_BaudRatePrescaler =SPI_BaudRatePrescaler_64;//SPI²¨ÌØÂÊʵ¼Ê¶àÉÙ£¿
SPI_InitStructure.SPI_NSS =SPI_NSS_Soft;
SPI_InitStructure.SPI_CRCPolynomial =SPI_CRCLength_8b;//CRC ?
SPI_Init(SPI2, &SPI_InitStructure);
// SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);
SPI_Cmd(SPI2, ENABLE);
while (1)
{
if(Flag_10ms ==1)
{
Flag_10ms =0;
// SPI2->SR &=(~0x02);
SPI2->DR =0x33;
}
}
}
void SysTickConfig(void)
{
//Setup SysTick Timers for 10ms interrupt
if(SysTick_Config(RCC_InitStructure.SYSCLK_Frequency /100))
{
//Capture error
while(1);
}
//Configure the SysTick handler priority
NVIC_SetPriority(SysTick_IRQn, 0);
}
|