Hi,
I have modified the USBFTDILoopback example to read data from a device. The device has a FTDI FT232R chip.
Under Windows, all I have to do is plug it in and make the right settings. Under Ardunio, I just receive two bytes. The device is recognized correctly (Manufacturer, Product and Serialnumber).
Here are the settings I use in Windows:
Baud rate: 9600
Data bits: 8
Stop bits: 1
Parity: None
Flow Control: None
Is it a problem with the settings? Does anyone have any advice for me?
J-M-L
April 23, 2018, 2:05pm
2
what is the device? and is there a driver being used on windows ?
It's an AMB8665-M AMBER USB Stick.
In Windows it's using the Microsoft USB-Serial Driver.
Here is the code:
#include <cdcftdi.h>
#include <usbhub.h>
#include "pgmstrings.h"
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
class FTDIAsync : public FTDIAsyncOper
{
public:
virtual uint8_t OnInit(FTDI *pftdi);
};
uint8_t FTDIAsync::OnInit(FTDI *pftdi)
{
uint8_t rcode = 0;
rcode = pftdi->SetBaudRate(9600);
if (rcode)
{
ErrorMessage<uint8_t>(PSTR("SetBaudRate"), rcode);
return rcode;
}
rcode = pftdi->SetData(FTDI_SIO_SET_DATA_STOP_BITS_1);
{
ErrorMessage<uint8_t>(PSTR("SetData 1"), rcode);
return rcode;
}
rcode = pftdi->SetData(FTDI_SIO_SET_DATA_PARITY_NONE);
{
ErrorMessage<uint8_t>(PSTR("SetData 2"), rcode);
return rcode;
}
rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetFlowControl"), rcode);
return rcode;
}
USB Usb;
USBHub Hub(&Usb);
FTDIAsync FtdiAsync;
FTDI Ftdi(&Usb, &FtdiAsync);
uint32_t next_time;
void setup()
{
Serial.begin( 9600 );
Serial.println("Start");
// As it seems that initialization is a bit hit and miss
// we loop here until it works out
// until it does we print lines of .
while (Usb.Init() == -1)
{
Serial.println(".");
delay( 1000 );
}
Ftdi.SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL);
next_time = millis() + 5000;
}
void loop()
{ // JJ
char *str;
char *p;
int field,count;
long PMValue;
byte msg[5];
uint16_t len;
uint8_t rcode;
count = 0;
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
// make a buffer and clear it
uint8_t buf[64];
for (uint8_t i=0; i<64; i++)
buf[i] = 0;
uint16_t rcvd = 64;
// uint8_t FTDI::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
rcode = Ftdi.RcvData(&rcvd, buf);
Serial.println("Received");
if (rcode && rcode != hrNAK)
{
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
Serial.print("x");
}
else
{
Serial.print("!");
Serial.print(rcvd,HEX);
}
Serial.print("Received data: ");
for (uint8_t i=0; i<64; i++) {
Serial.print(buf[i],HEX);
Serial.print("|");
}
Serial.println("\n");
Serial.print((char*)buf);
Serial.println("\nEnd of received data");
delay(10000);
} //II - USB State
} //JJ - loop