Please explicitly define which values you tried. There are 180 million logically possible values so I seriously doubt that you tried all of them.
I would expect a value of 500000 to work with above code.
sometimes the arduino responds the right data, most of the time it answers with the same value the teensy master sends through MOSI
How do you know? In the code you don't check the returned value.
"the OP doesnt want to share" .. come on, are you for real ? (yes it's obviously on the teensy side )
I mean I really tried tons of values and intermediate...which lead me to ask on this forum a less empirical way to do this
is there a way to predict the frequency I should use in the teensy SPI config to be compatible with the arduino (from it's cpu clock frequency ?) I mean teensy and arduino mini pro dont even have CPU freqs that are multiple of one another
would the SPI slave "adapt" to the SCK or does the frequency asolutely needs to be 100% precise ?
I honestly feel like I am gonna give up SPI on this one and use good ole regular/UART baud serial protocol...hoping they would be "platform independant"
A slave does not "adapt" as such, it will just follow whatever clock speed is set on the CLK line. In contrast, UART Serial requires accurate timing from both sides to work reliably.
Why don't you post the complete code that gives your best results so far? The Arduino code you posted doesn't seem to produce any output so I don't see how you can tell whether it works or not.
Maximum frequency allowed is 1/2 of the CPU frequency, so 8 MHz for a 16 MHz Arduino.
This provided you can read the buffers fast enough, and wiring has low enough stray capacitance, etc.
Indeed 500 kHz as suggested above sounds like a good starting point.
phil123456:
"A slave does not "adapt" as such, it will just follow whatever clock speed is set on the CLK line"
quiet contradictory
No, it is how SPI works. Shift registers running SPI don't have clocks, the SCLK line tells them when to accept data.
but you gave me an idea, I'll put a debug pin HIGH/LOW in the interrupt routine
which should give me an idea of the max frequency I should use on the master CLK
Or you could use the default AVR SPI speed which is CPU Clock/4... 4MHz on an Uno but it can go 8MHz and have less time to process what's coming in. Clock divider choices on AVR are powers of 2....
I guess the MISO = MOSI is related to the fact the SPDR register is used both for input/output
phil123456:
so it means that the external clock tells them when to sample so they "adapt" on it instead of requiring a particular frequency
I know MISO !=MOSI, but on the scope it says otherwise
there is no short circuit on my board neither
I thought I went too fast on teensy side, but I tried really low freqs, thinking that it would give enough time to the arduino
SPI is a circular bus, it writes and reads the same bit in the port register 1 bit at a time for 8 bits then data and port write are available. Some SPI slave devices can be daisy-chained, output shift regs and input shift regs can be chained so that every byte sent to the outputs reads a byte from the inputs. More usually it's output registers on MOSI and no connection to MISO.