CH554E 的评估版板 CH554EVT.ZIP 中软件 printf 的LOG 是否是输出到UART中?

我问一下,在CH554E评估板资料中,CH554EVT.ZIP -> CH554EVT\EVT\EXAM\USB\Host->USBHostHUB_KM.C, printf 打印的调试信息是否是输出到UART中? 是不是从评估板 CH554 T&E&G MINIEVT2@1710 中的P1的USB口(UART) 中输出的...

Keil C51 uses putchar() for printf(). The default putchar() funktion uses SIO0 and is located in the keil directory in c. If you want tu use printf() on SIO1 just add your own putchar() funtion in your source code.


putchar() does not use the sio interrupt. just make sure to set U1TI = 1 , before the first printf(). Ofcourse you also have to setup the baudrate before too.


hi usbman:

????can we talk this with in chinese?

????um....

????I am the new guy for the USB and CH554E.

?????um...

????I get 3 points from you comments:

????1. The "putchr? for printf()" defaul code for the USB host demo named USBHostHum_KM.c ?just use the SIO0 ( UART 0 ) as hardware output interface.

????????UART0 : P1.2 & P1.3? or P3.0 P3.1(UART0 )

????????UART1: P1.6 & P1.7? or P3.2 P3.4(UART1)

????2. I should rewrite putchr funtion for the printf to UART1 (CH554E use P1.6 and P1.7 )

????3. Must set U1TI = 1 and must set?baudrate?


Did any other code show I modify ? or Did you have the modifed code to share with me ???



hi usbman:


   um... 
   I check the CH554EVB souce , and got the UART1 demo , I will check and sample study it. 

   um.... 

   Does it work  with  USBHostHum_KM.c ? we do not discuss this printf funciton now.

   I just want print the keyboard key code's value to UART1 (CH554E,P16 and P17) 

   so , As i understand...

   I just inclue the uart1.h to USBHostHum_KM.c and then find some place to call 

   1. call UART1Init in the beging of main in the USBHostHum_KM.c

   2. call CH554UART1SendByte in some plate of USBHostHum_KM.c's main 

  

  Is't right ? I want fix this before I build the new hardware.


ok I will try to answer but in enhlish only because I am from Europe


  1. putchar() and printf() are part of c runtime library so if you dont change anyting printf() uses the putchar from the lib and therefore any printf() goes to SIO0.

  2. if you want to use printf on SIO1 you have to provide your own putchar function. The linker will reconize it and uses your putchar instead of the library one.

  3. printf() does not use IRQ therefore SIO1 IRQ must be disabled and U1TI must be set to 1.


Here some (untested) code:


#define BAUDRATE 9600

#define FSYS     6000000 //default speed after power on


void Sio1Init(unsigned char alternate)

{

   IE_UART1 = 0;

   if (alternate) PIN_FUNC |=   bUART1_PIN_X; //select the sio1 pinpair

   else              PINFUNC &= ~bUART1_PIN_X;

   

   U1SMOD = 1;

   SBAUD1 = 256- (FSYS / 16 / BAUDRATE) ;

   U1T1 = 1;

}


for more info check \c51\lib\putchar.c\

/*

 * putchar (mini version): outputs charcter only

   for CH554 SIO1

 */

char putchar (char c)  

{

  while (!U1TI);

  U1TI = 0;

  return (SBUF1 = c);

}



您好,

先感谢usbman的积极参与,我从您一开始提的问题应该是想问那个评估板是不是可以用上面的usb口直接链接电脑打印,答案是可以的,ch554的评估板上,那个'调试丝印'的usb口是板载了一个ch340,您可以通过边上的串口跳冒选择那个usb口链接到的串口引脚,可以再看下pub文件夹的原理图。

上面提到的print重定向方法您也可以再研究下

您也可以将问题描述时配上您手上板子的配图辅助我们理解问题。


hi  usbman:


    yeah , thanks for your stronly support, thanks again. 

   I have understand your meanings , and clear what show I do .

   Thank you very very much again.


hi  TECH29:


    我说一下我目前的情况 和 需要做到的 目标(我头一次自己设计HW,想完成自己产品中的一部分)

    目前情况:

    1. 手上 没有CH544EVT 的评估板(也就是https://www.wch.cn/products/CH554.html 开发资料 ->CH554EVT.ZIP ->CH554EVT\EVT\PUB\CH554EVT.pdf 中提到的  "CH554MINIEVT2@1711(新版)" 评估板)

    

     我的目标:

     1. 我要利用CH554解析 USB键盘上的每一个键值,比如"K"

     2. 然后将键值“K",通过串口(/或者其他通讯方式)发送给 其他的MCU。


     我的计划:

            硬件计划:1. 按照 《CH554 T&E&G MINIEVT2@1710 评估板原理图:(新版)》原理图

                                 2. 删除 JP1,U2,U4,JP2,U5, J1等等,(只用5V供电,VDO给5V,V33不接)

                                 3. 让P1.6和P1.7 当做串口,链接到我的MCU上(我从CH554SCH.PDF理解CH554只有串口1,没有串口0 )

              软件计划:

                                1. 利用CH554EVT.ZIP -> USBHostHum_KM.c source中的printf函数把,”K"键值,通过串口P1.6&P1.7发送到我的MCU中。


      我的问题和理解:

             1. 我理解,CH554EVT.ZIP -> USBHostHum_KM.c source(我利用这个Demo)中的printf的内容,针对我上述的 <硬件计划> ,是打印不到我的MCU的。因为CH554 只有UART1 ,没有UART0 ,所以printf打印不出来。(此问题也是通过 usbman 告诉才意识到的


            2. 所以,我需要在USBHostHum_KM.c 中加入UART1.h 的 UART1Init()的初始化  ,然后在适当的位置调用 CH554UART1SendByte()发送出来“K"的Data即可?这样我的MCU就能收到”K"的Data 。   我的理解是否正确?



      我需要自己设计硬件->打板->软件编译->下载,所以我希望这整个过程 能够清晰,所以提交了此贴。

 




您好,

1,是的,CH554E没有UART0的引脚,可以考虑使用更大封装的CH554G/T或者可以考虑使用CH32X035

2,您的理解正确,可以初始化UART1后,考虑使用print重定向到UART1或者直接调用CH554UART1SendByte函数发送串口数据


hi  TCECH29 :


    非常感谢你的答复,我尝试打板验证一下。


hi TECH29:


   我还有一个问题, 我参照 《CH554 T&E&G MINIEVT2@1710 评估板原理图:(新版)》原理图


   我也放上去了CH340C,我打回来板子,CH340C 是否需要烧录 固件(firmware)才能从USB接收到554的UART1 数据?

   如果需要,能否告诉我哪里下载固件以及下载的方法和工具?



hi  TECH29:


    我看了CH340的链接:https://www.wch.cn/products/CH340.html?from=list 如下描述

    是不是CH340C 芯片买回来后,里面就有USB 转 UART的功能 我无需下载 固件(firmware)

    备注:   如果要是方便,能否共享一下CH340C的固件,以及下载的方法 和 工具?

特点

  • 全速USB设备接口,兼容USB V2.0。

  • 仿真标准串口,用于升级原串口外围设备,或者通过USB增加额外串口。

  • 计算机端Windows操作系统下的串口应用程序完全兼容,无需修改。

  • 硬件全双工串口,内置收发缓冲区,支持通讯波特率50bps~2Mbps。

  • 支持常用的MODEM联络信号RTS、DTR、DCD、RI、DSR、CTS。

  • 通过外加电平转换器件,提供RS232、RS485、RS422等接口。

  • CH340R芯片支持IrDA规范SIR红外线通讯,支持波特率2400bps到115200bps。

  • 内置固件,软件兼容CH341,可以直接使用CH341的VCP驱动程序。

  • 支持5V电源电压和3.3V电源电压。

  • CH340C/N/K/E/X/B内置时钟,无需外部晶振,CH340B还内置EEPROM用于配置序列号等。

  • 提供SOP-16、SOP-8和SSOP-20以及ESSOP-10、MSOP-10无铅封装,兼容RoHS。



您好,

CH340无需下载固件,接口芯片,固定用法的,详情参考他的手册:

https://www.wch.cn/downloads/CH340DS1_PDF.html


hi TECH29 :


     非常感谢你的答复


只有登录才能回复,可以选择微信账号登录