DeqingSun / ch55xduino

An Arduino-like programming API for the CH55X
GNU Lesser General Public License v2.1
433 stars 85 forks source link

0.014版本ADC和外部晶振问题 #91

Closed perseverance51 closed 1 year ago

perseverance51 commented 1 year ago

非常感谢您对本项目的持续维护!在使用当前版本0.014版本测试当中,发现以下2点bug:

  1. 选择型号CH552,跑AnalogReadSerial示例,读取的ADC值比较小,范围:0-127,相同示例下,选择CH559,读取ADC值范围:0-2047;
    1. CH559选择外部24MHz晶振时,编译正常,运行时无法识别到CDC虚拟串口,选择内部24MHz正常,有CDC虚拟串口。 V0.014解决了CDC虚拟串口报错问题,但是并没有实现通过CDC虚拟串口实现代码的上传,还是需要借助WCHISPTool工具进行程序的烧录。其他示例和功能还未进行测试。
DeqingSun commented 1 year ago

@perseverance51

选择型号CH552,跑AnalogReadSerial示例,读取的ADC值比较小,范围:0-127 I got 255 when I test with CH552 and connect P1.1 to 5V. The 0~2047 on CH559 is intentional, wiring_analog.c samples analog pin with 11bits.

CH559选择外部24MHz晶振时,编译正常,运行时无法识别到CDC虚拟串口. The external oscillator option assumes your external oscillator works at the same frequency as the internal one, which is 12MHz. I've tested my CH559 with 12M external oscillator and they worked. If you have another frequency, you need to set CLOCK_CFG.

The CDC upload has been tested on Mac OS, Win10 and Win XP virtual machine. They all can upload with CDC. captureXP Capturewin10

If you still get errors, would you provide your error message?

perseverance51 commented 1 year ago

`------------------------------------------------------------------ CH55x Programmer by VNPro

Load file as hex Loaded 4776 bytes between: 0000 to 12F4 ch375Version 35 CH375GetUsbID 55e04348 CH375 open OK MCU ID: 59 11 Found Device CH559 `

if BOOT_LOAD_ADDR == 0x3800

    USB_CTRL = 0;
    EA = 0;                     //Disabling all interrupts is required.
    TMOD = 0;
    delayMicroseconds(50000);
    delayMicroseconds(50000);
   delayMicroseconds(50000);

    __asm__ ("lcall #0x3800");  //Jump to bootloader code

    while(1);

elif defined(CH559) && (BOOT_LOAD_ADDR == 0xF400)

    USB_CTRL = 0;
    EA = 0;                     //Disabling all interrupts is required.
    delayMicroseconds(50000);
    delayMicroseconds(50000);
    delayMicroseconds(50000);

    __asm__ ("lcall #0xF400");  //Jump to bootloader code

    while(1);

elif BOOT_LOAD_ADDR == 0xF400

    //todo: not working well, CH549 doesn't support direct jump

endif

}

} `

DeqingSun commented 1 year ago

@perseverance51 Thanks for reporting the issue. That is very likely to be caused by the erase command in https://github.com/DeqingSun/vnproch551/blob/master/main.cpp The current version only erase 8 pages (8 1024) for CH559. And you get error on pack 146 (146 56=8176) because it was not erased before flashing.

I'll take a look and fix it tonight.

DeqingSun commented 1 year ago

@perseverance51 The new 0.0.15 release fixes the flash issue on CH559.