user81549: I am trying to verify sck output on my arduino uno. I don't have oscilloscope so I loopbacked miso to sck and tried Executing int rx0=SPI.transfer(5) while printing this using Serial.printrx0) it is giving 255.Whether this is expected output?

user7508: As suggested by KIIV and myself, you can test the SPI port by:

connecting MOSI to MISO and checking if you receive what you send
connecting SCK to the timer input T1 and counting the clock pulses.

Below is a sketch that performs both tests:
/*
 * Test the SPI port.
 *
 * Connect:
 *   MOSI (11) to MISO (12)
 *   SCK (13) to T1 (5)
 */

void setup() {
    Serial.begin(9600);

    // Configure SPI port.
    DDRB |= _BV(PB2)   // SS (digital 10) as output
          | _BV(PB3)   // MOSI (digital 11) as output
          | _BV(PB5);  // SCK (digital 13) as output
    SPCR = _BV(SPE)    // enable port
         | _BV(MSTR);  // master mode

    // Configure Timer 1.
    TCCR1A = 0;          // normal mode
    TCCR1B = _BV(CS10)   // count rising edges of T1 = digital 3
           | _BV(CS11)   // ditto
           | _BV(CS12);  // ditto
}

void loop() {
    TCNT1 = 0;  // clear timer
    uint8_t data = random(256);
    Serial.print(data);
    Serial.print(" -> ");
    SPDR = data;  // send
    delay(1);
    if (bit_is_set(SPSR, SPIF)) {  // transfer complete?
        Serial.println(SPDR);
    } else {
        Serial.println("nothing received");
    }
    Serial.print("    clock pulses: ");
    Serial.println(TCNT1);
    delay(1000);
}

It should print:
167 -> 167
    clock pulses: 8
241 -> 241
    clock pulses: 8
217 -> 217
    clock pulses: 8
[...]


81549: <p>I am trying to verify sck output on my arduino uno. I don't have oscilloscope so I loopbacked miso to sck and tried Executing int rx0=SPI.transfer(5) while printing this using Serial.printrx0) it is giving 255.Whether this is expected output?</p>
 7508: <p>As suggested by KIIV and myself, you can test the SPI port by:</p>
<ul>
<li>connecting MOSI to MISO and checking if you receive what you send</li>
<li>connecting SCK to the timer input T1 and counting the clock pulses.</li>
</ul>
<p>Below is a sketch that performs both tests:</p>
<pre class="lang-cpp prettyprint-override"><code>/*
 * Test the SPI port.
 *
 * Connect:
 *   MOSI (11) to MISO (12)
 *   SCK (13) to T1 (5)
 */

void setup() {
    Serial.begin(9600);

    // Configure SPI port.
    DDRB |= _BV(PB2)   // SS (digital 10) as output
          | _BV(PB3)   // MOSI (digital 11) as output
          | _BV(PB5);  // SCK (digital 13) as output
    SPCR = _BV(SPE)    // enable port
         | _BV(MSTR);  // master mode

    // Configure Timer 1.
    TCCR1A = 0;          // normal mode
    TCCR1B = _BV(CS10)   // count rising edges of T1 = digital 3
           | _BV(CS11)   // ditto
           | _BV(CS12);  // ditto
}

void loop() {
    TCNT1 = 0;  // clear timer
    uint8_t data = random(256);
    Serial.print(data);
    Serial.print(&quot; -&gt; &quot;);
    SPDR = data;  // send
    delay(1);
    if (bit_is_set(SPSR, SPIF)) {  // transfer complete?
        Serial.println(SPDR);
    } else {
        Serial.println(&quot;nothing received&quot;);
    }
    Serial.print(&quot;    clock pulses: &quot;);
    Serial.println(TCNT1);
    delay(1000);
}
</code></pre>
<p>It should print:</p>
<pre><code>167 -&gt; 167
    clock pulses: 8
241 -&gt; 241
    clock pulses: 8
217 -&gt; 217
    clock pulses: 8
[...]
</code></pre>
