SPI Clarification?

07 Jun 2010

Hi

I am working with a Maxim-IC DS3234 SPI based RTC to learn about SPI on the mbed.  The comments in my code indicate what I believe I am doing which is based on the example in the Handbook.  I am getting 0xFF returned when I really expect I should be seeing 0x01.

I suspect that I am missing something.

Any clarification appreciated.

Thanks

Tim

int main() 
{

    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,3);
    spi.frequency(1000000);

    // Select the device by seting chip select low
    cs = 0;

    // Send the commands to write to test the seconds register
    int value;
    value = 0x00;
    spi.write(0x80);  // set write register to seconds
    spi.write(0x00);  // dummy read
    spi.write(0x01);  // send value of one
    spi.write(0x00);  // dummy read
    spi.write(0x00);  // set read register to seconds

    // Send a dummy byte to receive the contents of the seconds register
    value = spi.write(0x00);
    pc.printf("Seconds register = 0x%X\n\r", value);

    // Deselect the chip
    cs = 1;
}

08 Jun 2010

Hi Tim,

Maybe try the following:

 

int main() 
{

    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,3);
    spi.frequency(1000000);

    // Send the commands to write to test the seconds register
    cs = 0;
    spi.write(0x80);  // set write register to seconds
    spi.write(0x01);  // send value of one
    cs = 1;
  
    // Receive the contents of the seconds register
    cs = 0;
    spi.write(0x00);               // set read register to seconds
    int value = spi.write(0x00);   // read the value
    cs = 1;

    pc.printf("Seconds register = 0x%X\n\r", value);
}

Simon

 

08 Jun 2010

Hi Simon:

Thanks!  That's working.  It also helped that I moved the chip select definition to pin8 which is how I had it wired. Not sure why I said it was on pin9.

I'm off and running now!

 

Tim