FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: I2C with VinculumII  (Read 399 times)

willycat

  • Newbie
  • *
  • Posts: 6
    • View Profile
I2C with VinculumII
« on: June 16, 2021, 05:29:32 PM »

Hi,

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.

Thanks,

Willy.
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 645
    • View Profile
Re: I2C with VinculumII
« Reply #1 on: June 18, 2021, 04:32:43 PM »

Hello,

Please see AN_151 Vinculum II User Guide 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
Logged

willycat

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: I2C with VinculumII
« Reply #2 on: June 27, 2021, 10:09:41 PM »

Hi,

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:


Quote
   #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;

    VOS_HANDLE hI2C;

    // 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 ?

Thanks.
« Last Edit: June 27, 2021, 10:38:24 PM by willycat »
Logged

willycat

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: I2C with VinculumII
« Reply #3 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.

Quote
// 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.

Thanks.
« Last Edit: June 28, 2021, 01:43:05 PM by willycat »
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 645
    • View Profile
Re: I2C with VinculumII
« Reply #4 on: June 28, 2021, 03:09:15 PM »

Hello,

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
Logged