0
\$\begingroup\$

This is a follow/new insight regarding my previous question Messages for SPI protocol.

One idea from that question is to use the SS line to know a new message is being sent from the master to the slave. The master will be the STM32 and the slave the Arduino, see below:

  Slave   <---  Master
 Arduino  (SPI) STM32
   |            ^ ^ ^
   V            | | |
RS485/DMX512   3x UART/MIDI

The Master receives MIDI signals from various sources, processes them, transmits (changed) MIDI messages back and sends SPI messages to the Arduino which sends the DMX signals.

So far so good, I am currently implementing the Arduino code (including a Windows test application).

The reason I use an Arduino for RS485/DMX is mainly because I couldn't get it to work on an STM32, but also to relieve the STM32 processing power.

However, I need more SRAM on the Arduino, so I will use a SPI SRAM chip (32K256). The problem is, that I'm not sure if I can let the Arduino be the slave.

SPI RAM 32K256
    |(SPI)
    V
   Slave   <---  Master
  Arduino  (SPI) STM32
    |            ^ ^ ^
    V            | | |
RS485/DMX512     3x UART/MIDI

Some things I considered:

  • Making the Arduino the Master, and poll to the STM32 (resulting in my useless poll events likely).
  • Keeping the STM32 master and when a send fails to retry.
  • Using I2C but I think SPI is easier to implement.

Afaik the communication needs to be completely synchronous, but I'm not sure if there is some 'relaxation' due to buffers inside the SPI peripherals.

Some more background information about the entire project:

  • The STM32 read inputs from various MIDI inputs (synthesizers mainly)
  • At a later stage I might also add other inputs (non MIDI).
  • The STM32 processes these messages and sends out MIDI messages and commands for the Arduino slave.
  • The Arduino slave processes the messages which can be something like (make all front DMX lights fade in and out between red and blue, make lights X and Y green, switch on stroboscope with speed 50, etc). These messages all have the same length (18 bytes).
  • For each DMX light (17 so far, but can increase in future), I have a class (instance) that keeps information (max 64 bytes) per light, this will not fit in an Arduino, so I use external SRAM.
  • As often as possible (but at least every few ms), the Arduino processes a light, by reading its data from the SRAM, and changing the fade colors, and also processes new commands from the master if there are any. And finally saving back the changed data to SRAM.

Any insights would be helpful.

\$\endgroup\$
  • 1
    \$\begingroup\$ Depending on the speed you need, implementing SPI on a bit banging basis is fairly straightforward and usually very tolerant of variable bit timings. \$\endgroup\$ – Peter Smith Jun 3 '19 at 13:05
  • 1
    \$\begingroup\$ An insight: slave comms back to a master are usually the most vulnerable to be received correctly. \$\endgroup\$ – Andy aka Jun 3 '19 at 13:18
  • 2
    \$\begingroup\$ Based on your second diagram, it appears that the Arduino needs a SPI master interface to talk to the SRAM and a SPI slave interface to receive messages from the STM32. Is there some reason this isn't doable? \$\endgroup\$ – Dave Tweed Jun 3 '19 at 13:19
  • 1
    \$\begingroup\$ So then bit-bang it, or use some other protocol. You say that the STM -> Arduino link is relatively low bandwidth -- can you put any actual numbers to that? \$\endgroup\$ – Dave Tweed Jun 3 '19 at 13:21
  • 2
    \$\begingroup\$ Sounds like an XY problem. You need 32 kilobytes of SRAM on Arduino for what? I would imagine Arduino is just the part that sends out continuously the last complete DMX packet that the STM32 told to send. Please describe in more detail what MCU does what in the system. \$\endgroup\$ – Justme Jun 3 '19 at 13:22
2
\$\begingroup\$

Making the Arduino the Master, and poll to the STM32 (resulting in my useless poll events likely)

Perhaps you can have an extra "interrupt" line from the STM32 to the Arduino to signal when data is available. It could directly trigger an interrupt on the Arduino.

schematic

simulate this circuit – Schematic created using CircuitLab

If you have fixed size data packets, the STM32 SPI+DMA peripherals can handle SPI slave traffic autonomously, without any CPU intervention after the interrupt line is triggered (OK, the signal must be reset eventually, a DMA transfer complete interrupt, or a one-shot timer can do that).

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This sounds very usable, I never tried SPI + DMA but it's good to try that. \$\endgroup\$ – Michel Keijzers Jun 3 '19 at 13:32
  • \$\begingroup\$ Thanks ... and two small additional questions (I don't think the Arduino has DMA, but I guess I can use it on the STM32 (more useful too, because that will be the critical device), and what means the NSS pin (N??? Slave Select) ? \$\endgroup\$ – Michel Keijzers Jun 3 '19 at 14:13
  • \$\begingroup\$ @MichelKeijzers 1. Yes, DMA is on the STM32 side. It can feed the SPI data register with full speed, without noticeably slowing down program execution (I am using it e.g. to update SPI displays in the background). 2. For some reason, Chip Select is called NSS in ST documentation. INverted / Negated Slave Select, I'd guess. \$\endgroup\$ – followed Monica to Codidact Jun 3 '19 at 14:19
  • \$\begingroup\$ Thanks for the additional info (btw, I'm also planning to add a display, but I'm intending to use I2C for that, having already an I2C 1602 and 2004 module. The STM will hopefully (if I ever finish the part above) get more inputs (like IR, nRF and maybe even more) and be replaced by an STM32F4VET6 (instead of STM32F1C8T6). \$\endgroup\$ – Michel Keijzers Jun 3 '19 at 14:22
  • 1
    \$\begingroup\$ @MichelKeijzers If you upgrade the ST controller, it could certainly spare some RAM and cycles to hold the data structures of the lights as well, making the extra SRAM part unnecessary. \$\endgroup\$ – followed Monica to Codidact Jun 3 '19 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.