FT232 CBUS Bit Bang Mode

CBUS bit bang mode of FT232 using D2XX library

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.

Source Code and Library

link to xanthium enterprises repo containing D2XX programming code on github

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.

Hardware Required

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.

Buy USB to RS485 converter online from here   Buy USB to RS485 converter online from here (made in India )

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.

FT232RL CBUS bit bang configuration

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

cbus pin configuration in usb 2 serial board

Using FT_Prog 

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".

ftdi 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. 

configuring FTDI CBUS settings in eeprom

On the right hand side pane use the dropdown box corresponding to C0,C1,C2,C3 (CBUS0-CBUS3) and select the IO mode .

io mode settings for cbus pins

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.

programming 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. 

eeprom programming using ft_prog


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.

FT232 usb to serial converter board highlighting CBUS pins

Functions needed

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 .

FT_HANDLE FT_handle;


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.

CBUS bit bang mode data and direction settings

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_Directionand 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".

#include <stdio.h>
#include <windows.h> // for windows specific keywords in ftd2xx.h
#include "ftd2xx.h"  // Header file for ftd2xx.lib 
int main(void)
    FT_HANDLE FT_handle; // handle to FT 232 chip
    FT_STATUS FT_status; // status of the FT 232 chip

    UCHAR Mask;     // for selecting which pins are input/output
    UCHAR Mode;     // Selects the mode of operation for the chip
    UCHAR UpperNibble_Direction//whether port is input/output
    UCHAR LowerNibble_Data;      // 4 bit data to be sent

    UpperNibble_Direction0xF0// setting the direction nibble
    LowerNibble_Data      = 0x0F// setting the data 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
    FT_status = FT_SetBitMode(FT_handle,Mask,Mode);  // Opening  Bit Bang Mode

    getchar(); // Press any Key to Continue
    Mode = 0x00; // Reset the chip
    Mask = 0x00;  
    FT_status = FT_SetBitMode(FT_handle,Mask,Mode); // Bring back the chip to default mode 

    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.

compiling the code to enable CBUS bit bang mode on FT232 chip using D2XX library from FTDI

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.

CBUS bit bang mode of FT232 using D2XX library


Previous Tutorial                                      Main Page                                         Next Tutorial






Is there a way to user the serial port and CBUS bits? When I tried using the CBUS Bitbang mode, the serial port stopped working.

I am using an FT231X, but the app notes say its the same as the FT232R chips.

Any help would be greatly appreciated.


Yes it is Possible to use both CBUS bit bang mode and Serial Port Mode. 

In the Tutorial RS485 Communication using D2XX library and USB2SERIAL, We are using both CBUS mode and Serial port mode of D2XX library together for controlling MAX485 chip.

Here we first put the FT232 chip in CBUS bit bang mode ,so that we an Control the MAX485 chip using  CBUS1 and CBUS2 pins.

Mode = 0x20;    // Select Chip mode as CBUS Bit Bang

ft_status = FT_SetBitMode(ft_handle,Mask,Mode);

After which we write data into the FT232 Chip using  FT_Write() function,The data is then send serially fom FT232 to MAX485 and is then transmitted outside.

For more details regarding code you can check the above link.  The code is available on Github under FT232-D2XX-Library-Programming/Comm_RS485 Folder.