EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: nemail2 on July 26, 2019, 11:25:20 pm

Title: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
Post by: nemail2 on July 26, 2019, 11:25:20 pm
Hi

I'm struggling with using PB4 (SPI Slave Select) as an input in my current project. Unfortunately I did the PCB in a way that I need this pin working as an input for a standard tactile switch button.
I understand that in SPI Master mode when the SS pin is pulled low by external periphery, the SPI bus goes to slave mode. Subsequently in my software, the code tries to communicate via SPI with a DAC and that's where the whole thing freezes. I guess because the SPI bus is still in slave mode.

I already tried to do this, right after recognizing that the button has been pressed (i.e. PB4/SS has been pulled low):
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
also, I did set SS, MISO and SCK as a output, right after recognizing the button press.

Still, the firmware hangs as soon as it tries to communicate with the SPI DAC.

I do use the Arduino Framework.

Any ideas/ways how to do this without redoing the PCB?

Thanks!
Title: Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
Post by: imo on July 26, 2019, 11:27:56 pm
Is the 1284p supported by Arduino IDE today?
Title: Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
Post by: nemail2 on July 26, 2019, 11:35:17 pm
there is a third party core for it because basically every 8 bit 3d printer mainboard uses the 1284p and one of the most popular firmwares (Marlin) is based on the Arduino Framework.
Marlin is a huuuge project and thorougly tested for many years. so i gues the used 1284p core is mature...
Title: Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
Post by: nemail2 on July 26, 2019, 11:57:29 pm
ok fixed, the library I was using didn't make use of SPI Transactions. Fixed that, and now the thing isn't freezing anymore.
Title: Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
Post by: nemail2 on July 27, 2019, 01:30:10 am
nah, false positive, still hanging. went with using another pin than slave select of the atmega.
arduino SPI library documentation clearly says to always use the SS pin as an output. so i clearly goofed that.
Title: Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
Post by: nigelwright7557 on August 09, 2019, 04:41:59 pm
nah, false positive, still hanging. went with using another pin than slave select of the atmega.
arduino SPI library documentation clearly says to always use the SS pin as an output. so i clearly goofed that.

I got caught out with a PIC micro with USB pins.
A couple of the pins have a usb function on them that can't be used for anything else if using USB module.
Its a pig having to hack a nice pcb to move a pin function elsewhere.
The ICSP pins can be a nuisance too. I found sometimes the PICKIT3 locks up if I use data or clock pins.
The trick is to put resistors in series with the pins.