CH9102x USB-Serial Data Corruption --- 7-n-1 vs 8-n-1 - Page 1
Forum section: electronics / projects

author: sleemanj
author_rank: Super Contributor
timestamp: November 29, 2022, 01:32:05 am
content: Scratching my head here.USB-UART modules out of China which have replaced the old classic CP2102 with the pin-compatible WCH CH9102xAn Arduino Pro-Mini with the ASCII table example sketch on it at 9600 BaudConnect an original CP2102 module to it ( /dev/ttyUSB0 ), works fine, correct output.Code:ASCII Table ~ Character Map!, dec: 33, hex: 21, oct: 41, bin: 100001", dec: 34, hex: 22, oct: 42, bin: 100010#, dec: 35, hex: 23, oct: 43, bin: 100011$, dec: 36, hex: 24, oct: 44, bin: 100100Connect the new CH9102x module to it ( /dev/ttyACM0 - CDC driver ), garbage.Code:�"��: LLb hY� 6�z��i �M�n����1�L�Hp"�c�����.��i �b"��:�1�B��If I change the serial terminal (separate serial terminal, not the one in the Arduino IDE which can't change that) to 7-n-1 instead of 8-n-1 then I get maybe 95-98% correct output from the CH9102xCode:ASCII Table ~ Chara#ter Map!, dec: 33, h%x: 21, oct: 41, "in: 100001", dec: 34, he8: 22, oct: 42, b)n: 100010#, dec: 35, he8: 23, o#t: 43, bin: 100011$, $ec: 36, he8: 24, oct: 44, bin: 100100This is even though the Arduino sketch is unchanged and should be sending 8-n-1 (as evidence by the fact that the CP2102 module is correct output at 8-n-1).My best guess is that there is some bit timing issue with the CH9102x and it's most of a bit-length out? Any better ideas?

author: NiHaoMike
author_rank: Super Contributor
timestamp: November 29, 2022, 02:31:12 pm
content: Connect a scope and see if some weird stuff is happening with the signals.

author: voltsandjolts
author_rank: Unknown
timestamp: November 29, 2022, 02:49:13 pm
content: Adafruit seem to be using CH9102Fsuccessfullyas CP2102 replacement. Yeh, check the bit width.

author: sleemanj
author_rank: Super Contributor
timestamp: November 29, 2022, 08:48:01 pm
content: A scope sounds sensible, except that the problem seems more likely on the unscopable USB side not the serial side which is only receiving from the arduino, that a cp2102 is fine with. Hmm, could be marginal timing on the arduino I guess, seems unlikely though.I'll dig the scope or logic analyzer out and capture what the arduino sends.

author: sleemanj
author_rank: Super Contributor
timestamp: November 29, 2022, 11:31:39 pm
content: Transmission timing looks OK to me it is well within 1% of a bit length according to the logic analyzer.Here is with the CP2102 attached, the arduino sending a constant string of "U" (binary 10101010 for convenience), this is received in the serial terminal fine.Here it is with the CH9102x attached, same code, no changes just swapped the serial device, looks perfect to me in the logic analyzer, but the serial terminal is periodically corrupt characters.Weird. I wonder if it's a voltage supply problem maybe. My USB is down at 4.78v, Might have to see if I can find a powered hub around here somewhere.

author: sleemanj
author_rank: Super Contributor
timestamp: November 30, 2022, 01:59:34 am
content: Transmitting from the CH9102x at 9600 shows it is running fast with a bit-length error of 2.7%While the CP2102 is bang on.I'm thinking that the CH9102x modules I have just have really really poor timing.

author: sleemanj
author_rank: Super Contributor
timestamp: November 30, 2022, 02:06:52 am
content: According to the datasheet the error for transmission should be less than 1.5% (and reception less than 2%), so these seem to be waaaaay out of spec.I tried at a full 5v, didn't make any difference (it internally drops to 3.3 anyway so I'm not surprised).Seems like these go in the junk pile.

author: sleemanj
author_rank: Super Contributor
timestamp: November 30, 2022, 02:38:55 am
content: Hah! Solved!Needs an closer decoupling cap on V3 pin, add that and the error reduces far under 1%, reception is normal, and it all works.Frick'n Chinese designer "where should we put this decoupling cap? oh as far away as possible from the IC seems good, and just for fun make the trace meander around as much as possible and go through at least two vias before it gets there".