QianFan 发表于 2015-1-26 17:12
肯定是你程序的原因。当时我用429的时候,一次开4个没问题。103试过一次开两个也没问题。不过没有用printf ...
main(){
...
uart_init();
...
for(i=0;i<8;i++)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, A);
}
...
输出到uart3:
if (stArgPosOffset.iPos < 125)
{
for(i=0;i<ADC3_RAM_SIZE;i++)
{
printf("%d\n",ADC3Value);
}
}
.....
}
void uart_init(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* 开启GPIO_A | D的时钟 */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/*开启USART2 | USART3*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/*A2 is TX,A3 is RX*/
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_2MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
USART_InitStructure.USART_BaudRate = 115200;
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_Tx | USART_Mode_Rx;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
/*使能USART2*/
USART_Cmd(USART2, ENABLE);
/*PD8 is TX,PD9 is RX*/
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_25MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
USART_InitStructure.USART_BaudRate = 115200;
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_Tx | USART_Mode_Rx;
USART_Init(USART3, &USART_InitStructure);
/* 使能串口 */
USART_Cmd(USART3, ENABLE);
}
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART3, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET)
{}
return ch;
}
void USART2_IRQHandler(void)
{
unsigned char ch;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
ch = (USART_ReceiveData(USART2));
USART_SendData(USART2, (uint8_t) ch);
}
}
void USART3_IRQHandler(void)
{
unsigned char ch;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
ch = (USART_ReceiveData(USART3));
USART_SendData(USART3, (uint8_t) ch);
}
}
我上面的串口输出,根据代码条件选择,任意只使用一个输出时都正常。一旦条件满足,需要另一个也被调用到时,就不正常了。俩串口都停止。
自己写个printf试试,没遇到过
谢谢分享
理论上是没有冲突的,这样只能先看看死在哪个位置了。
加班要到年底了,手里有f091还没来得及研究
逍遥李 发表于 2015-1-27 10:31
加班要到年底了,手里有f091还没来得及研究
同加班…板子放了一周了orz
仔细检查程序
逍遥李 发表于 2015-1-27 10:31
加班要到年底了,手里有f091还没来得及研究
这是一个凄惨的故事。。。
本帖最后由 ataudio 于 2015-1-27 13:21 编辑
最新确定消息:上面的代码运行没什么问题,两串口同时输出都OK了,但是将printf放到了Uart_sendData()代码段的前面,就是说先printf,后Uart_sendData()就会出现两打印口都停止输出。
原因不详。分析来说,于理不合。