thanks, I got the code from the site copy and pasted it into. it looks like this:
#include <SPI.h>
// The setup() function runs once each time the micro-controller starts
void setup()
{
SPI.begin(10);
SPI.begin(4);
while (true)
{
// Receive using pin 10 as SS
byte byteFromTen = SPI.transfer(10, 0x00);
// Transmit 123 using pin 10 as SS
SPI.transfer(10, 123);
// Both directions:
byte otherByteFromTen = SPI.transfer(10, 123);
// Receive using pin 4 as SS
byte byteFromFour = SPI.transfer(4, 0x00);
// Transmit 123 using pin 4 as SS
SPI.transfer(4, 123);
// Both directions:
byte otherByteFromFour = SPI.transfer(4, 123);
}
}
here is the code from the site, I dont see any significant changes other then putting part of the code in a loop and fixing the last line of the code.
void setup() {
SPI.begin(10);
SPI.begin(4);
}
void loop() {
// Receive using pin 10 as SS
byte byteFromTen = SPI.transfer(10, 0x00);
// Transmit 123 using pin 10 as SS
SPI.transfer(10, 123);
// Both directions:
byte otherByteFromTen = SPI.transfer(10, 123);
// Receive using pin 4 as SS
byte byteFromFour = SPI.transfer(4, 0x00);
// Transmit 123 using pin 4 as SS
SPI.transfer(4, 123);
// Both directions:
byte otherByteFromFour = SPI.transfer(4, 123); // original otherByteFromTen
}
according to this site http://gammon.com.au/spi the default mode is mode0, I dont care right now if it is LSB first or MSB first because I have a stability issue. I am looking for two things: 1. if it outputs the same code 2. If the waveform is consistent with the code and the stability of the clock signal.
for the first item I get this from the logic analyzer. MISO is connected to 3v3 cause I dont care abot it and it cannot affect the mosi
Time [s] Analyzer Name Decoded Protocol Result
0.000004 SPI MOSI: 0x6E; MISO: 0xFF
0.00007 SPI MOSI: 0x59; MISO: 0xFF
0.000118 SPI MOSI: 0x22; MISO: 0xFF
0.000178 SPI MOSI: 0xD2; MISO: 0xFF
0.000238 SPI MOSI: 0xDD; MISO: 0xFF
0.000308 SPI MOSI: 0x77; MISO: 0xFF
0.000374 SPI MOSI: 0x95; MISO: 0xFF
0.000416 SPI MOSI: 0x4A; MISO: 0xFF
0.00046 SPI MOSI: 0x81; MISO: 0xFF
0.00052 SPI MOSI: 0xB2; MISO: 0xFF
0.00059 SPI MOSI: 0x7B; MISO: 0xFF
0.00065 SPI MOSI: 0xDD; MISO: 0xFF
0.00072 SPI MOSI: 0xB2; MISO: 0xFF
0.000768 SPI MOSI: 0xBC; MISO: 0xFF
Two of the four transmits are supposed to be 0x00 so something is wrong and either the code or the arduino itself.
The waveform confirms what the logic analyzer is giving me and the clock signal is unstable, the pulses vary from 8us to 2us. WIRING IS NOT AN ISSUE.
Instead of giving me sites can you help by pointing to where the error is?