forked from facts-engineering/P1AM
-
Notifications
You must be signed in to change notification settings - Fork 0
How to use SPI on the P1AM
AJ but at Work edited this page Oct 6, 2023
·
1 revision
The P1AM does not communicate directly with the modules to the right, rather it talks to a mysterious black box labeled "base controller" in the schematics. If you try to connect your own device to the SPI line, you will run into problems as the P1 tries to startup. The base controller sends out various commands that will cause your SPI device to respond, and that response of course doesn't match the closed-source response that the P1 modules respond with. In order to use SPI, you need to do these very specific yet easy things.
- Connect your SPI device to P1AM as usual. On the breakout (left side, referred to as SAMD21 pins) the pin connections are as follows:
SPI [newlabel] | SAMD21 Pin |
---|---|
MISO[CIPO] | Pin 10 |
SCK | Pin 9 |
MOSI[COPI] | Pin 8 |
SS[CS] | User Def |
-
Before you call
P1.init()
, make sure you set the chip select of your device to high so it will ignore all SPI messages. - Call
P1.init()
and let the P1 sign on its modules. - After this, you are free to use SPI how you'd like. It's important to note that the P1 always begins and ends its SPI transactions, so while you are not reading from the P1's modules, the SPI line is free. You should also always begin and end your transactions as well.
- No need to include the SPI library. It's already included in
P1AM.h
. Use the following code in your loop to interface with your device:
SPI.begin();
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); // changing these settings are optional. If you comment this out, defaults will be used.
digitalWrite(cs, LOW);
// Transfer any messages you need
// SPI.transfer({your data});
digitalWrite(cs, HIGH);
SPI.endTransaction(); // if you use defaults, comment this out too
SPI.end();