STM32F103RCT6串口4和串口5,可以发数据,但一接收数据,就进不了中断服务函数,程序就死了,我现在也遇到这个问题,发现库函数stm32f10x_usart.c这里:ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
{
uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
ITStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_GET_IT(USART_IT));
/* The CTS interrupt is not available for UART4 and UART5 */
if (USART_IT == USART_IT_CTS)
{
assert_param(IS_USART_123_PERIPH(USARTx));
}
/* Get the USART register index */
usartreg = (((uint8_t)USART_IT) >> 0x05);
/* Get the interrupt position */
itmask = USART_IT & IT_Mask;
itmask = (uint32_t)0x01 << itmask;
if (usartreg == 0x01) /* The IT is in CR1 register */
{
itmask &= USARTx->CR1;
}
else if (usartreg == 0x02) /* The IT is in CR2 register */
{
itmask &= USARTx->CR2;
}
else /* The IT is in CR3 register */
{
itmask &= USARTx->CR3;
}
bitpos = USART_IT >> 0x08;
bitpos = (uint32_t)0x01 << bitpos;
bitpos &= USARTx->SR;
if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
里面这样写:
/* The CTS interrupt is not available for UART4 and UART5 */
if (USART_IT == USART_IT_CTS)
{
assert_param(IS_USART_123_PERIPH(USARTx));
}
没有包含串口4和串口5,于是我跟进在stm32f10x_usart.h文件里将:
#define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) ||
((PERIPH) == USART2) ||
((PERIPH) == USART3) ||
((PERIPH) == UART4) ||
((PERIPH) == UART5))
#define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) ||
((PERIPH) == USART2) ||
((PERIPH) == USART3))
#define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) ||
((PERIPH) == USART2) ||
((PERIPH) == USART3) ||
((PERIPH) == UART4))
改为:
#define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) ||
((PERIPH) == USART2) ||
((PERIPH) == USART3) ||
((PERIPH) == UART4) ||
((PERIPH) == UART5))
#define IS_USART_123_PERIPH(PERIPH) (((PERIPH)== USART1) ||
((PERIPH) == USART2) ||
((PERIPH) == USART3) ||
((PERIPH) == UART4) ||
((PERIPH) == UART5))
#define IS_USART_1234_PERIPH(PERIPH) (((PERIPH)== USART1) ||
((PERIPH) == USART2) ||
((PERIPH) == USART3) ||
((PERIPH) == UART4) ||
((PERIPH) == UART5))
但我改完后发现,在中断接收数据,但有数据到来时不能进去中断函数,程序死了,请问大家知道知道怎么解决吗?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
已经解决问题,而且顺便解决了串口5的
改个其他的USART吧。
一般的,串口4和串口5都是异步的串口,名字叫做UART,比USART少一个S(Synchronous),
我当年也踩过雷,而且不知道怎么用的,最后改用了其他串口。估计UART是当外设用,收发数据要写特定的寄存器,资料没怎么找到。。。
没有复用
串口4.5不行么,串口1,串口2我们也没用到同步的方式啊。
一周热门 更多>