I2C bus speed in FtRoboPy

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
vleeuwen
Beiträge: 1209
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)

I2C bus speed in FtRoboPy

Beitrag von vleeuwen » 21 Jun 2020, 08:10

How and where in FtRoboPy can the I2C bus speed be set to 100kHz or 400 kHz?
100kHz (standard mode) and 400kHz (fast mode) bus speed is a basic for I2C, see the NXP I2C-bus specification and user manual, UM10204, chapter 5.
The original fischertechnik firmware I2C function KeLibI2cTransfer suggest that this would be possible:

Code: Alles auswählen

 /*!
    * @brief TXT I2C combined read/write function 
     * @param u8DevAddr         I2C device address
    * @param u16NumWrite       number of bytes to write
    * @param pWriteData        pointer to write data (byte array)
    * @param u16NumRead        number of bytes to read
    * @param pReadData         pointer to read data (byte array)
    * @param u16Clock400kHz     I2C_SPEED_100_KHZ or I2C_SPEED_400_KHZ    
    * @return 0 for Success, non-zero for failure (ft-error code)
   */
 UINT32 KeLibI2cTransfer(UCHAR8 u8DevAddr, UINT16 u16NumWrite, UCHAR8 * pWriteData, UINT16 u16NumRead, UCHAR8 * pReadData, UINT16 u16Clock400kHz);
/*!
 * @brief I2C bus speed definitions
 * 
 */
#define I2C_SPEED_100_KHZ       0  /*!< I2C bus clock speed */
#define I2C_SPEED_400_KHZ       1  /*!< I2C bus clock speed */
How to use 10 bits addresses?

Torsten
Beiträge: 190
Registriert: 29 Jun 2015, 23:08
Wohnort: Gernsheim (Rhein-Main-Region)

Re: I2C bus speed in FtRoboPy

Beitrag von Torsten » 22 Jun 2020, 19:30

Hi Carel,
vleeuwen hat geschrieben:
21 Jun 2020, 08:10
How and where in FtRoboPy can the I2C bus speed be set to 100kHz or 400 kHz?
i2c support in ftrobopy is currently implemented via the ROBOPro posix-socket protocol only and thus supports online- as well as offline-mode.

Since I'm no i2c-expert and had no documentation of the ROBOPro i2c-socket communication I had to reverse engineer the protocol. I have not detected a command to change the bus speed (I didn't explicitly look for such a command) and currently I cannot invest time into more extensive reverse engineering of the socket-protocol. If you happen to have a complete description of the protocol and would like to share it I would be happy to implement this functionality into ftrobopy.

The next ftroboby-version (>1.94) most likely will support i2c bus speed setting via the KeLib. However this will then only work in offline-mode.

Best wishes,
Torsten

vleeuwen
Beiträge: 1209
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)

Re: I2C bus speed in FtRoboPy

Beitrag von vleeuwen » 22 Jun 2020, 20:01

Hi Torsten,
Thanks for your reaction.

I have just ask fischertechnik if they could publish the underlaying protocol.
I an trying to extend the ftIF2013TransferAreaComHandler class but the result is not generic enough. I ran into the same limitation as you.

RoboPro is using it too. But the implementation is weak. It also, like the SLI, suffering also under the "5sec bug" in the remote mode.
By the way, the TXT firmware has also a bug concerning the I2C bus speed. It false always back to 400kHz.
Microcip has in their protocol tester "Pickit Serial analyzer" a very nice set of basic I2C read/write operations and functions define, see their user's guide. It is an old manual but I2C has not been changed since.

I saw already your first attempt for the bridge between Python and KeLib. This can be interesting in combination with the (embedded) Civetweb server too. This server support CGI and works beside C/C++ also with Python. I tested this already.

The next small changes will make the compressed transfer a little bit faster.
(The TXT can only work with 1 slave.)

Code: Alles auswählen

//FtShmemTxt.h
enum ShmIfId_TXT
{
    LOCAL_IO = 0,           // Local I/O
    REMOTE_IO_1,            // Remote I/O Slave #1/TXT can have only 1 slave
    SHM_IF_CNT
};
// member of IF slaves
#define SLAVE_CNT_MAX       (SHM_IF_CNT-1)  // only Slaves = 1
#define IF_TXT_MAX              SHM_IF_CNT      // Master + Slaves = 2
Kind regards,
Carel

Antworten