Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

FTDI 2232 H Mini Module SPI to USB converter Clock Problem

Status
Not open for further replies.

adip

Newbie level 3
Joined
Jul 17, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Los Angeles
Activity points
1,368
Hi

So I am trying to send data from SPI bus (from PIC MCU) to USB. I was using the MPSSE protocol and was able to do it .

The problem i am facing is that to run the program successfully , we have to restart the PIC MCU. The reason behind this is as soon as the program gets executed , the CLK goes to high, where as in the operation it starts from low. So everytime the program starts the MCU which is monitoring continuously misreads the intialisation.

Also i cant find the command to make it operate from high instead of going to low in the beginning.

I am using MPSSE . ftd2xx.h , lib to operate on the ftdi.

Thanks in advance.
 

Re: FTDI 2232 H Mini Module SPI to USB converter Clock Probl

HI

Look at the PIC mcu DS for the SPI set up registers it should have a clock or data reversal bit


All the best

Bobi

The microcontroller specialist
 

Re: FTDI 2232 H Mini Module SPI to USB converter Clock Probl

Hi

But the problem is with the ftdi chip and its clock mode. I cant seem to make it start from high in the operation too.. that way it wont go to low and MCU will misread it.

Sorry, I dont understand how the bit reversal register is going to help.

Thanks
 

I have to say that it is (near?) impossible to understand what you are saying.

I would suggest that you put your code up, tell us what you expect to say and what you say.

help us so we can help you.
 

Re: FTDI 2232 H Mini Module SPI to USB converter Clock Probl

i apologize if i am not able to make myself clear.

The problem is the free or ideal state of the clock is high (b/w ftdi and MCU).But as soon as i intialise my program the clock immediatly goes to low and then starts the clock cycle.Here is the code for ftdi 2232h chip. I am trying to intialise MPSSE and recieve 6 bytes (its similar to there application note AN_135 ) .

All I want is to not stop MCU all the time , if i stop the ftdi chip.

/*
To build you must include ftd2xx.dll, ftd2xx.lib, ftd2xx.h in your source directory.
*/

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

FT_STATUS init_usb(FT_HANDLE ftHandle);
FT_STATUS init_mpsse(FT_HANDLE ftHandle);

FT_STATUS write_start(FT_HANDLE ftHandle, int len);
FT_STATUS write_data(FT_HANDLE ftHandle, unsigned char *buff, DWORD len, DWORD *wLen);
FT_STATUS write_stop(FT_HANDLE ftHandle);

FT_STATUS read_data(FT_HANDLE ftHandle, unsigned char *buff, DWORD len, DWORD *wLen);

int main(int argc, char *argv[])
{
FT_STATUS ftStatus;
FT_HANDLE ftHandle;
DWORD len;
DWORD wLen;
unsigned char buff[20 + 2];

int i;

ftStatus = FT_Open(0, &ftHandle);
if (ftStatus != FT_OK)
printf("FT_Open Port A failed\n");

printf("Init USB and MPSSE\n");
ftStatus = init_usb(ftHandle);


#if 1
ftStatus = init_mpsse(ftHandle);

strcpy((char *)&buff[0], "Hello World!"); // String to output on SDO
printf("Write Data\n");
len = strlen("Hello World");

ftStatus = write_start(ftHandle, len);
for (i = 0; i < 2; i++)
{
ftStatus = write_data(ftHandle, buff, len, &wLen);
//sleep(1);
}
ftStatus = write_stop(ftHandle);

// sleep(2);
#endif

#if 1
printf("Init MPSSE\n");
ftStatus = init_mpsse(ftHandle);
printf("Read\n");
len = 5;
ftStatus = read_data(ftHandle, buff, len, &wLen);
printf("No bytes read %d\n", (int)wLen);

for (i = 0; i < wLen; i++)
printf("0x%x ", buff);
printf("\n");
#endif

ftStatus = FT_SetBitMode(ftHandle, 0x00, 0x00);
ftStatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX);
ftStatus = FT_ResetDevice(ftHandle);

FT_Close(ftHandle);

return 0;
}



FT_STATUS init_usb(FT_HANDLE ftHandle)
{
FT_STATUS ftStatus;
PFT_EVENT_HANDLER eh;
DWORD InOutTransferSize = 64 * 1024;
unsigned char event_error = 0x00;

/* Reset Device and Purge USB Buffers */
ftStatus = FT_ResetDevice(ftHandle);

/* Set USB Buffer to 64K */
ftStatus = FT_SetUSBParameters(ftHandle, InOutTransferSize, InOutTransferSize);
if (ftStatus != FT_OK)
printf("USB Setup Failed\n");

ftStatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX);

ftStatus = FT_SetEventNotification(ftHandle, 0, (PVOID) &eh );
if (ftStatus != FT_OK)
printf("Set Event Notification Failed\n");

ftStatus = FT_SetChars(ftHandle, event_error, 0, event_error, 0);
if (ftStatus != FT_OK)
printf("Set Chars Failed\n");

/* Set Timeouts */
ftStatus = FT_SetTimeouts(ftHandle, 0, 5000);
if (ftStatus != FT_OK)
printf("Set Timeout Failed\n");

ftStatus = FT_SetLatencyTimer(ftHandle, 16);
if (ftStatus != FT_OK)
printf("Set Latency Timeout Failed\n");

ftStatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX);
if (ftStatus != FT_OK)
printf("Purge Buffers Failed\n");

// usleep(100000);

return(ftStatus);
}


FT_STATUS init_mpsse(FT_HANDLE ftHandle)
{
FT_STATUS ftStatus;
DWORD wBytes;
DWORD nBytes;
unsigned char mpsee_cmd[16];

/* Reset MPSEE Mode */
ftStatus = FT_SetBitMode(ftHandle, 0x00, 0x00);

/* Set MPSEE Mode */
ftStatus = FT_SetBitMode(ftHandle, 0x00, 0x02);
if (ftStatus != FT_OK) {
printf("Failed to set MPSEE mode\n");
}

/* Set 8 Low Pins Directions and Output */
mpsee_cmd[0] = 0x80;
mpsee_cmd[1] = 0x00; //default is 0x00
mpsee_cmd[2] = 0xEB;
nBytes = 3;
ftStatus = FT_Write(ftHandle, mpsee_cmd, nBytes, &wBytes);
if(ftStatus != FT_OK)
printf("Set Low Pins Failed\n");

/* Set 4 High Pins Directions and Output */
mpsee_cmd[0] = 0x82;
mpsee_cmd[1] = 0x00;
mpsee_cmd[2] = 0x0F;
nBytes = 3;
ftStatus = FT_Write(ftHandle, mpsee_cmd, nBytes, &wBytes);
if(ftStatus != FT_OK)
printf("Set High Pins Failed\n");

/* Set Clock to 1.5 Mhz */
mpsee_cmd[0] = 0x86;
mpsee_cmd[1] = 0x03; // default is 0x03
mpsee_cmd[2] = 0x02;
nBytes = 3;
ftStatus = FT_Write(ftHandle, mpsee_cmd, nBytes, &wBytes);
if(ftStatus != FT_OK)
printf("Set Clock Failed\n");

/* Disconnnect Loopback */
mpsee_cmd[0] = 0x85;
nBytes = 1;
ftStatus = FT_Write(ftHandle, mpsee_cmd, nBytes, &wBytes);
if(ftStatus != FT_OK)
printf("Set Loopback Failed\n");
//usleep(100000);

return(ftStatus);
}


FT_STATUS write_start(FT_HANDLE ftHandle, int len)
{
FT_STATUS ftStatus;
DWORD wBytes;
unsigned char mpsee_cmd[8];

/* Set 8 Low Pins Directions and Output */
mpsee_cmd[0] = 0x80; // Set Data Bits Low Byte; default is 0x80
mpsee_cmd[1] = 0x00; // Initial value assigned to pins; default is 0x00
mpsee_cmd[2] = 0xFB; // Determines which pins are input or output.
// 0xFB maps to 1111 1011 (AD7-AD0)

mpsee_cmd[3] = 0x11; // 0x11 clocks bytes on falling (-ve) edge (default)
mpsee_cmd[4] = (unsigned char)(((len - 1) & 0xff00) >> 8);
mpsee_cmd[5] = (unsigned char)((len - 1) & 0x00ff);

ftStatus = FT_Write(ftHandle, mpsee_cmd, 6, &wBytes);

return(ftStatus);
}

FT_STATUS write_stop(FT_HANDLE ftHandle)
{
FT_STATUS ftStatus;
DWORD wBytes;
unsigned char mpsee_cmd[8];

/* Set 8 Low Pins Directions and Output */
mpsee_cmd[0] = 0x80;
mpsee_cmd[1] = 0xFF; // default is 0xFF
mpsee_cmd[2] = 0xFB;

ftStatus = FT_Write(ftHandle, mpsee_cmd, 3, &wBytes);

return(ftStatus);
}

FT_STATUS write_data(FT_HANDLE ftHandle, unsigned char *buff, DWORD len, DWORD *wLen)
{
FT_STATUS ftStatus;

ftStatus = FT_Write(ftHandle, buff, len, wLen);

return(ftStatus);
}


FT_STATUS read_data(FT_HANDLE ftHandle, unsigned char *buff, DWORD len, DWORD *wLen)
{
FT_STATUS ftStatus;
unsigned char mpsee_cmd[16];
DWORD wBytes;
int i;

/* Set 8 Low Pins Directions and Output */
mpsee_cmd[0] = 0x80;
mpsee_cmd[1] = 0x00; // default is 0x00
mpsee_cmd[2] = 0xFB;

ftStatus = FT_Write(ftHandle, mpsee_cmd, 3, &wBytes);
if(ftStatus != FT_OK)
printf("Set Low Pins Failed\n");

*wLen = 0;

#if 1
for (i = 0; i < len; i++)
{
/* Read from device without write */
mpsee_cmd[0] = 0x20;
mpsee_cmd[1] = 0;
mpsee_cmd[2] = 0;

ftStatus = FT_Write(ftHandle, mpsee_cmd, 3, &wBytes);
if(ftStatus != FT_OK)
printf("Read from Device Failed\n");

//usleep(20000);
/* Move Data to buffer */
mpsee_cmd[0] = 0x87;
ftStatus = FT_Write(ftHandle, mpsee_cmd, 1, &wBytes);
if(ftStatus != FT_OK)
printf("Data Move Failed\n");
}
#else

/* Read from device without write */
mpsee_cmd[0] = 0x20;
mpsee_cmd[1] = (unsigned char)((len - 1) & 0x00ff);
mpsee_cmd[2] = (unsigned char)(((len - 1) & 0xff00) >> 8);

ftStatus = FT_Write(ftHandle, mpsee_cmd, 3, &wBytes);
if(ftStatus != FT_OK)
printf("Read from Device Failed\n");

/* Move Data to buffer */
mpsee_cmd[0] = 0x87;
ftStatus = FT_Write(ftHandle, mpsee_cmd, 1, &wBytes);
if(ftStatus != FT_OK)
printf("Data Move Failed\n");
#endif

/* Read Data from USB Buffer */
ftStatus = FT_GetQueueStatus(ftHandle, wLen);
printf("wLen = %d\n", (int)*wLen);

if (*wLen > 0)
ftStatus = FT_Read(ftHandle, buff, *wLen, &wBytes);

if(ftStatus != FT_OK)
printf("Read Failed\n");

return(ftStatus);
}


Thanks
 

did you observe the right data going to the chip?
 

Yes, I saw the data going in from the PIC is correct (I checked it using a CRO), So data recieved by the chip is correct.

Does anybody know how to use the FT_Purge() function what is the Umask in that?

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top