ATTiny841, SPI Master Mode and !SS - SPI locks up?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've got a GPS clock based on the MAX6951 and an ATTiny841. The hardware uses PA7 as an ICP pin, which is unfortunate, because it's also !SS for the SPI port. 17.3.2 says that if !SS becomes low, then SPI master mode is aborted and the MSTR bit is cleared. Most of the time (but not all the time), A7 is low.

 

What I'm seeing instead is that the SPI system seems to get wedged, necessitating writing 0 to SPCR and then _BV(SPE)|_BV(MSTR) again.

 

As a workaround, I'm reading PINA7, writing that value to PORTA7 and then turning A7 into an output pin (this avoids the output clashing with the current state of the line, which is an output from another chip), then writing the correct bits to SPCR. When the transaction is done, I write 0 to SPCR and clear DDA7. This works. But if I attempt instead to set SPCR up at initialization time, I must write 0 to SPCR followed by the correct value after turning A7 into an output. Merely forcing MSTR on isn't enough. Neither is writing the correct bits to SPCR. You must write a 0 to SPCR and then reset it.

 

Are there any known errata with the SPI functionality of this chip with regards to !SS in Master mode?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks as if SS is always responsible for haywireability. 

 

So your only choice is to remap the SPI to PA0-PA3 via the REMAP register.  i.e SS goes to PA2 pin.

 

Other makes and models of microcontroller can be configured to ignore the SS bit.   AVRs seem to enjoy the haywireability feature.

 

David.

Last Edited: Sun. Apr 9, 2017 - 08:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Remapping is no good because the remapped pins collide with USART0. The better solution in hardware would be to switch to timer 2, which moves the ICP pin and allows !SS to be unused and therefore safely an output. But all of that is hardware changes. I have firmware that successfully works around the problem, by turning SPI on only when !SS is an output pin, so I don't really need a solution so much as I'd like to understand whether the documentation is incorrect or whether there's something else I missed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have never used a tiny841.

 

Yes, I noticed that remapping would be painful for the USART.

 

And ICP2 look easier to use.   

 

Mind you,  I would always try to use USART_MSPI mode whenever possible.   You get buffered TX and gap-less SPI.   And best of all.   It is immune from haywire.

Life would be so much simpler if you just had a HAYWIRE_DISABLE RW bit in SPSR.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, but more to the point, why does the !SS pin being low seemingly result in more than just MSTR being cleared?