FT232 CBUS Bit Bang Mode
FT232 supports a new type of Bit Bang mode on the CBUS pins called CBUS bit bang.In this mode the 4 CBUS pins CBUS0-CBUS3 acts as a 4 bit bidirectional dataport.To enable the CBUS mode you have to set the corresponding data bits in the eeprom.FTDI has a software called FT_Prog which can be used to program the CBUS pin settings of the FT232 chip
If you are using the USB2SERIAL converter board two of the CBUS pins are used to select between the RX and TX functions in RS485 mode.
All the C sourefiles along with D2XX library used in this tutorial can be downloaded from our GitHub Page.For this Tutorial use the "CBUS_BBM " Directory inside the code repository.
Here i am using USB2SERIAL board ,in which all the relevant pins for CBUS Bit Bang Mode are brought out to male bergs for easy access.
CBUS Bit Bang Pin Configuration
FT232RL chip have 5 CBUS pins numbered from CBUS0 - CBUS4.The Pins CBUS0 to CBUS3 can be programmed in the EEPROM to behave as a 4 bit data port while CBUS4 pin lacks the I/O capability.The CBUS pins also have alternate capabilities like bringing the system clock out or configuring the LED's to indicate TX or RX .The various functionalities can be configured using the software FT_Prog which is freely available from the FTDI website.
In the case of the USB to Serial converter only 4 CBUS pins are available outside.
The CBUS0 Pin is connected to the TX/RX LED to indicate data transmission and reception in UART mode.
CBUS1 and CBUS2 are available at CONN2 through the jumpers.The CBUS1 and CBUS2 lines are used to put the RS485 chip in transmission and reception mode.This is used to create a USB to RS485 converter.
CBUS3 and CBUS 4 are not connected to any lines and are available at the connector P1
Download FT_Prog from FTDI website and install it in your computer.Double click the icon on your desktop to launch the program.After launching the program connect your FTDI breakout board or USB2SERIAL board to the PC .Go to the "EEPROM" tab and select "Devices" → "Scan and Parse".
If the software is able to detect the FTDI chip it would display the various parameters of the chip under "Device Tree".Now under the "Device Tree",you can see "FT EEPROM" → "Hardware Specific" under which select the " IO Controls".On the Right pane you can see the 5 CBUS pins and the corresponding selected modes.
On the right hand side pane use the dropdown box corresponding to C0,C1,C2,C3 (CBUS0-CBUS3) and select the IO mode .
After making the selection for CBUS pins go to the "EEPROM" tab and select "Devices" → "Program" to program the selected settings into the FTDI EEPROM.
On Pressing "Program" another window called "Program Devices" will popup, Click on the "Program" button to program the FTDI eeprom.On the bottom left corner of this window you can see the various messages generated during programming like "Programming Device 0" ,"Finished Programming" and at last "Ready" .Close the window and your FTDI is ready to do some serious Bit banging.
Any FT232RL breakout board with access to the required pins (TXD,RXD,RTS,DTS...RI) can be used or you can use the USB2SERIAL breakout board.Connect the 4 CBUS pins (CBUS0 -CBUS3) to LED's through 1K resistors as mentioned in the previous article .Make the grounds common.If you are using the USB2SERIAL board you can take Ground from the Connector P4.
If you are using USB2SERIAL converter board only 3 CBUS terminals(CBUS1,CBUS2,CBUS3) are available as one is connected to the LED.To access the CBUS1 and CBUS2 terminals remove the jumpers on CONN2.
CBUS Bit Bang mode is simple compared to the Asynchronous Bit bang mode.The only function we require is the FT_SetBitMode() function which we have seen in the previous article.There are some small differences in the parameters of the function compared to the previous one .
Mode is used to select the required mode for the FT232 chip ,here it is CBUS Bit bang mode.
Mode = 0x20 // Selects the CBUS Bit Bang Mode
Mask is an 8 bit unsigned char used to control the direction and data sent to the CBUS port pins.
The upper nibble of the Mask is used to control the direction of the data(Direction Bits (4bits)) whether it is input or output.A '1' makes the corresponding bit output while a '0' makes the corresponding bit input.
The lower nibble of the Mask represents the 4 bit data (Data Bits (4 bits)) that is sent to the port.
|Mask = 0xF0 //CBUS port direction output,CBUS port data 0x00
Mask = 0xFF //CBUS port direction output,CBUS port data 0x0F
In the actual code that follows we have used two variables (UpperNibble_Direction and LowerNibble_Data ) to represent the data and direction and they are ORed together to create the mask.
Open up a text editor and copy the following code.Save it as "cbus_BBM.c".
UCHAR Mask; // for selecting which pins are input/output
UpperNibble_Direction = 0xF0; // setting the direction nibble
Mask = UpperNibble_Direction | LowerNibble_Data;//OR'ing
FT_status = FT_Open(0,&FT_handle); // Open a connection to FT232RL
Mode = 0x20; // Select Chip mode as CBUS Bit Bang
getchar(); // Press any Key to Continue
FT_Close(FT_handle);// Close the connection to the Chip
Compile the " cbus_BBM.c " using GCC and run the resulting executable.All the 4 CBUS pins will be high and LED's will light up.Please make sure that ftd2xx.lib , ftd2xx.h and your source file are in the same folder while compiling using GCC.
The figure below shows the compilation and running on Windows 7, A few extra lines of printf() statements are added to the code described above to make it more descriptive.You can find the code (CBUS_bbm_Verbose.c) in the zip file.
The code along with header file and D2XX library can be downloaded from here.
The below figure shows USB2SERIAL connected to 3 LED's to moniter the CBUS lines (CBUS1 - CBUS3) .Please note that CBUS0 is not available outside in USB2SERIAL board.