Author Topic: Atmega1284p use SS pin (PB4) as input for simple push button -> hang  (Read 836 times)

0 Members and 1 Guest are viewing this topic.

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
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!
Boron rhymes with moron
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4675
  • Country: nr
  • It's important to try new things..
Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
« Reply #1 on: July 26, 2019, 11:27:56 pm »
Is the 1284p supported by Arduino IDE today?
 

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
« Reply #2 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...
Boron rhymes with moron
 

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
« Reply #3 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.
Boron rhymes with moron
 

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
« Reply #4 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.
Boron rhymes with moron
 

Offline nigelwright7557

  • Frequent Contributor
  • **
  • Posts: 689
  • Country: gb
    • Electronic controls
Re: Atmega1284p use SS pin (PB4) as input for simple push button -> hang
« Reply #5 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf