Read the SPI pins directly??

06 Jun 2011

Hey fellow mbedians....

So I have a working SPI routine that talks to an ADC chip but the way it works requires I pull the clock low and then wait for the MISO pin to go low indicating a convertion is complete before I clock the rest of the signal. So my question is how can I do this using the SPI routines we have available?

Is there a way to use the MISO pin as an SPI pin but also read it as a digital Input? I think this would be done by bringing the clock low and with a timeout waiting for the MISO pin to go low and then write my SPI transaction to read the other 32bits.

I already have the pcb so cannot route to another I/O pin plus thats really a wasted I/O in my opinion since the MISO pin is being read at some level in the SPI routines right?

Thoughts??? Ideas???

06 Jun 2011

The Mbed SPIs can have SSCLK on either p7 or p13. You didn't say which port you are using. However, from the manual:-

9.5.4 page 127 wrote:

GPIO port Pin value register FIOxPIN (FIO0PIN to FIO4PIN- 0x2009 C014 to 0x2009 C094)

This register provides the value of port pins that are configured to perform only digital functions. The register will give the logic value of the pin regardless of whether the pin is configured for input or output, or as GPIO or an alternate digital function. As an example, a particular port pin may have GPIO input, GPIO output, UART receive, and PWM output as selectable functions. Any configuration of that pin will allow its current logic state to be read from the corresponding FIOxPIN register

So, being able to read the pin is a matter of:-

For p7, which is P0.7

  // Returns true if high
  bool value = (LPC_GPIO0->FIOPIN & (1UL << 7)) == 0 ? false : true;

For p13, which is P0.15

  // Returns false if low
  bool value = (LPC_GPIO0->FIOPIN & (1UL << 15)) == 0 ? false : true;

Or simply

  if (LPC_GPIO0->FIOPIN & (1UL << 7)) {
    // Pin high
  }
  else {
    // Pin low
  }