打印

USART 多机通信问题

[复制链接]
1662|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yyztju|  楼主 | 2010-11-10 18:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我现在使用STM32F103VE芯片为平台的装置进行多机通信,采用USART1,串口485通信,modbus规约,一台主机,三台从机,软件识别地址,主机循环给三个从机发信,收到回信后才开始下一次发送使能,采用中断方式收发,现在遇到一个问题,通信一段时间后就中断了,硬件电路采用6N137光耦,接口芯片为SN75LBC184,初始化程序如下:
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

USART_ITConfig(USART1, USART_IT_RXNE,DISABLE);      
USART_ITConfig(USART1, USART_IT_TXE,DISABLE);

/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate =baud;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
// USART_InitStructure.USART_Clock = USART_Clock_Disable;
// USART_InitStructure.USART_CPOL = USART_CPOL_Low;
// USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
// USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
USART_Init(USART1, &USART_InitStructure);

/* Enable the USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE,ENABLE);      
USART_ITConfig(USART1, USART_IT_TXE,DISABLE);
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
  
    /* Enable USART1 */
USART_Cmd(USART1, ENABLE);

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

4

帖子

1

粉丝