1
\$\begingroup\$

I would like to know if in adroid it is possible to have baud rates different from the default ones for usb communication with a pcb / arduino board, I would like to send a frame with a particular baud rate: 31500 (this rs232 has this particular baud rate) but unfortunately the frame goes with a baud rate of 38400 (standard one). It seems like android sends the frame only with the common baud rates. Thanks in advance for response.

This is the part where I configure the baud rate:

private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { //Broadcast Receiver to automatically start and stop the Serial connection.
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION_USB_PERMISSION)) {
            boolean granted = intent.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);
            if (granted) {
                connection = usbManager.openDevice(device);
                serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
                if (serialPort != null) {
                    if (serialPort.open()) { //Set Serial Connection Parameters.
                        setUiEnabled(true);
                        serialPort.setBaudRate(31500);
                        serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
                        serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
                        serialPort.setParity(UsbSerialInterface.PARITY_NONE);
                        serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
                        serialPort.read(mCallback);
                        tvAppend(textView,"Serial Connection Opened!\n");

                    } else {
                        Log.d("SERIAL", "PORT NOT OPEN");
                    }
                } else {
                    Log.d("SERIAL", "PORT IS NULL");
                }
            } else {
                Log.d("SERIAL", "PERM NOT GRANTED");
            }
        } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
            onClickStart(startButton);
        } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
            onClickStop(stopButton);

        }
    }

    ;
};
\$\endgroup\$

closed as off-topic by SamGibson, brhans, Marcus Müller, Dave Tweed Mar 18 at 12:19

  • This question does not appear to be about electronics design within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ Welcome :-) This looks like an Android programming question, not an electronics design question, and so would be more on-topic on the Android Stack Exchange site. I recommend that you join there, ask your question there, and (importantly) delete it from here - duplicates across on multiple sites are discouraged. Thanks. \$\endgroup\$ – SamGibson Mar 18 at 11:25
  • 2
    \$\begingroup\$ I'm voting to close this question as off-topic because it belongs on Android Stack Exchange. \$\endgroup\$ – SamGibson Mar 18 at 11:26
  • 1
    \$\begingroup\$ @SamGibson No, Android stack exchange is only for end-user questions, development questions are not permitted there. Further this isn't really about Android at all - the baud rate is a configuration of the USB serial chip so changing it is about sending the proper USB (presumably control) request. The actual subject matter is the the (unfortunately unidentified) USB serial chip or this "UsbSerialDevice" class which is not an standard Android one but rather something the asker has found somewhere. \$\endgroup\$ – Chris Stratton Mar 18 at 13:49
  • 1
    \$\begingroup\$ @ChrisStratton - Thanks for the info re Android Stack Exchange - my bad on that. \$\endgroup\$ – SamGibson Mar 18 at 20:04
  • 1
    \$\begingroup\$ The answer to the actual question is that each USB serial chip implements this in its own way. Some may support arbitrary rates, others may not. It looks like the asker is using something like github.com/felHR85/UsbSerial which just passes the requested value through to the device specific class. A practical solution would be a custom USB/CDC implementation on a microcontroller with firmware specifically crafted to be able to achieve the desired baud rate. This would likely be a small variation on a sample project, and USB/CDC supports passing an arbitrary request to the MCU. \$\endgroup\$ – Chris Stratton Mar 18 at 20:24

Browse other questions tagged or ask your own question.