Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 9 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:
1 Answer
8 years, 9 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.
@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 28 Jan 2016In 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 28 Jan 2016I'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 28 Jan 2016
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