XMOS pins usage

Technical discussions around xCORE processors (e.g. xcore-200 & xcore.ai).
MaximLiadov
XCore Addict
Posts: 143
Joined: Mon Apr 16, 2018 9:14 am

Post by MaximLiadov »

Disclamer. I'm not XMOS technical support. This is just my own experience. I promise to write a book "Programming XMOS" when I become a real guru. :) Until then, I would be grateful if someone could correct me or add more information to this topic.
lmariotti
Member++
Posts: 27
Joined: Mon Nov 21, 2022 5:38 pm

Post by lmariotti »

I was able to manually import the i2c library but no way to make it work as it is, even though the i2c library settings are the same as i2s library (which definetly works).
Still can't find #include <i2c.h>, I've tried to replace it with the absolute path #include "../lib_i2c/api/i2c.h replaning also in .xe library files #include "../api/i2c.h", with these adjustments the compilation complete successfully, but I don't know if it may cause some trubles somehow...
MaximLiadov
XCore Addict
Posts: 143
Joined: Mon Apr 16, 2018 9:14 am

Post by MaximLiadov »

I highly recommend that you use the standard way to add the i2c library. I just double checked and it works for me. Check your internet connection / firewall settings. Turn off your anti-virus maybe.

Second, look at your project settings and check if all i2c library paths are included to C/C++/XC tabs.
You do not have the required permissions to view the files attached to this post.
MaximLiadov
XCore Addict
Posts: 143
Joined: Mon Apr 16, 2018 9:14 am

Post by MaximLiadov »

By the way, i2c library v.5.0 has some problems with my hardware possibly because of wrong timing. So I use 4.0. Standard import is very handy tool to choose version library you need. So highly recommended.
lmariotti
Member++
Posts: 27
Joined: Mon Nov 21, 2022 5:38 pm

Post by lmariotti »

I've switched to i2c v4.0 and I'm able to compile, I've also creaded a new project from scratch (still unable to use i2c v5.0) and with the same procedure as before now the i2c.h library is linked correctly. I guess somehow something f****d-up in the previous project? Have no idea.
MaximLiadov
XCore Addict
Posts: 143
Joined: Mon Apr 16, 2018 9:14 am

Post by MaximLiadov »

It is good to hear that. If you need some custom functions for the I2C library for some non-standard hardware, it is quite easy to modify it. I added a dozen new functions without any problem.
lmariotti
Member++
Posts: 27
Joined: Mon Nov 21, 2022 5:38 pm

Post by lmariotti »

I did some tests with i2c v4.0, I wasn't unable to R/W any registers until I've checked with an oscilloscope and noticed that the address was wrong.
I was using:

Code: Select all

i2c.write_reg(0x20, 0x00, 0x0D);
But the address in SDA line was 0x40, I've changened to:

Code: Select all

i2c.write_reg(0x10, 0x00, 0x0D);
Now the address in SDA line is 0x20 and the write operation complete successfully.

The payload remained unchanged and works fine just the address was 1bit shifed (?!)

Is that a know bug from i2c v4.0 library or maybe I'm missing something? (I'm not really confident with i2c communication)
lmariotti
Member++
Posts: 27
Joined: Mon Nov 21, 2022 5:38 pm

Post by lmariotti »

I've double checked the i2c master example AN00156, in this example the i2c is used to read the acceleration from FXOS8700CQ, refering to electrical drawing that chip has SA0 & SA1 shorted to GND so the address (refering to datasheet) is 0x1E and from the example code works just fine with:

Code: Select all

#define FXOS8700CQ_I2C_ADDR 0x1E
In my application I have exactly the same situation, the base address value is 0x20 and the 2 hardware configuration pins are both shorted to GND, but somehow I've to define my address as 0x10 to make it work.
You do not have the required permissions to view the files attached to this post.
MaximLiadov
XCore Addict
Posts: 143
Joined: Mon Apr 16, 2018 9:14 am

Post by MaximLiadov »

That's Ok. The last bit in the i2c address indicates the read/write flag. So the required address would be 0x20 >>1 = 0x10. Then i2c library adds LSB automatically. You can see it in the source code.
Last edited by MaximLiadov on Mon Sep 04, 2023 10:46 pm, edited 1 time in total.
MaximLiadov
XCore Addict
Posts: 143
Joined: Mon Apr 16, 2018 9:14 am

Post by MaximLiadov »

Google says on this subject: Technically speaking the 8bit i2c address does not exist, it is always 7bit address and 1bit for setting the read/write direction and together it is one byte.