IO expander

flash parallel eeprom by i2c expander pca9698 and ft232h in VC



Schematic


Figure 1.1 ioexpander schematic

Figure 1.2 ioexpander board

注:IO0~1无拉,IO2上拉,IO3~4下拉


Resources


# Name Category Reference Description
1 PCA9698.pdf datasheet
2 AT28LV64B-20PI.pdf datasheet
3 FT232H.pdf datasheet
4 USB to I2C Example using the FT232H and FT201X devices.pdf tutorial FTDI official tutorial using ft2xx driver - AN255
5 Adafruit FT232H With SPI & I2C Devices tutorial important guidance for wiring and python
6 Bit Bang ft232h to control SPI devices tutorial c programming realization using visual studio
7 教程:在 Visual Studio 中使用 Python tutorial microsoft official tutorial
8 FTDI SPI Tutorial: LibMPSSE with Visual Studio 2015 tutorial MPSSE tutorial
9 How to get I/O to Computer Application - USB FTDI D2XX drivers tutorial FTDI D2XX tutorial
10 FT_Prog.exe application download page important FTDI utility
11 AN_255 Files.zip library download page source library header template for AN255 and FT2XX driver
12 AN_177_User_Guide_For_LibMPSSE-I2C.pdf tutorial FTDI official tutorial AN177
13 LibMPSSE-I2C_source.zip library download page LibMPSSE I2C library


Workflow


VC新建C++ windows console项目,添加依赖于Resource#13
ftd2xx.h
libMPSSE_i2c.h
WinTypes.h
libMPSSE.lib
libMPSSE.dll

TEST CODE
#include "pch.h"
#include <stdio.h>
#include <Windows.h>
#include "../libMPSSE_i2c.h"

//#include <iostream>

void print_and_quit(const char cstring[]) {
	printf("%s\n", cstring);
	getc(stdin);
	exit(1);
}

int main(int argc, char **argv)
{
	Init_libMPSSE();

	FT_STATUS status;
	FT_DEVICE_LIST_INFO_NODE channelInfo;
	FT_HANDLE handle;
	uint8 buffer[256];
	uint32 bytesTransfered;

	uint32 channelCount = 0;
	status = I2C_GetNumChannels(&channelCount);
	if (status != FT_OK)
		print_and_quit("Error while checking the number of available MPSSE channels");
	else if(channelCount<1) 
        print_and_quit("Error: no MPSSE channels are available");
    printf("There are %d channels available. \n\n", channelCount);
    for (int i=0; i < channelCount; i++) {
		status = I2C_GetChannelInfo(i, &channelInfo);
		if (status != FT_OK)
			print_and_quit("Error while getting details for an MPSSE channel.");
		printf("Channel number: %d\n", i);
		printf("Description: %s\n", channelInfo.Description);
		printf("Serial Number: %d\n", channelInfo.SerialNumber);
	}

	status = I2C_OpenChannel(0, &handle);
	if (status != FT_OK)
		print_and_quit("Error while opening the MPSSE channel.");

	ChannelConfig channelconfig;
	channelconfig.ClockRate = I2C_CLOCK_FAST_MODE;
	channelconfig.LatencyTimer = 75;
	status = I2C_InitChannel(handle, &channelconfig);
	if (status != FT_OK)
		print_and_quit("Error while initializing the MPSSE channel");

	buffer[0] = 0x1;	//IO bank 1
	bytesTransfered = 0;
	printf("result: %d\n", buffer[0]);

	status = I2C_DeviceWrite(handle, 0x20, 1, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT);

	if (status != FT_OK)
		print_and_quit("Error while writing command.");

	bytesTransfered = 0;
	status = I2C_DeviceRead(handle, 0x20, 1, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT);
	if (status != FT_OK)
		print_and_quit("Error while reading data.");

	printf("result: %d\n", buffer[0]);

	Cleanup_libMPSSE();
	return 0;
}



Troubleshoot