Arm Mbed OS support forum

How can I use API about spi.write()

Hi
I want to ask how to use the API about spi.write() below.


Now I only can use spi.write(0xff) to controll the SPI transaction.
image
But if I want to use another spi.write()API, it would show the error below.
Can you help me with how to use this API correctly?
image
image

Hello,

that is probably because your both buffers are Int type, so check the requested data types of SPI::write(…). I see const char pointer and char pointer.

BR, Jan

Hi Jan,

Thank you for your information!
But according to my experiment, I still cannot use API spi.write() successfully after I select the requested data types.
image

Can you help me how to define the requested data successfully?
Thank you !

Best Regards,
Denny

Hello,

probably go back to your previous version and just change from int type to char type

Br, Jan

spi.write accepts pointers to char arrays. You should still declare them as char tx[2] and char rx[2], and simply invoke spi.write(tx, 2, rx, 2).

Hi Jan,

It seems to work successfully when using “char” type.
Thank you so much for your help!

Best Regards,
Denny

Hi Richard,

It helps me a lot and I work successfully by using “char” type.
Thank you so much!

Best Regards,
Denny

Adding a short explanation:

char RxBuf[2]; creates a char pointer with the name RxBuf.
Thats the reason why just usign char solved the issue.

Same reasoning for const char* TxBuf[2]