本帖最后由 gurong60 于 2013-6-24 16:48 编辑
现在是用spi接口的adc来采集电压,
使用usb——vcp的例程来改成自定义bluck传输。stm32作为从机,电脑接收数据
采用定时器中断100khZ来作为adc的采样率,
spi设置分频为9M.
stm32发送spi命令等待时间大概1.5us,
这样采集的数据送到usb导致usb没有响应,
但如果把spi发送命令中等待屏蔽去除,就可以传送usb数据,当然传送的数据是有误的
请问是为什么,是不是影响到usb中断了?
spi发送数据
u16 SPIx_ReadWriteByte(u16 TxData)
{
// u8 retry=0;
// while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); //检查指定的SPI标志位设置与否:发送缓存空标志位
// {
// retry++;
// if(retry>200)return 0;
// }
SPI_I2S_SendData(SPI1, TxData); //通过外设SPIx发送一个数据
// retry=0;
// while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); //检查指定的SPI标志位设置与否:接受缓存非空标志位
// {
// retry++;
// if(retry>200)return 0;
// }
return SPI_I2S_ReceiveData(SPI1); //返回通过SPIx最近接收的数据
}
主程序:
int main(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1| RCC_APB2Periph_AFIO, ENABLE); // 初始化时钟系统、使能相关的外围设备电源
Set_USBClock();
LED_config(); // 配置USB所用到的中断
USB_Interrupts_Config(); // 配置和使能USB时钟
USB_Init();
SPI_AD_Init();
USART1_Config();
TIM5_Interrupts_Config();
TIM5_Init();
while (1)
{
// adc_out1[2]=(adc_out[1]>>8)&0x00ff;
// adc_out1[3]=adc_out[1]&0x00ff;
/* while(1)
{
USART_SendData(USART1,adc_out1[0]);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){}
USART_SendData(USART1,adc_out1[1]);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){}
USART_SendData(USART1,adc_out1[2]);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){}
Delayms(2000);
Delayms(2000);
Delayms(2000);
Delayms(2000);
Delayms(2000);
Delayms(2000);
}
*/
if ((count_out != 0) && (bDeviceState == CONFIGURED))
{
while(1)
{
USB_SIL_Write(EP1_IN, adc_out1,64);
}
count_out==0 ;
}
}
}
void TIM5_Interrupts_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the TIM5 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
* Function Name : USB_Interrupts_Config
* Description : Configures the USB interrupts
* Input : None.
* Return : None.
*******************************************************************************/
void USB_Interrupts_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
#ifdef STM32F10X_CL
/* Enable the USB Interrupts */
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#else
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif /* STM32F10X_CL */
}
|