Skip to content

SPI mode and bit order not set correctly #12

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

Closed
trevor-makes opened this issue Jun 28, 2023 · 3 comments
Closed

SPI mode and bit order not set correctly #12

trevor-makes opened this issue Jun 28, 2023 · 3 comments
Assignees

Comments

@trevor-makes
Copy link
Contributor

See this line in SPI.cpp

spcmd0 &= !(((uint32_t)0xFF) << 2); should be spcmd0 &= ~(((uint32_t)0xFF) << 2);

The logical not makes the mask 0 and wipes out the earlier settings. Should be a bitwise not to make the mask FFFFFC03.

@trevor-makes
Copy link
Contributor Author

Looking into this a bit further, I'm not sure why this would be the mask setting. BRDV is only two bits (b3, b2), so I think the mask should actually be ~(((uint32_t)0x03) << 2).

I'm experimenting with setting the registers directly, but haven't had any luck thus far.

@trevor-makes
Copy link
Contributor Author

Aha, got it working... I was using the SPI0 registers, but should have been using SPI1. Adding the following after calling beginTransaction set the expected LSB and MODE3 behavior, so fixing the mask as above should resolve the issue.

  R_SPI1->SPCMD_b[0].CPHA = 1;
  R_SPI1->SPCMD_b[0].CPOL = 1;
  R_SPI1->SPCMD_b[0].LSBF = 1;

maidnl pushed a commit that referenced this issue Jul 4, 2023
Ensure that sensible SPI settings are configured after `SPI.begin()`
maidnl added a commit that referenced this issue Jul 4, 2023
@aentinger
Copy link
Contributor

Closing this issue since it is heavily outdated, see #45 .

cristidragomir97 pushed a commit to cristidragomir97/ArduinoCore-renesas that referenced this issue May 20, 2024
Ensure that sensible SPI settings are configured after `SPI.begin()`

Former-commit-id: fe8b469
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants