【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?
恩,我在裸机下改成用if来做判断了,可以了,可是操作系统下不行,这系统是自己看教程移植的,现在可能会有问题,初次接触RTOS的菜鸟,够艰难的,各种问题
这是不是指虽然进入的串口中断,因为在中断里读取串口数据.而读出的0.是不是接收函数有问题
接收函数是ST的官方库函数,跑裸机都没问题的,接收函数肯定没问题,是因为接收寄存器的值是0,所以才读到0
这跟变量没关系吧,接收寄存器是16位的,我初始化时设置是八位,我是接收1字节发送1字节,一个unsigned char型的就行了
大神。。。。。我把GPS模块拿掉,RXNE位也会被置位一次,然后进中断,也就是说那次中断不是因为接收到我的gps信号而产生的,溢出错误标志位一直都是0
void NvicInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void UartInit(void)
{
INT8U i;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE); // 使能GPIOA端口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE); // 使能串口1时钟
GPIO_PinAFConfig(GPIOA ,GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA ,GPIO_Pin_10, GPIO_AF_1);
/////////////////////////////////////////////////////////////////////////////////////
/* PA9==TX PA10-RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA , &GPIO_InitStructure);
/////////////////////////////////////////////////////////////////////////////////////
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure); //串口配置
USART_ITConfig(USART1, USART_IT_RXNE,ENABLE);//打开中断
USART_Cmd(USART1, ENABLE);//使能串口1
USART_ClearFlag(USART1, USART_FLAG_TC);
}
以上是初始化,我单步调试发现执行完 USART_Cmd(USART1, ENABLE);后RXNE标志位就被置位了
这是ST的库函数,执行完USARTx->CR1 |= USART_CR1_UE;后标志位就被置位了
void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the selected USART by setting the UE bit in the CR1 register */
USARTx->CR1 |= USART_CR1_UE;
}
else
{
/* Disable the selected USART by clearing the UE bit in the CR1 register */
USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
}
}
看汇编代码如下:
0x080021B6 4770 BX lr
403: if (NewState != DISABLE)
404: {
405: /* Enable the selected USART by setting the UE bit in the CR1 register */
0x080021B8 2900 CMP r1,#0x00
0x080021BA D004 BEQ 0x080021C6
406: USARTx->CR1 |= USART_CR1_UE;
407: }
408: else
409: {
410: /* Disable the selected USART by clearing the UE bit in the CR1 register */
0x080021BC 6802 LDR r2,[r0,#0x00]
0x080021BE 2301 MOVS r3,#0x01
0x080021C0 431A ORRS r2,r2,r3
0x080021C2 6002 STR r2,[r0,#0x00]
0x080021C4 E003 B 0x080021CE
411: USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
412: }
0x080021C6 6802 LDR r2,[r0,#0x00]
0x080021C8 0852 LSRS r2,r2,#1
0x080021CA 0052 LSLS r2,r2,#1
0x080021CC 6002 STR r2,[r0,#0x00]
413: }
截图如下所示
找到原因了!多谢版主热心指点,今天太开心了。
GPIO_PinAFConfig(GPIOA ,GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA ,GPIO_Pin_10, GPIO_AF_1);
仔细看这两句发现应该写作GPIO_PinSource10的写成GPIO_Pin_10,而GPIO_Pin_10也有宏定义,编译器没查出来错。
人多力量大。