[Tinyos-devel] SPI slave select on atm128

Miklos Maroti mmaroti at math.u-szeged.hu
Wed Apr 23 12:44:48 PDT 2008


On Wed, Apr 23, 2008 at 4:40 PM, Philip Levis <pal at cs.stanford.edu> wrote:
>
> On Apr 22, 2008, at 11:53 AM, Miklos Maroti wrote:
> > Hi All,
> >
> > I have noticed that the HplAtm128Spi component updates the SS (slave
> > select) line, while it clearly shouldn't. If more than one chip is
> > connected to the SPI bus then the user of the SpiResource should
> > select the slave when access is granted. This is the extract from
> > HplAtm128SpiC.nc and HplAtm128SpiP.nc files:
> >
> > HplSpi.SS   -> IO.PortB0;  // Slave set line
> >
> >  async command void SPI.initMaster() {
> >   call MOSI.makeOutput();
> >   call MISO.makeInput();
> >   call SCK.makeOutput();
> >   call SS.makeOutput();
> >   call SPI.setMasterBit(TRUE);
> >   call SS.clr();
> >  }
> >
> >  async command void SPI.initSlave() {
> >   call MISO.makeOutput();
> >   call MOSI.makeInput();
> >   call SCK.makeInput();
> >   call SS.makeInput();
> >   call SPI.setMasterBit(FALSE);
> >  }
> >
> >  async command void SPI.sleep() {
> >   call SS.set();
> >  }
> >
> > This does not cause any bug on current platforms where the SPI is bus
> > is connected to a single device, but should be corrected like it is
> > done for the Msp430. The authors of these files are  Philip Levis and
> > Martin Turon. Do you guys want to fix this or should I go ahead and do
> > it? I will hunt down the users of this component and toggle the SS
> > line there as needed.
> >
>
> Sounds good.
>
> My guess is that this crept in because the micaZ and mica2 only have a
> single peripheral on the SPI bus. The only users of this component should be
> the CC1000 and CC2420.
>
> Phil
>

Ok. I think the propef fix is to remove SS.clr from SPI.initMaster but
to keep the SS.makeOutput there. The SS.makeInput should stay in
SPI.initSlave. I am not sure about the SPI.sleep, and I think the
SS.set should be removed from there as well. What is the purpose of
SPI.sleep anyways? It is called from Atm128SpiP only:

void stopSpi() {
    call Spi.enableSpi(FALSE);
    started = FALSE;
    atomic {
      call Spi.sleep();
    }
    call McuPowerState.update();
  }

If the SPI bus is disabled then do we have to care about the state of
the SS line (for example not to leak current), but if so then why dont
we do the same to MISO/MOSI/SCK? The data sheet does not say much, but
I think these PIOs can be used freely if the SPI is disabled. So the
questions: 1) how not to leak current if the SPI is disabled, and 2)
what to do in Spi.sleep()?

Miklos


More information about the Tinyos-devel mailing list