6 years, 6 months ago.

I2C.Transfer Function

Hello mbed community and ST team,

I'm using some Platforms to communicate with a digital temperature sensor, with I2C interface. I started test my "hello world" program with I2C standard lib of mbed, but I get an error that I couldn't understand yet.

I'm using the I2C.transfer function. The error is: Error: Class "mbed::I2C" has no member "transfer" in "main.cpp"

The line that I get the error is:

if(sensorI2C.transfer(_address, (char*)_tx_buf, 2, (char*)_rx_buf, 8, NULL, I2C_EVENT_ALL) != 0) { serial.printf("\r\nError: IC2"); }

Why I'm not able to use the transfer function? ST Platforms does not support this function yet?

Thank you very much!

Question relating to:

ST
A world leader in providing the semiconductor solutions that make a positive contribution to people’s lives, both today and in the future.

Another thing that I note is the I2C class is not so portable for other platforms. For example, using the simple READ and WRITE function in Silicon Labs Boards works well, but when I use the same application in ST or NXP board it doesn't work. (I just edit pin configs)

Do you know why this happen? Could be clock configurations of MCU?

posted by Uilter Witte 28 Jan 2016

Hello, you have an example using i2c with an STM board here : https://developer.mbed.org/teams/ST/code/Nucleo32_gravitech_7seg/

posted by Armelle DubocST 01 Feb 2016

1 Answer

6 years, 6 months ago.

transfer is part of the async API and is only supported on silicon labs parts.

The mbed organisation seem to like confusing beginners including functions in the documentation that only a few boards support and then not clearly indicating this.

Accepted Answer

Thank you Andy A, very helpfull.

posted by Uilter Witte 28 Jan 2016

@AndyA Which docs are you referring to? If doxygen, there should be note that it's only if device supports async HAL functions (implements them). If this one is not there, we should fix it!

posted by Martin Kojtal 28 Jan 2016

In the documention for the mbed library in the online compiler it states

int transfer (int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false)

  Start non-blocking I2C transfer.

No mention of async HAL or limited support that I can see.

Similarly the Serial.read command does state that it starts an asynchronous read but doesn't make it clear that support for that is very limited. If you don't already know that there is an async HAL with limited support there is nothing to indicate that it may not work on your board. Sure if you know what's going on or look at the source then it's all fairly obvious but the current situation is hardly the most user friendly for beginners.

posted by Andy A 28 Jan 2016

I'll create github issue for this, and should fix this for the next release. Thanks for the write up.

done - https://github.com/mbedmicro/mbed/issues/1518 , I'll have a look

posted by Martin Kojtal 28 Jan 2016