怎么用串口1 输出os_printf内容呢?
本帖最后由 1112 于 2016-12-31 11:15 编辑问题:怎么用串口1 输出os_printf内容呢?
1、我是这样尝试修改的:
/**
* @brief 程序入口函数
* 在该函数中完成用户相关的初始化
* @param none
* @return none
*/
void ICACHE_FLASH_ATTR user_init(void)
{
uint32 system_free_size = 0;
wifi_station_set_auto_connect(1);
wifi_set_sleep_type(NONE_SLEEP_T);//set none sleep mode
espconn_tcp_set_max_con(10);
uart_init_3(9600,115200);
UART_SetPrintPort(1);<b>//串口1</b>
os_printf( "---------------SDK version:%s--------------\n", system_get_sdk_version());
os_printf( "system_get_free_heap_size=%d\n",system_get_free_heap_size());
uart_init_3(UartBautRate uart0_br, UartBautRate uart1_br)
{
// rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br;
UartDev.exist_parity = STICK_PARITY_DIS;
UartDev.parity = NONE_BITS;
UartDev.stop_bits = ONE_STOP_BIT;
UartDev.data_bits = EIGHT_BITS;
uart_config(UART0);
UartDev.baut_rate = uart1_br;
uart_config(UART1);
ETS_UART_INTR_ENABLE();
// install uart1 putc callback
// os_install_putc1((void *)uart1_write_char);//print output at UART1
}
UART_SetPrintPort(uint8 uart_no)
{
if(uart_no==1){
os_install_putc1(uart1_write_char);
}else{
/*option 1: do not wait if uart fifo is full,drop current character*/
os_install_putc1(uart0_write_char_no_wait);
/*option 2: wait for a while if uart fifo is full*/
os_install_putc1(uart0_write_char);
}
}
2、接线
RX--GPIO2
GND---GND
3V---3V
3、波特率:74880
4、串口输出:
这样os_printf没有打印出内容,换串口0一切正常。
各位大神,这怎么解决?
参考一下第42点的os_printf这条函数~ 前面是设置 115200,后面是用74800 , 能输出吗
本帖最后由 1112 于 2016-12-30 10:49 编辑
yCat 发表于 2016-12-30 10:17
参考一下第42点的os_printf这条函数~
看了文档了,我是这样改的:
uart_init_3(UartBautRate uart0_br, UartBautRate uart1_br)
{
// rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br;
UartDev.exist_parity = STICK_PARITY_DIS;
UartDev.parity = NONE_BITS;
UartDev.stop_bits = ONE_STOP_BIT;
UartDev.data_bits = EIGHT_BITS;
uart_config(UART0);
UartDev.baut_rate = uart1_br;
uart_config(UART1);
ETS_UART_INTR_ENABLE();
// install uart1 putc callback//添加uart1
os_install_putc1((void *)uart1_write_char);//print output at UART1
}
UART_SetPrintPort(uint8 uart_no)
{
if(uart_no==1){
//os_install_putc1(uart1_write_char);
os_install_putc1((void *)uart1_write_char); //添加uart1
}else{
/*option 1: do not wait if uart fifo is full,drop current character*/
os_install_putc1(uart0_write_char_no_wait);
/*option 2: wait for a while if uart fifo is full*/
os_install_putc1(uart0_write_char);
}
}
实测也没有正确输出。
szuser 发表于 2016-12-30 10:27
前面是设置 115200,后面是用74800 , 能输出吗
这确实也有点奇怪,但改成74880时 实际上已经输出上面我贴的内容,只是没有打印os_printf的内容 1112 发表于 2016-12-30 11:19
这确实也有点奇怪,但改成74880时 实际上已经输出上面我贴的内容,只是没有打印os_printf的内容 ...
ESP8266 开机时 是 74880, 然后就改为用户设定的值, szuser 发表于 2016-12-30 12:25
ESP8266 开机时 是 74880, 然后就改为用户设定的值,
嗯,但是我这个按照文档改了,为啥还没有办法打印出内容呢? GAgent esp8266 日志的debug 串口就已经是uart1 了。
楼主你修改了之后还是没输出,可能是你修改串口的设置在机智云修改参数之前,所以最后还是被修改为机智云默认的参数了。 本帖最后由 1112 于 2016-12-30 21:58 编辑
alex.lin 发表于 2016-12-30 19:21
GAgent esp8266 日志的debug 串口就已经是uart1 了。
楼主你修改了之后还是没输出,可能是你修改串口的设置 ...
我是直接拿宠物屋源码调试uart1的。改的地方如下:
user_init中
uart_init_3(9600,115200);
UART_SetPrintPort(1);
uart.c中365行 去掉注释
// install uart1 putc callback
os_install_putc1((void *)uart1_write_char);//print output at UART1
其他地方都没动,但就是无法输出
加入这段代码,我之前 测试过只加UART_SetPrintPort(UART1);这句不行
请加入下列代码
UART_ConfigTypeDef uart_config;
uart_config.baud_rate = BIT_RATE_74880;
uart_config.data_bits = UART_WordLength_8b;
uart_config.parity = USART_Parity_None;
uart_config.stop_bits = USART_StopBits_1;
uart_config.flow_ctrl = USART_HardwareFlowControl_None;
uart_config.UART_RxFlowThresh = 120;
uart_config.UART_InverseMask = UART_None_Inverse;
UART_ParamConfig(UART1, &uart_config);
UART_SetPrintPort(UART1);
就可以在TXD1引脚输出调试信息
页:
[1]