0
\$\begingroup\$

I'm attempting to read analogue voltage from a potentiometer by converting it into digital using ADC0804 and then passing the data onto y pc using FT232RL. As it stands the ADC0804 circuit is working properly as i have tested it using leds. However attempting to read the data using the FT232 is being problematic , my current approach is setting it to bit bang mode and then connected each I/O pin to the ADC output.

This is how i have the ADC outputs wired

This is how i have the ADC outputs wired to the board and this is the code i'm using which is just the sample code from the documentation for FT_Read() modified to run in async bit bang mode. The code i'm using

#include <stdio.h>
#include "ftd2xx.h"
#include <windows.h>
#include <stdint.h>

#define PIN_TX  0x01  
#define PIN_RX  0x02  
#define PIN_RTS 0x04  
#define PIN_CTS 0x08  
#define PIN_DTR 0x10
#define PIN_DSR 0x20
#define PIN_DCD 0x40
#define PIN_RI  0x80

int main(){
    FT_HANDLE ftHandle;
    FT_STATUS ftStatus;
    DWORD TxBytes;
    DWORD RxBytes;
    DWORD BytesReceived;
    DWORD EventDWord;
    uint8_t RxBuffer[2048];
    RxBuffer[RxBytes+1]='\0';
    ftStatus = FT_Open(0, &ftHandle);
if(ftStatus != FT_OK) {
// FT_Open failed
return 0;
}
//FT_SetBitMode(ftHandle, PIN_TX | PIN_RX | PIN_RTS | PIN_CTS | PIN_DTR | PIN_DSR | PIN_DCD | PIN_RI, 1);
FT_SetBitMode(ftHandle, 0x00, 0x01);
FT_SetBaudRate(ftHandle, 9600);
FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
if (RxBytes > 0) {
ftStatus = FT_Read(ftHandle,RxBuffer,RxBytes,&BytesReceived);

if (ftStatus == FT_OK) {
// FT_Read OK
printf("%s\n",RxBuffer);
}
else {
printf("failed");
}
}
FT_Close(ftHandle);
getchar();
}

Running this gives no output , it isn't a driver issue as the FTProg Utility picks up the device and i was able to write data to the CTS pin earlier to run an LED.

\$\endgroup\$
  • \$\begingroup\$ It's unclear what exactly you are doing as your question is missing a lot of the detail (which needs to be in the body not at a link) but overall, this is not a good approach to solving a problem; in particular, bitbanging over USB is very, very slow. Problems like this are best solved with an MCU that bundles the data for USB transmission, in some cases you may even be able to use the MCU's own ADC. \$\endgroup\$ – Chris Stratton Apr 17 at 20:13
  • \$\begingroup\$ I'm just trying to read ADC output data in a C program , i'll elaborate on anything you wish ; i am aware this is an inefficient route , i'm mostly just doing this as an exercise to familiarize myself with the FT232rl. \$\endgroup\$ – Amb1tion Apr 17 at 20:21
  • \$\begingroup\$ You need to explain your algorithm in the body of the question, and explain how your results differ from expectation. One thing to definitely watch out for is to somehow make sure that after you change configuration, you get a reading from the new configuration - that's the kind of place where USB bit-banging is horribly inefficient. \$\endgroup\$ – Chris Stratton Apr 17 at 20:25
  • \$\begingroup\$ ADC0804 is a chip with 8-bit parallel interface. It needs 11-13 wires to operate. Simultaneously. How did you manage to connect 11 wires to 4 pins of serial UART interface? \$\endgroup\$ – Ale..chenski Apr 17 at 21:51
  • \$\begingroup\$ @Chris i managed to read data by using the FT_GetBitMode() function which sends the instantaneous pin state (in one byte like 0xFF) instead of the FT_Read() function which gives a buffer of these bytes. So my connections aren't the issue it's probably that i'm handling the char buffer incorrectly. \$\endgroup\$ – Amb1tion Apr 18 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.