RP2040 SPI
#2809
Replies: 3 comments
-
We implement the regular Arduino SPI interface. The Arduino docs and forum can help you there, and the specific Pico extensions are documented in https://arduino-pico.readthedocs.io/en/latest/spi.html You can use the
|
Beta Was this translation helpful? Give feedback.
0 replies
-
html,body{background-color:#fff;color:#333;line-height:1.4;font-family:sans-serif,Arial,Verdana,Trebuchet MS;}Good morning Earle,
thank you for the quick answer.
I think I tested this approach already, but I am nit sure about it.
Unfortunately I will not be able to review it until tomorrow afternoon CET.
Just a suggestion: it is quite tedious to jump between different documentations.
Your documentation about the RP2040 differences maybe improved by adding the redundant information aboutSPI.transfer() and SPI1.transfer(), escpecially the overloading versions. ;-))
Anyhow, please be patient. I will notify you about my observation.
Kind regards
Klaus P. StockStock & PartnerAdvanced Education GmbH-----------------------
Earle F. Philhower, III schrieb am 18.02.2025 18:22 (GMT +01:00):
We implement the regular Arduino SPI interface. The Arduino docs and forum can help you there, and the specific Pico extensions are documented in https://arduino-pico.readthedocs.io/en/latest/spi.html
You can use the SPI.transferbuffer, count) to do what you want using HW chip select. Something like
...
uint8_t pkt[3] = { ADDRCMD, REGADDR, DATA};
SPI.beginTransaction(spisettings);
SPI,transfer(pkt, 3);
SPI.endTransaction();
...
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
html,body{background-color:#fff;color:#333;line-height:1.4;font-family:sans-serif,Arial,Verdana,Trebuchet MS;}Hello Earle,
sorry to answer late, but I was quite busy.
The first picture shows what happens when using the following:
#define MCP_SPEED 10000000
#define MCP_DATA_ORDER MSBFIRST
#define MCP_SPI_MODE SPI_MODE0
SPISettings MCP_setting( MCP_SPEED
,MCP_DATA_ORDER
,MCP_SPI_MODE
);
setup:
SPI1.setCS(MCP_CS_PIN);
SPI1.setSCK(MCP_SCK_PIN);
SPI1.setTX(MCP_TX_PIN);
SPI1.setRX(MCP_RX_PIN);
SPI1.begin(true);
the read:
buttonState = MCP_read(GPIOB);
the function:
uint8_t MCP_read(const uint8_t register_addr)
{
uint8_t data;
uint8_t pkt[3] = {
MCP_READ_CMD
,register_addr
,DUMMY_BYTE
};
SPI1.beginTransaction(MCP_setting);
SPI1.transfer(pkt, 3);
SPI1.endTransaction();
return pkt[2];
}
Channel 1: a trigger pulse for the scope
Channel 2: CSn
Channel 3: COPI
Channel 4; CIPO
As you can see each byte transfered has an individual CSn and nothing will be returned on CIPO.
The second picture shows what the MCP23S17 requires:
One CSn for all three bytes.
I had to do it by specifying
SPI1.begin();
and in the function using a manually set LOW and HIGH for the CSn pin.
digitalWrite(MCP_CS_PIN, LOW); //enable chip select manually
SPI1.beginTransaction(MCP_setting);
SPI1.transfer(pkt, 3);
SPI1.endTransaction();
digitalWrite(MCP_CS_PIN, HIGH); //disable chip select manually
I don't know if there is any elegant solution and yes, I can live with the manual solution.
Thank you for your help.
Kind regards
Klaus P. StockStock & PartnerAdvanced Education GmbH-----------------------
Earle F. Philhower, III schrieb am 18.02.2025 18:22 (GMT +01:00):
We implement the regular Arduino SPI interface. The Arduino docs and forum can help you there, and the specific Pico extensions are documented in https://arduino-pico.readthedocs.io/en/latest/spi.html
You can use the SPI.transferbuffer, count) to do what you want using HW chip select. Something like
...
uint8_t pkt[3] = { ADDRCMD, REGADDR, DATA};
SPI.beginTransaction(spisettings);
SPI,transfer(pkt, 3);
SPI.endTransaction();
...
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Good morning.
I am able to use both SPI channels on the RP2040 with success.
When using "SPI.begin(true)" each transmission is pulling down CSn for every byte.
What I havn't found, lacking documentation, is a way to send to send three or more bytes within a common CSn.
My solution is to use "SPI.begin()" and "digitalWrite(CSn, LOW/HIGH)" controlling a MCP23S17 device.
This device needs at least three bytes, ADDRCMD - REGADDR - DATA, within one CSn.
My motivation is to gain control over the registers byte wise.
Did I miss something?
Kind regards
Klaus P. Stock
Beta Was this translation helpful? Give feedback.
All reactions