Topic: SPI slave
(Read 662 times)
May 28, 2013, 12:23 am
New to this, so please bear with me.
Trying to implement Due in SPI slave mode.
Have followed Nick Gammon's excellent article
This all works really well until I try porting the slave code to a Due.
Compiling throws up a series of errors where SPCR SPE and others are undefined.
After doing a bit of digging, it would appear that SPI.h causes the chip to setup in master SPI mode, and that
then certain register bits need to be written to turn it into a slave
At least I think thats what this code is doing.
// turn on SPI in slave mode
SPCR |= _BV(SPE);
However the register architecture on the due is different,
according to the data sheet for the SamX3
there is a register called SPI_MR with a byte called MSTR which must be set 0 to enter Slave mode
(its quite likely there are others I don't know about yet)
Can someone explain the syntax required to do this
Re: SPI slave
May 29, 2013, 09:09 am
Check out the SPI.cpp file at :
C:\Program Files (x86)\arduino-1.5.2\hardware\arduino\sam\libraries\SPI\SPI.cpp
It has a line in it's constructor that goes something like this:
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
I would be willing to bet if you either removed SPI_MR_MSTR or changed the logic to something like:
!SPI_MR_MSTR & (SPI_MR_PS | SPI_MR_MODFDIS) depending on the actual bits you need you might be able to achieve what you are looking for with some variant of this.
Re: SPI slave
May 30, 2013, 11:39 am
I'll study that