I feel a little silly for asking this question. I'm still finding the differences between the Arduino and the Maple; I need to use the SPI library to communicate with an ADC. I looked at the HardwareSPI reference, but I don't so much need help with the software as with the hardware (although i'm not sure exactly what I'm missing).
On the Arduino, I had set up one chip select pin, and there were preset pins listed in the reference for clock and data in and data out. Looking at the HardwareSPI reference I'm a little confused because I don't know which pins to use for chip select, clock, MOSI and MISO... is there more reference material I missed somewhere? Also, when I start the program with HardwareSPI spi(1), port one is then the chip select, the clock, or a data pin? Sorry if i'm missing something obvious...
SPI pins and setup?
(3 posts) (2 voices)-
Posted 2 years ago #
-
Oops sorry, i just found the pin map for the Maple. D11 for MOSI, D12 for MISO, and D13 for clock.
NSS is negative chip select... but Im now guessing i can choose whatever pin i want for chip select with HardwareSPI spi(#)?Posted 2 years ago # -
The number you pass the constructor for HardwareSPI related to the SPI port you are using since the Maple has 2. You have to set up a chip select pin by yourself, there is one for each SPI port, but it is not driven automatically. Here's a bit of example code:
HardwareSPI spi(1);
void setup() {
spi.begin(SPI_1_125MHZ, MSBFIRST, 0);
pinMode(10, OUTPUT);
}void loop(){
digitalWrite(10, LOW);
spi.transfer(0x00);
digitalWrite(10, HIGH);
delay(500);
}This code sets up the SPI port on port 1, setting it to 1.125MHz (see HardwareSPI documentation for other speeds), Most Significant bit first, and mode 0 (which defines when to take samples and the clock polarity).
It also sets the CS pin as an output in this case D10. The loop set the CS line low (which usually selects the SPI device you wish to communicate with) and then transmits a single byte before setting the CS line to high and waiting 500ms before delaying again.Hope that helps!
Posted 2 years ago #
Reply
You must log in to post.