各位大侠,我刚开始接触STM32F103VCT6,关于SPI1的数据发送的一些疑问,请帮忙!写了一个测试程序(SPI Master Mode),每秒定时发送数据,SPI部分的程序如下: /* SPI1初始化*/ GPIO_InitTypeDef GPIO_InitStruct; SPI_InitTypeDef SPI_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; /* Enable GPIOA and SPI1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); /* Enable the SPI1 Pins Software Remapping */ GPIO_PinRemapConfig(GPIO_Remap_SPI1, DISABLE); /* Connect PXx to SPI1_NSS(PA.4) */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_SetBits(GPIOA, GPIO_Pin_4); /* Connect PXx to SPI1_SCK(PA.5) and SPI1_MOSI(PA.7) */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_5; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStruct); /* Connect PXx to SPI1_MISO(PA.6) */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStruct); /* SPI1 configuration -------------------------------------*/ SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStruct.SPI_Mode = SPI_Mode_Master; SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b; SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low; SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStruct.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStruct); SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE); SPI_Cmd(SPI1, ENABLE); /* NVIC configuration */ /* Configure the Priority Group to 2 bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /* Enable the SPI1 Interrupt */ NVIC_InitStruct.NVIC_IRQChannel = SPI1_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); 主程序中每1s进行SPI1数据发送。 if(net_spi1_flag == 1) { net_spi1_flag = 0; GPIO_ResetBits(GPIOA, GPIO_Pin_4); for(test_num=0; test_num<255; test_num++) { for(test_len=0; test_len<255; test_len++) { SPI_I2S_SendData(SPI1, net_spi1_data[test_len]); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); } } GPIO_SetBits(GPIOA, GPIO_Pin_4); } 问题:在程序中只开启了SPI1得接收中断,而没有开启发送中断,每次SPI1发送数据时,都会进入到SPI1中断服务程序中。SPI1的中断服务程序如下: void SPI1_IRQHandler(void) { static uint8_t spi_num=0; if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) != RESET) { spi_num++; } } 请不吝赐教! |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
楼主你去群里问问