0
\$\begingroup\$

I'm working on android drivers (native code) for CH340G USB-to-serial chip. I've successfully tested it with baudrate 115200 and Arduino Uno CH340G but for some reason it does not work with baudrate 57600 and Arduino Nano CH340G.

I've looked at linux drivers code:

static int ch341_set_baudrate(struct usb_device *dev,
121                               struct ch341_private *priv)
122 {
123         short a, b;
124         int r;
125         unsigned long factor;
126         short divisor;
127 
128         if (!priv->baud_rate)
129                 return -EINVAL;
130         factor = (CH341_BAUDBASE_FACTOR / priv->baud_rate);
131         divisor = CH341_BAUDBASE_DIVMAX;
132 
133         while ((factor > 0xfff0) && divisor) {
134                 factor >>= 3;
135                 divisor--;
136         }
137 
138         if (factor > 0xfff0)
139                 return -EINVAL;
140 
141         factor = 0x10000 - factor;
142         a = (factor & 0xff00) | divisor;
143         b = factor & 0xff;
144 
145         r = ch341_control_out(dev, 0x9a, 0x1312, a);
146         if (!r)
147                 r = ch341_control_out(dev, 0x9a, 0x0f2c, b);
148 
149         return r;
150 }

What's wrong? Is there any difference between 340 and 341 in terms of setting baud rate? ANy suggestions are appreciated.

\$\endgroup\$
1
\$\begingroup\$

Not sure what's wrong but i've found ready magic values for baud rate 57600 here: http://www.codota.com/android/scenarios/52fcbcdbda0ad7268260dfcd/android.hardware.usb.UsbDeviceConnection?tag=dragonfly

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.