libftdi Archives

Subject: Re: How to use libftdi ftdi_set_bitmode function bitmask ?

From: Nicolas <nmassart+intra2net@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sun, 29 Mar 2009 01:57:02 +0100
Hi,

As I continued to search for an answer I finally managed to use this CBUS thing using libftdi.
The fact is that's not simple for someone who never heard about serial our USB developpement. So here is what I learned, in case of someone as newbie as me have the same problems.

The point was simply that I missunderstood "input" and "output" pin types. To set pins levels from the computer I had to use output pins. I used input ones... I know this is a basic serial thing, but serial developpement and electronics are not part of my knowledge. Here data goes from the computer to the chip, so it's an output from the computer. I viewed the thing from a chip point of view and then thaught it had to be an input on the chip. My basic serial knowledge is now fixed :)

I Also, I thaught I had to set the 3rd bit. It was the bit 3, so the 4th as it begins at bit zero (pin 12 on MM232R module which is connected to pin 11 on FT232R chip).
My bit mask undestanding was ok, but with all the missunderstanding rount it, I thaught I was wrong on masks too.
For real newbies like me, also note that bytes bit zero is the far right one...
So in this cbus setting byte, positions are as the following : 76543210
position 0 : cbus pin 0 level (0 = low, 1=high)
position 1 : cbus pin 1 level
position 2 : cbus pin 2 level
position 3 : cbus pin 3 level
position 4 : cbus pin 4 type (0 = input, 1=output)
position 5 : cbus pin 5 type
position 6 : cbus pin 6 type
position 7 : cbus pin 7 type

So to fix my exemple, here are the right bytes to light my LED on or off :

    ftdi_set_bitmode(&ftdic, 0x87, BITMODE_CBUS); // 0x87 is 10000111 byte to switch on. Cbus pin 3 is output set to low. All other pins are input and set to high.

    ftdi_set_bitmode(&ftdic, 0x8F, BITMODE_CBUS); // 0x8F is 10001111 byte to switch off. Cbus pin 3 is output set to high. All other pins are input and set to high.

Chears,
Nicolas.

Le 20.03.2009 01:06, Nicolas a écrit :
Hi,

Im really new to this sort of usb device developpement and C code (started yesterday), so my question is probably very low level. Sorry.

I built a small usb prototype based on MM232R module that lights a LED when PWREN# (12) pin goes low. It well works when the EEPROM is configured to have this pin switched on PWREN# event.

After that I configured the EEPROM to accept bitbang on this pin (the 3rd of the 4 bits capables to be used as general purpose I/O) in order to light my LED using a small C program based on libftdi.

So, I tried to use the ftdi_set_bitmode function, but I can't figure how to set the bitmask.
I would like to change level of the 3rd bit, but I'm messed up with bitmasks...
Sometimes it works, I tried all the bitmasks values from 0x00 to 0xFF and notices that some works. My LED lights sometimes.
Also I don't really know if I should use the bit as input or output.

To illustrate my problem, I can't understand why the bitmask value 0xA6 lights my LED :
    ftdi_set_bitmode(&ftdic, 0xA6, BITMODE_CBUS); // 0xA6 is 10100110 bits
and why 0x9A shut it down.
    ftdi_set_bitmode(&ftdic, 0x9A, BITMODE_CBUS); // 0x9A is 10011010 bits

What bitmasks should I use to change 3rd pin from low to high and high to low ? input or output ?

I now it's probably more a question of bitmask understanding than a libftdi problem, but any help or documentation URLs would be appreciated to understand this part and begin to learn using this library.

Thanks,
Nicolas.



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread