DeqingSun / ch55xduino

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

USBSerialAdaptor不能切换到Serial1 #97

Closed pythoniot closed 1 year ago

pythoniot commented 1 year ago

编译示例文件USBSerialAdaptor的时候,使用Serial0可以正常使用,但是切换为Serial1的时候,不能正常收发数据, 主要是想使用CH552E的MSOP10小封装,只有Serial1可用

test1025 commented 1 year ago

您好,看到了您issue,我最近也在研究这个单片机的Serial,问一下您使用Serial1的时候能正常的接收数据吗?我尝试好长时间都收不到,发送倒是正常

DeqingSun commented 1 year ago

Can not reproduce any problem with the following code.

extern __xdata uint8_t LineCoding[]; //lineCoding of CDC is located in this array
__xdata uint32_t oldBaudRate = 9600;

void setup() {
  Serial1_begin(9600);
}

void loop() {
  if (USBSerial_available()) {
    char serialChar = USBSerial_read();
    Serial1_write(serialChar);
  }
  if (Serial1_available()) {
    char serialChar = Serial1_read();
    USBSerial_write(serialChar);
  }

  __xdata uint32_t currentBaudRate = *((__xdata uint32_t *)LineCoding); //both linecoding and sdcc are little-endian

  if (oldBaudRate != currentBaudRate) {
    oldBaudRate = currentBaudRate;
    Serial1_begin(currentBaudRate);
  }

}