研究生
最后登录1970-1-1
在线时间 小时
注册时间2016-6-14
|
为什么串口输出不对- #include "stm32f10x.h"
- #include "bsp_usart1.h"
- #include "bsp_led.h"
- #include "bsp_can.h"
- void delay_ms(u16 time);
- void HMISends(char *buf1);
- void HMISendb(u8 buf);
- char buf[64];
- char buff[64];
- void RCC_Config(void);
- void USARTx_Config(void);
- int main(void)
- {
- /* USART1 config */
- USARTx_Config();
- RCC_Config();
-
- /* LED config */
- // LED_GPIO_Config();
-
- // printf( "\r\n Õa¸öò»¸öCAN£¨»Ø»·Ä£ê½oíÖD¶Ïģ꽣©2aêÔ3ìDò...... \r\n" );
-
- // USER_CAN_Init();
- // delay_ms(300);
- sprintf(buf,"n0.val=1");
- HMISends(buf);
- HMISendb(0xff);
- // printf( "\r\n CAN »Ø»·2aêÔ3õê¼»ˉ3é1|...... \r\n" );
-
- // USER_CAN_Test();
- // delay_ms(300);
- sprintf(buf,"n0.val=66666");
- HMISends(buf);
- HMISendb(0xff);
- // printf( "\r\n CAN »Ø»·2aêÔ3é1|...... \r\n" );
-
-
- while (1)
- {
- sprintf(buf,"n0.val=6666");
- HMISends(buf);
- HMISendb(0xff);
- }
- }
- void delay_ms(u16 time)
- {
- u16 i=0;
- while(time--)
- {
- i=12000;
- while(i--);
- }
- }
- void HMISends(char *buf1) //???????
- {
- u8 i=0;
- while(1)
- {
- if(buf1[i]!=0)
- {
- USART_SendData(USART1,buf1[i]); //??????
- while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){};//??????
- i++;
- }
- else
- return ;
- }
- }
- void HMISendb(u8 k) //??????
- {
- u8 i;
- for(i=0;i<3;i++)
- {
- if(k!=0)
- {
- USART_SendData(USART1,k); //??????
- while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){};//??????
- }
- else
- return ;
- }
- }
- void RCC_Config(void)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1,ENABLE);
- }
- void USARTx_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
-
- /* config USART1 clock */
- macUSART_APBxClock_FUN(macUSART_CLK, ENABLE);
- macUSART_GPIO_APBxClock_FUN(macUSART_GPIO_CLK, ENABLE);
-
- /* USART1 GPIO config */
- /* Configure USART1 Tx (PA.09) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = macUSART_TX_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(macUSART_TX_PORT, &GPIO_InitStructure);
- /* Configure USART1 Rx (PA.10) as input floating */
- GPIO_InitStructure.GPIO_Pin = macUSART_RX_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(macUSART_RX_PORT, &GPIO_InitStructure);
-
- /* USART1 mode config */
- USART_InitStructure.USART_BaudRate = macUSART_BAUD_RATE;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No ;
- USART_InitStructure.USART_Mode =USART_Mode_Rx | USART_Mode_Tx;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
-
- USART_Init(macUSARTx, &USART_InitStructure);
- USART_Cmd(macUSARTx, ENABLE);
-
- }
复制代码
|
|