Pages: [1] 2   Go Down
Author Topic: [SOLVED] Due and SPI library and SPI pins?  (Read 5835 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello fellow Due users, what a fantastic board this thing is!

The SPI docs here:
http://arduino.cc/en/Reference/SPI

say that the MOSI, MISO, and SCK pins on the Due are ICSP-4, ICSP-1, and ICSP-3 respectively.  Really?  If that's so, how do you access the actual SPI port on the Due using the SPI library.  My understanding was that it would be bad idea to use the ICSP header because it is used for the interaction between the FTDI USB/serial conversion chip and the SAM3X chip.

« Last Edit: June 06, 2013, 10:25:57 pm by exedor » Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually the SAM is not programmed through ICSP like the AVR Arduinos.  So that is the only header they designed to access those pins.  They have also provided extended SPI functions at http://arduino.cc/en/Reference/DueExtendedSPI

There is a bit more consolidated info at http://21stdigitalhome.blogspot.com/2013/02/arduino-due-hardware-spi.html

Also see this post http://forum.arduino.cc/index.php?topic=167068.0
« Last Edit: May 23, 2013, 11:36:06 am by TheKitty » Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm programming it through the "Programming" port which uses the FTDI chip on the board and very clearly has traces that are connected directly to the ICSP labeled header on the board near the FTDI chip.

Surprisingly, I have already read the 21stdigitalhome page but not the other Arduino form link posting you provided.  I'm wondering if I made my question clear because the answer I'm looking for is about resolving a conflict that I see in the documentation versus what I'm seeing on those sites.

There are TWO headers on the Due board.  One of them is located just behind the FTDI adapter chip and is labeled ICSP.  I assumed this corresponded with the pin definitions in the documentation at the link I provided as ICSP-x (see 1st post above.)  The other is located immediate adjacent to the SAM3X chip next to the infinity symbol and Arduino Due logo silk-screened onto the top side of the board.  What is not clear to me is which one of these two the SPI library actually uses.  The 21stdigitalhome link leads me to believe the latter, but the docs lead me to believe the former.  I really am just trying to use SPI is all smiley

Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm programming it through the "Programming" port which uses the FTDI chip on the board and very clearly has traces that are connected directly to the ICSP labeled header on the board near the FTDI chip.

Surprisingly, I have already read the 21stdigitalhome page but not the other Arduino form link posting you provided.  I'm wondering if I made my question clear because the answer I'm looking for is about resolving a conflict that I see in the documentation versus what I'm seeing on those sites.

There are TWO headers on the Due board.  One of them is located just behind the FTDI adapter chip and is labeled ICSP.  I assumed this corresponded with the pin definitions in the documentation at the link I provided as ICSP-x (see 1st post above.)  The other is located immediate adjacent to the SAM3X chip next to the infinity symbol and Arduino Due logo silk-screened onto the top side of the board.  What is not clear to me is which one of these two the SPI library actually uses.  The 21stdigitalhome link leads me to believe the latter, but the docs lead me to believe the former.  I really am just trying to use SPI is all smiley


I am using SPI for two Adafruit thermocouple boards, I am using SPI library with SPI header that is next to the SAM chip and labeled SPI.  I am also using PWM Pin 4 and PWM Pin 10 for chip select.  I have not had any trouble.

Also, following installation instructions, I am not using FTDI driver:
"Navigate to the folder with the Arduino IDE you downloaded and unzipped earlier. Locate and select the “Drivers” folder in the main Arduino folder (not the “FTDI USB Drivers” sub-directory). Press “OK” and “Next” to proceed."
I am not sure why you are using FTDI driver.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
One of them is located just behind the FTDI adapter chip and is labeled ICSP
The Due does not have an FTDI chip, it uses an Atmega16u2. The first header you refer to is a programming header for this Mega should you even need to reflash it.

Quote
The other is located immediate adjacent to the SAM3X chip next to the infinity symbol and Arduino Due logo silk-screened onto the top side of the board.
This is the actual SPI header and AFAIK the only access you have to the SPI port and therefore this is the header used by the SPI libraries.

______
Rob
« Last Edit: May 24, 2013, 12:26:44 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The Due does not have an FTDI chip, it uses an Atmega16u2. The first header you refer to is a programming header for this Mega should you even need to reflash it.

Thanks for the clarification...that's what I meant.  I'm not using the FTDI driver.  I'm using the correct driver.


Quote
This is the actual SPI header and AFAIK the only access you have to the SPI port and therefore this is the header used by the SPI libraries.

Thanks, that's how I actually understood it.  The docs threw me.  So the docs are in error then?  When they say ICSP-x for ISP pin assignment with ISP on the Due it really means ISP-x.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So the docs are in error then?
I would say so, probably a cut-n-paste from the Mega or something where that header was ICSP as well as SPI.

I gather you are referring to the small graphic that shows the pinout of the header, the fact that the "ICSP" label almost matches the location on the board (relative to the header, EI below whereas the SPI label is above) makes it really seem to refer to the 16U programming port and not the SPI header.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you got it.  There are two clues.  The fact that the pin-out diagram of the header on the doc page does say ICSP along with the table above labeling the actual pins as ICSP as well.  The actual SPI header is clear over on the other side of the SAM3X chip and located nowhere near the ICSP header but yes as you said (I think) the ICSP header is adjacent to and even appears directly connected with the 16U programming port so yes...that is what was confusing.  I tried using my forum creds to edit the page but they must be different because it doesn't work smiley

Now I'm just hoping the pinout on the SPI header is what is accurately represented there or if it isn't then the pin-out for ICSP and SPI header are identical.

Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The pinout is the same but the headers are mounted in opposite directions, have a look at the unofficial pinout diagram.

http://forum.arduino.cc/index.php?topic=132130.0

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the thorough clarification on that.  I'd already accounted for it.  Thankfully, I at least know how to find pin 1  of most any header and IC.
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you control how the SPI library manages your CS pins? i.e how to tell the SPI library that your CS pin you used in the begin, setXXXX, and transfer calls is active high or low?
« Last Edit: May 25, 2013, 06:16:10 pm by exedor » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't read that tiny pic in an ocean of white. A larger pic would be nice and/or a link to a data sheet.

Quote
How do you control the SPI library managing your CS pins active high or low?
With normal SPI you just select a pin and control it yourself. The Due has extended SPI which probably uses the SAM's dedicated CS pins but I don't know how that is implemented.

Quote
How do you control the SPI library managing the reset pin as active high or low?
You don't, reset has nothing to do with SPI. If you really want to reset that chip you have to use a spare pin and do it yourself.

Quote
What is the behavior of the reset pin?
Ummm, it resets the device smiley Without a data sheet I don't know.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I modified my original posting probably while you were reading it smiley

Thank you very much for the reply.  I looked at the schematics and noticed that it was as you said and the reset pin is not something that gets written to but is rather connected to the SAM3X reset line I would imagine to either allow an SPI device to reset the SAM3X and/or allow an SPI device to get reset when the chip resets.  That became pretty clear as soon as I understood where it went.  I also noticed the attachment was tiny right after attaching it and since I already cleared up my question with the reset, I removed it but I'm posting it here again (and larger of course) so you can see that the CS pin on this particular package is sort of backwards from what most SPI devices use which is  kind of the source of my problems.  While I can manage it myself, which is what I was doing on the Arduino UNO with an older bit banging library, I was left with the impression from the docs that the stock SPI library does it for you.

In my case it will probably work because by default the library, I believe uses pin 52 or something way up there so as long as I call:

ISP.begin() and not ISP.begin(10) like I was doing it will be OK.  It's also a good thing I'm not trying to use multiple SPI devices since this one's CS is goofy.
I'm thinking it might be nice to offer an overloaded begin that looks something like this:

ISP.begin(10, HIGH);
With the second param being the active state of the CS pin specified and being defaulted to LOW for calls that do not specify it.

It sounds like I'm going to have to dig into the implementation and climb through the SAM3X data sheet and all kinds of macros in underlying code to figure this out...bummer...


* chip.png (20.41 KB, 303x360 - viewed 85 times.)
« Last Edit: May 25, 2013, 08:18:29 pm by exedor » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As there is no support for an active high CS signal you either have to add an external inverter or do it yourself with a GPIO pin.

Quote
ISP.begin(10, HIGH);
The polarity is set by the hardware, I don't think it's possible to invert it internally although if you dig deep into the data sheet there may be an option for pin inversion. There is on some CPUs but I've not seen that with the SAM.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I was noticing that myself.  I've spent the afternoon studying the data sheet.  Holy cow it is VERY large and there are MANY MANY features of this thing.  Some of which the Due doesn't even expose.  For example, there are two hardware quadrature encoders.  I just spent the last 2 weeks ironing out extremely efficient interrupt routines to do the same thing.  I learned the pins those lines are connected are available on my project if I re-route pin 2 so I can use Pins 2, 13, an A7 (AD7) not sure which yet for the index pulses.  I may do that when I get to it but for now the interrupts I've written seem to be doing a fine enough job.

I did find the 4 bits in the register that are used for managing the CS pins.  Did you know you can configure them to be addresses that feed a built-in MUX allowing you to manage up to 15 or 16 total SPI devices all on the same TX/RX pins?  Crazy, crazy.

I also re-read the datasheet on my chip and it technically isn't SPI.   it's really 3-wire or something like that. It has SCLK, DataIn (MOSI on SPI,) and CS.  Then there is an error pin which could technically be the MISO but wasn't designed as such.  Still it's desirable to use it so I'm not burning other pins I need for other things so, yes I've resigned myself to using a separate I/O pin for CS.

Given all the above, I'd like to find a way to use the CS lead that actually isn't connected to any of the Arduino pins because right now I'm burning a digital pin I actually kind of need (52) just because that's the default in the SPI library and IS NOT the one that actually controls chip select.

Also, I discovered that Timer 1 channel 0 must be used with SPI somehow because when I use that timer to manage another function it completely disables SPI.  I've moved my timer interrupt over to Timer 1 channel 1 and now both seem to be working again.

I'm wondering how that will affect trying to use the hardware quadrature decoder with SPI as well.  So many possibilities, so little time....
smiley
Logged

Pages: [1] 2   Go Up
Jump to: