Recently I found a topic "Arduino uno clone -- USB Host Shield -- Arduino uno clone (USB Device), Nov 2019 by ardcp".
I found it useful in testing to see if it would work on a project I testing at the moment.
Setup
Arduino Pro Mini 3.3v connected to a MAX3421E USB HOST board.
This USB Host PCB connects to the Arduino Pro Mini pin for pin like an expansion board.
FTDI232 to program the Arduino via the Arduino IDE v2.2.1.
Connected to the USB Host is a Sparkfun CH340 PCB and I have the TXO and RXI pins connected together.
So whatever the CH340 receives it transmits back out.
Now, ardcp did some really nice work and developed a CH340 driver which with his demo program, sends a string of characters to the ch340, they are looped back, received by the Arduino and sent to the serial port for viewing.
This works great.
In playing around with the sample code, I increased the size of the string to a point where there is nothing being sent back from the ch340. I found this limit to be 31 characters.
Here is the loop routine
void loop()
{
uint8_t buf[64];
Usb.Task();
//if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) {
if (ch340.isReady()) {
uint8_t rcode;
char strbuf[] = "DEADBEEF\n";
//char strbuf[] = "123456789012345678901234567890\n"; //ok
//char strbuf[] = "1234567890123456789012345678901\n"; //doesnt work
//char strbuf[] = "The quick brown fox jumps over the lazy dog\n";
//char strbuf[] = "This string contains 61 character to demonstrate CH340 buffers"; //add one symbol to it to see some garbage
Serial.print(".");
rcode = ch340.SndData(strlen(strbuf), (uint8_t*)strbuf);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
delay(50);
for (uint8_t i = 0; i < 64; i++)
buf[i] = 0;
uint16_t rcvd = 64;
rcode = ch340.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
if (rcvd) {
Serial.print((char*)(buf));
}
delay(5000);
}
}
I thought by increasing the buffer size "buf[64]" and maybe also "rcvd=64" this would help, but no luck. I also played around with the RcvData routine and inTransfer routine. No luck.
Now, my limit is 31 characters, not 64 as I thought it would be.
Can anyone give me an idea what is going on here.
I have linked the Topic here