Hi,
I try to receive data from an USB FTDI device (which push data every 10 secondes) then display the data in my Arduino Monitor.
The problem is (I think) I have to enable DTR and RTS from my USB Host Shield 2.0, but I don't know how to do it.
USB Configuration I need:
Baudrate: 115200
Flow Control: Only XON
DTR and RTS on
Capture local echo
Can somebody help me please ?
I'm using an Arduino UNO + USB Host Shield 2.0.
My code:
#include <SD.h>
#include <adk.h>
#include <cdcftdi.h>
//#include <usbhub.h>
#include "pgmstrings.h"
class FTDIAsync : public FTDIAsyncOper
{
public:
virtual uint8_t OnInit(FTDI *pftdi);
};
uint8_t FTDIAsync::OnInit(FTDI *pftdi)
{
uint8_t rcode = 0;
rcode = pftdi->SetBaudRate(115200);
if (rcode)
{
ErrorMessage<uint8_t>(PSTR("SetBaudRate"), rcode);
return rcode;
}
rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL, FTDI_SIO_XON_XOFF_HS);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetFlowControl"), rcode);
return rcode;
}
int led = 13;
USB Usb;
//USBHub Hub1(&Usb);
FTDIAsync FtdiAsync;
FTDI Ftdi(&Usb, &FtdiAsync);
uint32_t next_time;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(115200);
//For usb
if (Usb.Init() == -1) {
Serial.println("KO: OSC did not start.");
}
else {
Serial.println("OK: OSC start.");
}
delay( 2000 );
next_time = millis() + 5000;
//End for usb
}
// the loop routine runs over and over again forever:
void loop() {
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
digitalWrite(led, HIGH);
uint8_t rcode;
uint8_t buf[64];
for (uint8_t i=0; i<64; i++)
buf[i] = 0;
uint16_t rcvd = 64;
rcode = Ftdi.RcvData(&rcvd, buf);
Serial.println(rcvd);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
// The device reserves the first two bytes of data
// to contain the current values of the modem and line status registers.
if (rcvd > 2)
Serial.print((char*)(buf+2));
delay(10);
digitalWrite(led, LOW);
}
}
Thank you in advance.