FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Show Posts

You can view here all posts made by this member. Note that you can only see posts made in areas to which you currently have access.

Messages - Vijay

Pages: [1]
1
Discussion - Software / Re: FT4232 libmpsse SPI interface
« on: June 22, 2021, 05:44:01 AM »
Hello FTDI Community. Kindly help me to resolve my problem which I mentioned above.

2
Discussion - Software / FT4232 libmpsse SPI interface
« on: June 21, 2021, 01:14:06 PM »
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ftd2xx.h"
#include "libMPSSE_spi.h"
#include "QDebug"

uint8 buffer[256] = {0};
 FT_HANDLE ft4232_handle=NULL;
 FT_STATUS read_byte( unsigned short address, unsigned char *data)
 {
     unsigned short spi_addr;
     spi_addr=address;
     uint32 sizeToTransfer = 0;
     uint32 sizeTransfered;
     FT_STATUS status;

         sizeToTransfer=2;
         sizeTransfered=0;
         buffer[0] = (unsigned char)spi_addr>>8;
         buffer[1]=(unsigned char)spi_addr;

         status = SPI_Write(ft4232_handle, buffer, sizeToTransfer, &sizeTransfered,
             SPI_TRANSFER_OPTIONS_SIZE_IN_BYTES|
             SPI_TRANSFER_OPTIONS_CHIPSELECT_ENABLE);

         //read 1 byte
         sizeToTransfer=1;
             sizeTransfered=0;
             status = SPI_Read(ft4232_handle, buffer, sizeToTransfer, &sizeTransfered,
                 SPI_TRANSFER_OPTIONS_SIZE_IN_BYTES|
                 SPI_TRANSFER_OPTIONS_CHIPSELECT_DISABLE);
             *data=buffer[0];

             return status;
    }
 FT_STATUS write_byte( unsigned short address, unsigned char data)
  {
      unsigned short spi_addr;
      spi_addr=address;
      uint32 sizeToTransfer = 0;
      uint32 sizeTransfered;
       FT_STATUS status;
      sizeToTransfer=3;
      sizeTransfered=0;
      bool state;
      buffer[0] = (unsigned char)spi_addr>>8 ;
      buffer[1]=(unsigned char)spi_addr;
        buffer[2] = data;
          status = SPI_Write(ft4232_handle, buffer, sizeToTransfer, &sizeTransfered,
              SPI_TRANSFER_OPTIONS_SIZE_IN_BYTES|
              SPI_TRANSFER_OPTIONS_CHIPSELECT_DISABLE|
              SPI_TRANSFER_OPTIONS_CHIPSELECT_ENABLE);
          return status;
  }
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::on_pushButton_clicked()
{
    Init_libMPSSE();

    FT_STATUS ftStatus;
    FT_DEVICE_LIST_INFO_NODE listinfo;
    uint32 channel_cnt=0;

    ftStatus=SPI_GetNumChannels(&channel_cnt);
        if(FT_OK!=ftStatus)
            qDebug() << "FT4232 channel_cnt --> failed";
        else
            qDebug() << "FT4232 channel_cnt --> success" <<"FT4232 chn_cnt="<<channel_cnt;

     ftStatus=SPI_GetChannelInfo(1,&listinfo);
        if(FT_OK!=ftStatus)
              qDebug() << "listing FT4232 info failed";
         else
             qDebug() << "listing FT4232 info success";
qDebug() <<"Device=" <<listinfo.Description;
     ftStatus=SPI_OpenChannel(1,&ft4232_handle);
            if(FT_OK!=ftStatus)
                qDebug() << "opening FT4232 failed";
            else
                qDebug() << "opening FT4232 success";

          ChannelConfig ft4232_ch_cnfg;
          ft4232_ch_cnfg.ClockRate=20000000;
          ft4232_ch_cnfg.configOptions= SPI_CONFIG_OPTION_MODE0 | SPI_CONFIG_OPTION_CS_DBUS3 | SPI_CONFIG_OPTION_CS_ACTIVELOW;
          ft4232_ch_cnfg.LatencyTimer=75;
            ft4232_ch_cnfg.Pin = 0x00000000;
      ftStatus=SPI_InitChannel(ft4232_handle,&ft4232_ch_cnfg);
          if(FT_OK!=ftStatus)
              qDebug() << "Initialize FT4232 failed";
          else
              qDebug() << "Initialize FT4232 success";
        ftStatus=write_byte(0x0000,0x90);
        Sleeper::sleep(5);

        ftStatus=write_byte(0x0000,0x10);
        Sleeper::sleep(5);

        unsigned char rx;
       ftStatus=read_byte(0x800C,&rx);
        qDebug() << "value read="<<rx;


     ftStatus=SPI_CloseChannel(ft4232_handle);
     if(FT_OK!=ftStatus)
         qDebug() << "Closing FT4232 failed";
     else
         qDebug() << "Closing FT4232 success";

    Cleanup_libMPSSE();
}
Statement:
2nd channel of FT4232H is connected to 2 SPI Slave. In the above code,I was trying to interface FT4232H with 1 SPI SLave with the help of libmpsse spi library, but I was not able to perform Read/Write Operation whereas API's return value are SUCCESS,. SPI Slave device accepts 24bits(16 bit address+8 bit data) from SPI Master which is done in write_byte function in above code, then for receiving data from SPI Slave in which 16bits address is first written into slave & reading 8bits from slave, which is done in read_byte function of above code. Kindly help me resolve my problem & let me also know whether coding is correct

Pages: [1]