Photon: SPI slave / manually writing to registers

So my goal is to set up the photon as an SPI slave. From what I understand this can’t be done with the provided firmware.

I looked up the datasheet for the Cortex M3 and found the addresses mapped to the SPI registers. I thought the easiest course of action would be to simply interact with these registers from my code. The problem is, I’m not sure how to define my own “register variables” that can be read and written to. In Arduino they are usually pre-defined such as PORTB etc. How do I define my own using the memory addresses? Are the addresses from the Cortex M3 datasheet the right ones to use? Is there a simpler way to implement an SPI slave?

REG_SPI0_CR = 0x40008000 // (SPI0) Control Register
REG_SPI0_MR = 0x40008004 // (SPI0) Mode Register
REG_SPI0_RDR = 0x40008008 // (SPI0) Receive Data Register
REG_SPI0_TDR = 0x4000800C // (SPI0) Transmit Data Register
REG_SPI0_SR = 0x40008010 // (SPI0) Status Register

I appreciate any and all help.

@JLaferri, I believe the Photon firmware does support slave mode. Perhaps @BDub can shed some light on this. :smile:

@peekay123, Could you elaborate on your belief that the Photon firmware supports slave mode? Do you have any references?

The reason i’m asking is that i’m trying to set up a photon as a SPI slave but am having trouble ifguring out the best way to do so without writing my own library.

@peekay123, it seems that I was confusing I2C slave mode with SPI Slave mode. The STM32 can support SPI slave mode but it is not done in the firmware presently. Perhaps @mdma can comment on this?

1 Like