SerialUSB Arduino Problems
Lothar (3292) 134 posts |
In the beginning, thanks for any help. I am trying to make my Linux code for Arduino serial request-response work under RISC OS by using SerialUSB and ran into various problems. To be safe I first tried an Arduino UNO Plus which has an FTDI chip. This works perfectly with my code. This is how SerialUSB shows it: Device name: 'SerialUSB' Vendor: 0403 Product: 6001 Version: 0600 Serial number: 'A106TPWM' Description: 'FTDI. FT232R USB UART' Underlying USB device name: 'USB7' Interface number: 0 Location: 00000000 00040101 Then I tried a regular Arduino UNO with Atmega16U2. With this my code is loosing one character from each Arduino response. It is not always the same character. It is dependent on timing. Possibly I make something wrong in my RISC OS code. This is how SerialUSB shows it: Device name: 'SerialUSB' Vendor: 2341 Product: 0042 Version: 0001 Serial number: '8573531393235180A170' Description: 'CDC Device, Arduino (<a href="http://www.arduino.cc">www.arduino.cc</a>)' Underlying USB device name: 'USB7' Interface number: 1 Location: 00000000 00040101 And then I tried the new Arduino Nano Every. It has the same Atmega16U2, but SerialUSB does not show it. USBDescriptors says this on a Pi 3B+ Computer | +-1.USB1: , Synopsys DWC OTG root hub | +-1.USB2: Hub | +-1.USB3: | +-2.USB4: USB2.0 Hub | | | +-2.USB5: Logitech, USB Optical Mouse | | | +-3.USB6: , USB Keyboard | +-4.USB7: Arduino LLC, Arduino Nano Every Regarding my RISC OS code, as said, it works without problem on the Arduino UNO Plus with FTDI chip, but has trouble with regular Arduino UNO with Atmega16U2. So is the problem with my code? Does the Atmega16U2 require handshake? Or could it be some buffering problem inside SerialUSB? OS_GBPB 4 remaining = 1 int VCOM_receive(char *buf, int size) { ... int remaining = XOS_GBPB(4, INPUT, (int) buf, size, 0, 0); if (VFLAG) { printf("Error: Receive\n"); return 0; } return remaining; } int VCOM_send(char *buf, int size) { ... int remaining = XOS_GBPB(2, OUTPUT, (int) buf, size, 0, 0); if (VFLAG) { printf("Error: Send\n"); return 0; } return remaining; } void VCOM_init(void) { char port[] = "SerialUSB#noblock;nohandshake;baud=9600;data=8;stop=1;noparity:"; ... Finally, just to mention it, when making a direct serial connection between Arduino RX/TX/GND pins and Pi TX/RX/GND pins, and using RISC OS OS_SerialOp – then it works without problem for all Arduino types. But I would really prefer the USB connection. ... // send request OS_SerialOp(SERIALOP_SEND_BYTE, request[0], 0); ... OS_SerialOp(SERIALOP_SEND_BYTE, request[7], 0); ... // wait for completion delay(WAIT); // receive response unsigned short idx = 0; do { unsigned char ch = OS_SerialOp(SERIALOP_GET_BYTE, 0, 0); // received byte if (CFLAG == 0) response[idx++] = ch; // 8 bytes max. if (idx >= 8) break; } while (CFLAG == 0); // clear buffer do { OS_SerialOp(SERIALOP_GET_BYTE, 0, 0); } while (CFLAG == 0); // wait for completion delay(WAIT); ... void SERIAL_init(void) { // TX %100 UART0 TX GPIO_WriteMode(14, 4); // RX %100 UART0 RX GPIO_WriteMode(15, 4); // state = R1 ^ (state & R2) // 0 : 0 : no software handshake // 1 : 1 : no DCD // 2 : 1 : no DSR // 3 : 0 : DTR active // 4 : 1 : no CTS // 5 : 1 : no hardware handshake // 6 : 0 : input active // 7 : 0 : RTS low // %0011|0110 = &36 OS_SerialOp(SERIALOP_STATES, 0x00000036, 0xFFFFFF00); // receive enable OS_Byte(STREAM_IN, KEYBOARD_AND_SERIAL); // 8-bit : no parity : 1-stop OS_SerialOp(SERIALOP_FORMAT, FORMAT_8N1, 0); OS_SerialOp(SERIALOP_RECEIVE_BAUD, BAUD_9600, 0); OS_SerialOp(SERIALOP_TRANSMIT_BAUD, BAUD_9600, 0); } |
Colin (478) 2433 posts |
I have an Arduino UNO with Atmega16U2 that I use to test SerialUSB. It doesn’t require a handshake. If you have an arduino sketch that fails with a test riscos program that reads the arduino you could send them both to me and I’ll see what I can do. My address is on my ftpc website. |
Lothar (3292) 134 posts |
I just sent the request-response programs. Many thanks for your help. |