Forum: Mikrocontroller und Digitale Elektronik Issues FT245


von Franz P. (Firma: franck) (franziski)


Lesenswert?

As first exercise with FT245 I would to turn on two LEDs. So I wrote the 
following code [taken from this forum and adapted]. The software 
compiles but the LEDs keep on turned off...except for that one connected 
to DB1 pin of FT245 (that is always ON...). Here it is the code:

// FTDI.cpp : Defines the entry point for the console application.


//#include "stdafx.h"

#include <windows.h>

#include <stdio.h>

#include "ftd2xx.h"

typedef unsigned char UCHAR;

FT_HANDLE fthandle;
FT_STATUS status;



void Reload()

{

  FT_Reload(0403,6010);
  FT_Rescan();
  Sleep(1000);


    // Open device #0 and save in handle variable the task handle

  status = FT_Open(0, &fthandle);


    // Try again the open if previuos opening failed

  while( status != 0) {
    status = FT_Open(0, &fthandle);
  }

  // Prints a message
  printf("[OK] Device successfully opened...\n");

}



int main(int argc, char* argv[])

{


  Reload();


/************************************************************/

// Reset

  status = FT_ResetDevice(fthandle);

              if(status == FT_OK) {

              printf("[OK] Device reset...\n");

                    //Reload();

        } else printf ( "Error!\n");



/************************************************************/

// Timeout

 DWORD rTimeout=1000;
 DWORD wTimeout=1000;


 status = FT_SetTimeouts(fthandle,rTimeout,wTimeout);



                   if(status == FT_OK)  {

               printf("[OK] Read/Write timeout successfully set to %d/%d 
(ms)...\n", rTimeout, wTimeout);

                     //Reload();
           } else printf ("Error!\n");


/************************************************************/

// Baudrate


 status = FT_SetBaudRate(fthandle, 9600);



                   if(status == FT_OK) {

                      printf("[OK] Baudrate set to 9600..\n");

                     //Reload();
           }


/************************************************************/


// Make a reset


UCHAR mask = 0xFF; // pin all to output
UCHAR mode = 0;    // reset code





 status = FT_SetBitMode(fthandle, mask, mode);



        if(status == FT_OK) {

          printf("[OK] Device Reset...\n");

        } else printf ("Error!\n");



/************************************************************/

// Set asincron bit-bang

mask = 0xFF;
mode = 1;





 status = FT_SetBitMode(fthandle, mask, mode);


  if(status == FT_OK) {

          printf("[OK] Set asyncron mode...\n");

        } else printf ("Error!\n");






/************************************************************/

// Write

DWORD byteWritten = 0;

UCHAR buffer[] = { 128 };  // Turn on LED #2 and LED #8



        status = FT_Write (fthandle,
                   buffer,
                 1,
                 &byteWritten);


                if(status == FT_OK) {
                   printf("[OK] Data wrote successfully...\n");

        } else printf ("Error!\n");


/************************************************************/

// Close

   FT_Close(fthandle);



   return 0;



}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.