This blog has permanently moved to

Contact Form | Email Address

© 2018 All rights reserved by Boseji

Thank you for all your support.

Thursday, May 27, 2010

VI.K.A.S Updates - I

These are the Updates on the progress of my project VIKAS(VIllage Komputing Agricultural System):
  • 20-MAY-2010: 
    • Clock Out Code is now Working - Need to check for the Alternate Clock Sources and configuration
  • 06-MAY-2010:
    • Rearranged the SVN directories for better outlay
  • 02-MAY-2010:
    • Was able to split the Board 
    • Stand Alone Code Possible 
    • Added Data sheets to the SVN
  • 01-MAY-2010:
I would try to publish some pictures also for this project. Unfortunately I still did not receive my Kit and I have to share the kit from my friend.

FT232: FTDI's Bit Bang using Python (Parallel Port Replaced !!)

I tired using the FTDI's FT232R USB to Serial chip for the Bit bang type of application using the D2XX mode driver in Python.
The Bit-Bang mode of the FT232R chip is detailed in the FTDI Application note AN232R-01.
It was amazingly easy. I did it on my Windows XP laptop. This reminds me of the Parallel port days when we used to make stuff interfaced using the PC's Parallel Port. In fact due to some wrong connection I burnt the input pins of my PC's Parallel Port. But with FT232R's Bit-Bang mode I can happily say a good bye to the Parallel Port.
I would try to explain this in as lucid way as I can, so that it becomes a good document even for me to use at a later point.

[1] So the first we would being with setup needed for this Bit-Bang Experiment:
Listed below are the Pre-requisites:
  • Python V2.6 anything higher than this will also work however I don't know on the compatibility of Python V3.0 & higher ups
  • PyWin32 use the Latest version available for the Python V2.6
  • PyUSB package V1.6 for Windows I have tested this to be working, you can try for higher version if available
    UPDATE 06-NOV-2010: The PyUSB is only available till Python Version 2.6
    Still checking if we can get the newer Version available.

  • FT232R Chip of course in the form of some module or your custom PCB. I plan to make one for myself too would post once ready. There are a verity of Modules available from various vendors depending on the Flexibility and I/Os provided for use. Some of them only provide a few serial lines and the rest are hidden. I like the FTDI's conventional UM232R module for which I found an alternative at Sunrom (However now its non-stock). There are other modules too : SparkFun's BOB-00718 , Foca and Modren Devices USB - BUB.
[2] Details about the Modes available in FT232 for Bit Banging:
  • Asynchronous Bit Bang Mode: This mode helps to emulate the Parallel port kind of interface. Whatever is written to the 8bit port(D0-D7) is written out. The rate at which its written out is controlled by the Baud rate set in the chip. The CBUS pins are not accessible and also the Serial Interface Pins are now acting as the data pins(Given in the Below Section). Since this mode the write to the Bus and the Read from the bus can be without any strobe, that's why its called Asynchronous. below table shows the Pins available in this mode.
Signal Serial
Type Description
1 30 D0 TXD Input/Output Bit Bang Data Bus Bit 0
5 2 D1 RXD Input/Output Bit Bang Data Bus Bit 1
3 32 D2 RTS# Input/Output Bit Bang Data Bus Bit 2
11 8 D3 CTS# Input/Output Bit Bang Data Bus Bit 3
2 31 D4 DTR# Input/Output Bit Bang Data Bus Bit 4
9 6 D5 DSR# Input/Output Bit Bang Data Bus Bit 5
10 7 D6 DCD# Input/Output Bit Bang Data Bus Bit 6
6 3 D7 RI# Input/Output Bit Bang Data Bus Bit 7
  • Synchronous Bit Bang Mode: In this mode the communication of data is controlled by the #RD and #WR strobe signal from the CBUS port(Pre config required in the FT232 EEPROM). This mode is good to interface with microcontroller for parallel transfer of data but I would not details about this mode since its not useful in the present context.
  • CBUS Bit Bang Mode: This mode is a Handy mode for interfacing some small control logic along with a Serial Interface. In this mode the Serial Interface work as it is and the CBUS can be handled in parallel. Its an interesting mode for implementing control on the microcontroller such as an additional connection needed to reset the micro(not like Arduino since its uses the DTR pin) or put the micro in boot loader mode. Note that CBUS4 cant be used for this bit bang mode.

    FT232RL Pin Number FT232RQ Pin Number Signal Type Description
    23 22 C0 Input/Output Configurable function
    22 21 C1 Input/Output Configurable function
    13 10 C2 Input/Output Configurable function
    14 11 C3 Input/Output Configurable function
[3] Commands for Asynchronous Bit Bang Mode and CBUS Bit Bang Mode '{}' - contains the Python Command Equivalent:

  1. FT_SetBitMode {[handle].setBitMode([mask],[mode])}:
    Asynchronous Bit Bang mode is enabled using the FT_SetBitMode command.
    A value of 0x01 will enable it and a value of 0x00 will reset the device mode.
    [mode] = 0x00:Reset , 0x01:Asynchronous Bit Bang Mode , 0x20:CBUS Bit Bang Mode
    [mask] = 8bit Mask for configuring the I/O pins

    • Asynchronous Bit Bang Mode:[mode]=0x01
      This configures the direction 8 pins of the Bus(D0-D7)
      Bit = 0:Input , 1:Output
      Eg. For setting D0=Input and All the Other pins as Output  this Value would be 0xFE (0b11111110)
    • CBUS Bit Bang Mode: [mode]=0x20
      The first 4bits is the Mask for C0-C3 and the Lower bits are used to Set the Data to the Pins.
      Eg1. Set all pins to output with bit 0 high: 0xF1(0b1111[mask] 0001[data])
      Eg2. Set bits 0 and 1 to input, bits 2 and 3 to output and make bits 2 and 3 high: 0xCC(0b1100[mask] 1100[data])

  2. FT_GetBitMode {[handle].getBitMode()}:
    This reads the current Bus(D0-D7) data in Asynchronous mode & CBUS BitBang Setup of the FT232 chip. It has the same bit pattern as that of current mode.

    • Asynchronous Bit Bang Mode
      This gives the status at the Pins on the Bus(D0-D7). Even if its configured as output the current status would be reported back.
    • CBUS Bit Bang Mode
      In this mode it would give the status of the C0-C3 pins with first 4bits are the Mask for C0-C3 and the Lower bits are the Data available. This last nibble would show up complete nibble even if the pin is configured as an output.

  3. FT_SetBaudRate {[handle].setBaudRate([baud])}: (only for the Asynchronous Bit Bang mode)
    The rate of data transfer can be controlled by using the FT_SetBaudRate command. The maximum Baud rate is 3MBaud.The clock for the Asynchronous Bit Bang mode is actually 16 times the Baud rate. A value of 9600 Baud would transfer the data at (9600x16) = 153600 bytes per second, or 1 every 6.5 mS.

  4. FT_Write {[handle].write([string])}: (only for the Asynchronous Bit Bang mode)
    Data can be written to the device in Asynchronous Bit Bang mode using the FT_Write command. If multiple bytes are written to the device the values on the pins will change at the rate set by FT_SetBaudRate. The string would be standard "" as for Python with escape sequences to send bytes.
    Eg1: Wrting a full data pattern to the port [handle].write("Hello world!\r\n")
    Eg2: Wrting a byte of data to the port [handle].write("\x01")
  5. FT_ListDevices {[handle].listDevices([string])}:
    This is used to check the number of devices(FT232's) connected to the PC. Depending on that the required device can be opened for communication. There are three different ways in which the devices connected can be listed.

[4] Example:
Listed below is an example that was executed in the Python Window:

Step 1: Include the Driver from the installed Location
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> import d2xx

Step2: Find if there are any devices

Type (I): Check by Name:
>>> d = d2xx.listDevices(d2xx.OPEN_BY_DESCRIPTION)
>>> print d
('FT232R USB UART',)

Type (II): Check by Serial Number
>>> print d2xx.listDevices()

Step3: Open the Device. Since we can see that only one device is available, we can directly open using the Zero location. As the FT232 devices are enumerated starting from Zero.
>>> h = d2xx.open(0)
>>> print h


(Here 'h' is the handle to the device no created)

Step4: Configure the Parallel Port Asynchronous Bit Bang Mode for I/O
>>> h.setBitMode(0xF0,1)

The device is configured for Asynchronous Bit Bang Mode  and D0-D3 are 4bit Input port & D4-D7 are 4bit Output Port.

Step 5: Set the outputs to some value
>>> print h.write("\x80")

The "1" printed indicates that the byte was written. At this point the D7=1 and D6-D4 are all 0.

Step 6: Read the Pins
>>> print "0x%X" % h.getBitMode()
This shows that D0 is pulled to High and D1-D3 are Zero.

Step7: Close the Port. This is important if you wish to keep accessing the device on the same computer. Else you might need to reconnect the device to make it work again after you have opened an handle to the device.
>>> h.close()

This is a basic operations example. Need to detail it further to include the Serial Mode bit banging and the CBUS mode also. Let us know your suggestions.

UPDATE 09-JAN-2011: New driver for Python 2.7.1 has been compiled successfully. Need to tweak the DLL interface so waiting till the PyUSB creator comes back. Would be adding a full blown tutorial for this soon with the update for the pyUSB driver.

VLSI Layout Tools

I was recently searching for some open tools to get started with VLSI Layout design and also for simulating them with varying features. Listed below are the options that I found:

Thursday, May 6, 2010

Arduino Programming : using on board FT232

This is another innovation from Kimio Kosaka where the Arduino chip is programmed with the required bootloader using FT232 chip on-board the Arduino.

Single Chip Arduino:Crazy !!

Today I saw one of the the most Awesome projects: SingleChipArduino . I could not believe the amount of work that went in to creating this piece of Art. I congratulate Kimio Kosaka on this creative feet.