

求助,想實作按下按鍵,電平取反并且串口除錯能夠接收到printf輸出,但是printf沒有被接收。
uj5u.com熱心網友回復:
波特率沒有設定對?校驗方式不一致?位數設定不對?uj5u.com熱心網友回復:
串口通信定時器沒有啟動?uj5u.com熱心網友回復:
baud rate先確認一下吧uj5u.com熱心網友回復:
先把串口 send/recive 除錯好 再使用printf
uj5u.com熱心網友回復:
選要確認USART 能夠通訊在,在用printfuj5u.com熱心網友回復:
波特率沒有設定對uj5u.com熱心網友回復:
先把串口通信調通,在串口助手上列印輸出東西,這樣的例程網上很多。之后就可以實作你的功能了。。。實作電平反轉之后列印資訊。。uj5u.com熱心網友回復:
看看你串口設定了沒uj5u.com熱心網友回復:
//如果使用ucos,則包括下面的頭檔案即可.#if SYSTEM_SUPPORT_UCOS
#include "includes.h" //ucos 使用
#endif
//加入以下代碼,支持printf函式,而不需要選擇use MicroLIB
#if 1
#pragma import(__use_no_semihosting)
//標準庫需要的支持函式
struct __FILE
{
int handle;
};
FILE __stdout;
//定義_sys_exit()以避免使用半主機模式
_sys_exit(int x)
{
x = x;
}
//重定義fputc函式
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);//回圈發送,直到發送完畢
USART1->DR = (u8) ch;
return ch;
}
#endif
void uart_init(u32 bound){
//GPIO埠設定
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能USART1,GPIOA時鐘
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //復用推挽輸出
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX PA.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空輸入
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Usart1 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//搶占優先級3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子優先級3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根據指定的引數初始化VIC暫存器
//USART 初始化設定
USART_InitStructure.USART_BaudRate = bound;//一般設定為9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字長為8位資料格式
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_Rx | USART_Mode_Tx; //收發模式
USART_Init(USART1, &USART_InitStructure); //初始化串口
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//開啟中斷
USART_Cmd(USART1, ENABLE); //使能串口
}
把這個代碼打進去,初始化串口一,然后PRINTF,串口就能輸出東西了,百分百
uj5u.com熱心網友回復:
USART 沒有定義用哪個 特殊暫存器標志位要弄好uj5u.com熱心網友回復:
謝謝分享!你貼的那張圖解了我很久的心病:printf 中一直不能理解怎么監視:
HAL_UART_Transmit(&huart1,CH,1,30);
的狀態,原來可以不監視。
uj5u.com熱心網友回復:
檢測滑鼠按下,確認,然后當發現抬起時執行,否則撤銷操作.uj5u.com熱心網友回復:
沒有printf()輸出,通常與串口設定有關,開串口時鐘,設定波特率等轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/45703.html
標籤:單片機/工控
