0
\$\begingroup\$

Working on designing an ESC for BLDC motor and I need 6PWM. I am using ATMEGA328p-AU. I need to program the M328p after its in the PCB so I need to leave some pin outs for SPI. But some PWM and SPI pins are same. I applied a switch/buffer between MISO and MOSI. But to enable the SPI mode, I would always need the SS pin as input while also need it in PWM. What can I do?

If possible can I change SS pin?

\$\endgroup\$
2
  • \$\begingroup\$ I believe the ATmega can also use its UART's in SPI mode, though it might be a headache in slave mode. Never used that feature. Perhaps a different chip with more pins? e.g. ATmega 1284? (you still lose one of the OCx lines to SS) \$\endgroup\$
    – Pete W
    Feb 23 at 15:28
  • \$\begingroup\$ You don't need the SS pin to program the atmega, but the RESET pin. As long as you only need SPI for uploading via AVR-ISP you can use all 6 PWM channels. \$\endgroup\$
    – Sim Son
    Feb 25 at 3:09
0
\$\begingroup\$

Edit: This is what bootloaders are good for. For some period of time, when your device comes out of a power-on/Reset, the MCU is in Slave mode waiting to receive programming. After some set time, it switches to Master mode and runs the normal program.

You can change the SS pin to any other DIO pin and you can use Analog pins as DIOs for the circuits slave (motor control) operation so you don't enable your regular slave while programming.

To use analog pins as DIO, A0 = DIO14, A1 = DIO15, Etc... Set the DIO number pinMode to output.

For setting the SS pin number, you can #define ss= Whatever pin you like but make sure to set that pin as an output and write it high before setting the rest of the SPI settings. Arduino site has good notes on that if you have any trouble.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ From what I found, I can only change SS pin for master but for slave it is hardware fixed. \$\endgroup\$ Feb 23 at 11:10
  • \$\begingroup\$ @Creetintrim Thanks for pointing out that I wasn't clear enough. It did seem like I was suggesting that the SS could change for either mode. I made an edit to fix that. \$\endgroup\$ Feb 23 at 16:31

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.