0
\$\begingroup\$

I need to use my Arduino Uno (ATmega328) as an SPI slave and have still have access to at least 5 PWM pins. The only issue is that this means I will have to use pin 10 (Slave select / PB2) as the fifth PWM pin because pin 11 (MOSI / PB3) is definitely not an option and it appears that the moment I initiate SPI in slave mode it stops PWMing pin 10 and simply turns it off. Would it be possible to somehow restore PWM access to this pin? I do not need this pin for slave select, I can rather use a plain IO and just attach and detach SPI upon interrupts from it thereby emulating slave select.

\$\endgroup\$
4
  • \$\begingroup\$ Or you could use programmed SPI instead of hardware SPI. \$\endgroup\$ – jippie Dec 2 '13 at 18:50
  • \$\begingroup\$ Programmed SPI and/or programmed PWM would both mess up the working of my specific application which cannot afford to stand of as many cycles. \$\endgroup\$ – Gerharddc Dec 2 '13 at 19:26
  • \$\begingroup\$ Depends on what rates you need, but could use the standard digital pins for PWM code.google.com/p/rogue-code/wiki/SoftPWMLibraryDocumentation \$\endgroup\$ – rom Dec 2 '13 at 19:35
  • \$\begingroup\$ You could still use OCR and OVF to trigger the ISRs for PWM. \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 2 '13 at 23:17
1
\$\begingroup\$

The ATmega328p datasheet section 18.3.1 states

the Slave Select (SS) pin is always input.

where using the SPI in slave with out a SS would likely have issues with sync'ing the first bit of the data. Where if that is not a problem then I would suggest that perhaps a Leonardo would solve your problem. It has 8 PWM's, none on the SPI. Whereas its SPI SS is wired to the RXLED and not to a header. Otherwise the Mega would have all what you want.

\$\endgroup\$
0
\$\begingroup\$

The Hardware SPI module forces the use of the Assigned SS pin on slave mode.

enter image description here

The pin schematic shows that it is automatic, and cannot be overwritten, as long as the SPI module is in use.

See the ATMega328p data sheet, section 18.2 and 18.3.

You need a software SPI implementation.

\$\endgroup\$

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.