Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read 16 bit data from SPI #13721

Closed
CJayakumar opened this issue Mar 26, 2020 · 7 comments
Closed

Read 16 bit data from SPI #13721

CJayakumar opened this issue Mar 26, 2020 · 7 comments
Assignees
Labels
Area: drivers Area: Device drivers State: stale State: The issue / PR has no activity for >185 days Type: question The issue poses a question regarding usage of RIOT

Comments

@CJayakumar
Copy link

Hello Team,

We could not find in riotos to connect wifi with board b-l475e-iot01a.So we are trying to write driver to connect wifi with b-l475e-iot01a, The board is using esWifi module so esp32 will not support here.
Issue is,
We can read and write 8 bit data using SPI in riotos but we could not find option to read 16 bit data.If there is way to read 16 bit data from SPI, it would helpful us to resolve the issue.

Thank you

@benpicco
Copy link
Contributor

benpicco commented Mar 26, 2020

Can you not just use spi_transfer_bytes()?

uint16_t out = 0x1234;
uint16_t in;
spi_transfer_bytes(bus, cs, true, &out, NULL, sizeof(out));
spi_transfer_bytes(bus, cs, false, NULL, &in, sizeof(in));

@CJayakumar
Copy link
Author

Hello Team,

Thanks for your update.

Yes we are using the below method for receive data,
spi_transfer_bytes(dev,SPI_CS_UNDEF, false,NULL, pData, len);
and below method for send data,
spi_transfer_bytes(dev,SPI_CS_UNDEF, false,pdata, NULL, len);

But in spi.c, we found only configuration SPI for 8-bit data. there is no option for 16 bit data.
Here attached file link for your reference and kindly check and provide your suggestion.
https://github.com/RIOT-OS/RIOT/blob/master/cpu/stm32_common/periph/spi.c

Thank you.

@benpicco
Copy link
Contributor

benpicco commented Mar 27, 2020

Ah I see - stm32 has an option to load 16 bit or two data bytes into DR in one go to improve performance.
Yes this has not been implemented yet - patches welcome 😃

From my brief skimming of the data sheet, for polling mode it might be enough to set the DFF bit as long as there is still an even number of bytes in the transfer buffer, then always read two bytes and write them to DR, if needed clear DFF for the last, odd byte.

For DMA mode you might just transfer one byte manually if the transfer buffer has an odd size and write the rest in 16-bit mode, always reading/writing two bytes at at time.

@CJayakumar
Copy link
Author

Hello Team,
Thanks for the update.
We implemented and tested code in spi.c to read and write 16bit data.
It will not affect existing functional call.
Could you please tell us the procedure to check-in code in riotos, so that somebody can use this feature.

Thank you.

@benpicco
Copy link
Contributor

If you have your RIOT fork on Github, you can click that "New pull request" button and select your source branch. You'll get a template with a description to fill out.

CONTRIBUTING.md has a more in-depth explanation.

@miri64 miri64 added Area: drivers Area: Device drivers Type: question The issue poses a question regarding usage of RIOT labels Jul 6, 2020
@miri64
Copy link
Member

miri64 commented Jul 6, 2020

@CJayakumar are your questions answered? Can this issue be closed?

@stale
Copy link

stale bot commented Jan 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Jan 9, 2021
@stale stale bot closed this as completed Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers State: stale State: The issue / PR has no activity for >185 days Type: question The issue poses a question regarding usage of RIOT
Projects
None yet
Development

No branches or pull requests

4 participants