FTDI Community

General Category => Discussion - Software => Topic started by: willycat on June 16, 2021, 05:29:32 PM

Title: I2C with VinculumII
Post by: willycat on June 16, 2021, 05:29:32 PM

I would like to use an RTC chip with the VinculumII via an i2c interface.

But where is the documentation of the "i2c.a" library ? Only one function is referenced in the "i2c.h" file of the VinculumII toolchain ("i2c_device_init") but nothing else.


Title: Re: I2C with VinculumII
Post by: FTDI Community on June 18, 2021, 04:32:43 PM

Please see AN_151 Vinculum II User Guide (https://ftdichip.com/wp-content/uploads/2020/08/AN_151_Vinculum-II_User_Guide.pdf) for all available information on the APIs.

You can also check the About --> Help in the Toolchain which has the same information but allows you to search.

The i2c.a library is obsolete so that’s why there is no documentation on it.

You are also in contact with our support team via email, feel free to post any information here to help other FTDI users.

Best Regards,
FTDI Community
Title: Re: I2C with VinculumII
Post by: willycat on June 27, 2021, 10:09:41 PM

thank you for your reply. My confusion came from the "i2c.h" file which talk about pin number starting at one.

Things go better now as there is activity on clock and data signals, but it doesn't work yet. Look at this source code:

   #define VOS_DEV_I2C 5

   // Configure direction of port B
    vos_gpio_set_port_mode(GPIO_PORT_B, 0x0c);

    // i2c interface
    vos_iomux_define_output(14, IOMUX_OUT_GPIO_PORT_B_2);
    vos_iomux_define_output(15, IOMUX_OUT_GPIO_PORT_B_3);

    // Needed declarations
    i2c_ioctl_cb_t i2c_iocb;
    i2c_port_t i2c_port;
    unsigned char i2cerr;

    char i2c_Buf[8];
    uint16 i2c_Nbr;


    // Define the I2C pins
    i2c_port.clkPort = I2C_PORT_B;
    i2c_port.clkPortNo = 3; // Pin 15
    i2c_port.dataPort = I2C_PORT_B;
    i2c_port.dataPortNo = 2; // Pin 14
    i2cerr = i2c_device_init(VOS_DEV_I2C, &i2c_port);

    // Open I2C Interface
    hI2C = vos_dev_open(VOS_DEV_I2C);

    // Set RTC address
    i2c_iocb.ioctl_code = VOS_IOCTL_I2C_SET_DEVICE_ADDRESS;
    i2c_iocb.data = 0x68;
    i2cerr = vos_dev_ioctl(hI2C, &i2c_iocb);

    // Set I2C options
    i2c_iocb.ioctl_code = VOS_IOCTL_I2C_SET_OPTIONS;
    i2c_iocb.data = I2C_OPTIONS_READ_ADDRESS;
    i2cerr = vos_dev_ioctl(hI2C, &i2c_iocb);

    // Set address to read
    i2c_iocb.ioctl_code = VOS_IOCTL_I2C_SET_RDWR_ADDRESS;
    i2c_iocb.data = 0x00;
    i2cerr = vos_dev_ioctl(hI2C, &i2c_iocb);

    // Read one byte form Addess 0x00
    i2cerr = vos_dev_read(hI2C, i2c_Buf, 1, &i2c_Nbr);

First: All vos_dev_ioctl() calls return 1. From what i saw in the disassembly code window, this is normal and each call successfully did its job. But according to the manual, the vos_dev_ioctl() function should return 0 in case of success.

Second: The vos_dev_read() fail and return 2. With my scope, i know that the first byte (which contain the start condition,the chip address, the direction bit) is sent to the RTC which response with an ACK. But that is all i see and the R/W bit is set to 0 instead of 1 for a read.

I tried to find where the problem could be in the assembler code, but your debugger doesn't allow to put breakpoint in the assembler code which makes the debug process almost impossible.

Maybe, i do something wrong, but i don't know what.

In attachment, you will find the result of the vos_dev_read() function.

Can you help me again ?

Title: Re: I2C with VinculumII
Post by: willycat on June 28, 2021, 01:37:53 PM
OK, i found the mistake !

i incorrectly configure the pins for the i2c interface: they need to bi bidirectional.

// i2c interface
vos_iomux_define_bidi(14, IOMUX_IN_GPIO_PORT_B_2, IOMUX_OUT_GPIO_PORT_B_2);
vos_iomux_define_bidi(15, IOMUX_IN_GPIO_PORT_B_3, IOMUX_OUT_GPIO_PORT_B_3);

Now, it works.

It is normal for the vos_dev_read() function to begin with a write operation to update the address pointer of the i2c slave.

Title: Re: I2C with VinculumII
Post by: FTDI Community on June 28, 2021, 03:09:15 PM

Thanks for the update! I'm glad you have gotten up and running.

Yes, the slave address should be written on the I2C bus for every vos_dev_read() call issued so the data packet conforms to the I2C standard.

Best Regards,
FTDI Community