初级会员

- 积分
- 95
- 金钱
- 95
- 注册时间
- 2012-9-24
- 在线时间
- 0 小时
|

楼主 |
发表于 2012-10-10 15:15:41
|
显示全部楼层
回复【2楼】正点原子:
---------------------------------
问题已经找到了,是由下面的函数造成的,U转串才弄的,里面有好多东西不懂,下面的函数应该是主机配置U转串设备的一个子函数吧。再研究两天。
bool USART_Config(void)
{
//set the bit rate
if ((linecoding.bitrate > 115200) || (linecoding.bitrate < 1200) )
{
USART_Config_Init();
return (FALSE);
}
// set the Stop bit
switch (linecoding.format)
{
case 0:
USART_InitStructure.USART_StopBits = USART_StopBits_1;
break;
case 1:
USART_InitStructure.USART_StopBits = USART_StopBits_1_5;
break;
case 2:
USART_InitStructure.USART_StopBits = USART_StopBits_2;
break;
default:
{
USART_Config_Init();
return (FALSE);
}
}
// set the parity bit
switch (linecoding.paritytype)
{
case 0:
USART_InitStructure.USART_Parity = USART_Parity_No;
break;
case 1:
USART_InitStructure.USART_Parity = USART_Parity_Even;
break;
case 2:
USART_InitStructure.USART_Parity = USART_Parity_Odd;
break;
default:
{
USART_Config_Init();
return (FALSE);
}
}
//set the data type: only 8bits and 9bits is supported
switch (linecoding.datatype)
{
case 0x07:
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
break;
case 0x08:
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
break;
default:
{
USART_Config_Init();
return (FALSE);
}
}
USART_InitStructure.USART_BaudRate = linecoding.bitrate;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
return (TRUE);
} |
|