Go Down

Topic: Configure Arduino Due as SPI slave (Read 809 times) previous topic - next topic

venksbond

Sep 18, 2013, 06:07 am Last Edit: Sep 18, 2013, 09:18 am by venksbond Reason: 1
In SAM3X8E datasheet section 33.8.2 pg.no:699 described how to configure SPI as slave mode. I set
Code: [Select]
SPI_MR = SPI_MR & 0xFF0F00FE;  MSTR set to 0. when i compiled got

error: 'SPI_MR' was not declared in this scope. Is it right?

Thanks
Venkatesh

Nick Gammon

I get the same error, however it seems to be declared here on my Mac:

/Applications/Arduino_Due_1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3n/include/component/component_spi.h

Also here, and in a few other places:

/Applications/Arduino_Due_1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/component/component_spi.h

I don't know enough about the build process to comment on why those includes don't seem to be active, perhaps someone else can help?

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

ralphnev

you have to state the correct spi instance

as seen in
/hardware/arduino/sam/system/libsam/source/spi.c

Code: [Select]

{snip out lots of code}
extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration )
{
    pmc_enable_periph_clk( dwId ) ;
    spi->SPI_CR = SPI_CR_SPIDIS ;

    /* Execute a software reset of the SPI twice */
    spi->SPI_CR = SPI_CR_SWRST ;
    spi->SPI_CR = SPI_CR_SWRST ;
    spi->SPI_MR = dwConfiguration ;   ///<------------------------------------------------------------
}
{more code follows }


venksbond

#3
Sep 20, 2013, 04:01 am Last Edit: Sep 20, 2013, 04:36 am by venksbond Reason: 1
Here i did config after digging all files from hardware folder in sam for pin register's have a try and reply.

Code: [Select]

void setup();
{
pinMode(PIN_SPI_MISO,OUTPUT);
 REG_SPI0_MR = REG_SPI0_MR & 0xFF0F00B6;
 REG_SPI0_WPMR = REG_SPI0_WPMR & 0xFF0F00FE;
 
 REG_SPI0_CR=0x1;
 
 REG_SPI0_CSR=0x00000400; //Configured to 8bit transfer & 21MHz
}


Im getting "FF" reply from due(slave) in rpi(master)

Go Up