Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
USBHostSerial buffers and functions - talking to FTDI chip
Hi,
I am trying to use an MBED to control a GPIB instrument, by using this GPIB-USB converter (http://prologix.biz/gpib-usb-controller.html) (which uses an FDTI chip) and then using the serial host library to send SCPI commands.
So far, I am able to talk to the prologix device, get the model identifier, set the GPIB address and get data from a *IDN? query on the instrument, but I'm unable to get any data. Longer SCPI commands just don't work at all. My output data also appears embedded in '1'1'1'1'1'1'1'1 arrays, and sometimes doesn't appear on the first few calls of the loop. I assume that something is up with the way I'm using the buffers, but I can't see a better way of doing it, and there doesn't seem to be much documentation of the functions for the latest version - I would like to use an event handler really, but I'm not sure if this is possible?
Here is my (very crude) code:
USB serial host code
#include "mbed.h" #include "USBHostSerial.h" DigitalOut led(LED1); Serial pc(USBTX, USBRX); int i; int main() { pc.printf("\nMain started \r\n"); USBHostSerial serial; char str[1]; int len; while(1) { wait(1); pc.printf("Start\r\n"); // try to connect a serial device while(!serial.connect()) pc.printf("Trying to connect \r\n"); wait(1); pc.printf("Connected \r\n"); // in a loop, print all characters received // if the device is disconnected, we try to connect it again while (1) { serial.printf("*IDN?\r\n"); // send SCPI command led=!led; // if device disconnected, try to connect it again if (!serial.connected()) break; i = 0; // print characters received while (serial.available()) { pc.printf("%c", serial.getc()); i++; } pc.printf(" (%d)\r\n\n", i); wait(0.3); } } }
Any help would be very much appreciated :-)
Cheers,
Tom
1 Answer
9 years, 6 months ago.
So, I have made some progress, but there are still a few things that puzzle me. I've kept more or less the same structure, but clear the buffer at some strategic points, and put in some delays here and there - but these were done more by trial and error rather than by design... I also had missed putting the two pull-down resistors on the data lines, which have helped matters. However, I still get the '1'1'1'1'1'1' 'noise' coming through (this doesn't happen at all when I use the USB device normally on a PC). My data comes amongst this noise and I can't always filter it out. I've also noticed that it gets worse when I have high currents running on a test rig nearby, so am of course wondering if it is noise-related, but I don't understand why it doesn't do it on the PC at all. I wondered if it might be some sort of FTDI timeout thingy?
Assigned to
9 years, 6 months ago.This means that the question has been accepted and is being worked on.
S
posted by Tom Hillman 11 May 2015