C Programming and SPI port.

29 Oct 2010 . Edited: 29 Oct 2010

I have a programming question. I wish to write a hex number to the spi.write (hexnumber). How do I do that?

SPI spi(p5, p6, p7);

 serial pc(USBTX, USBRX); // tx, rx

main () {

 

        char str[2];   
       pc.printf ("\n Please type hex number to be written: ");
       pc.scanf ("%s", &str);  // don't think this is correct. Please advice.
       spi.write (str);

}

 

29 Oct 2010

Maybe something more like this?

    int i
    pc.printf ("\n Please type hex number to be written: ");
    pc.scanf ("%x", &i );
    spi.write (i);