SPI with BMI160

Status
Not open for further replies.

Major7

Active member
I've been trying to find how to use the SPI libraries, and it gets confusing pretty quick.

First, the Teensy SCK shares a line with the built in LED. This has been a problem I solved with another library ST LIS3DH (moved SCK over one pin), but the Bosch library doesn't apparently support user designation of the MISO/MOSI/SS/SC at the API level. So I think I'll have to go deeper into the SPI library.

My question is simply this. Where can I hard code a change in the pinouts for SPI to suit my needs? A finder check doesn't even find SPI.H on my Mac.
 
on mac, /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI/SPI.h

SPI works just fine with SCK on pin 13.

before SPI.begin() you can do SPI.setSCK(14);
 
on mac, /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI/SPI.h

SPI works just fine with SCK on pin 13.

before SPI.begin() you can do SPI.setSCK(14);

Thanks. There is no such directory on my Mac. Arduino doesn't even show as an app. I just run it from the icon. It dowloaded as a ZIP file - upon expansion, it just shows one file. It never even installed anything, but it seems to work.
 
On Mac, Apps are folders but are just shown as icons. You might right click the app icon and select "Show content" from the context menu to see the folder structure behind.

Capture d’écran 2018-07-25 à 01.51.14.png Capture d’écran 2018-07-25 à 01.52.35.png
 
First, the Teensy SCK shares a line with the built in LED.

The LED is not a problem. The SCK pin is easily able to drive the LED.

Many, many thousands of people have successfully build projects using SPI with SCK on pin 13 with the LED, on Teensy and also on the many Arduino boards which also have a LED on their SCK pin. Really, this is a non-issue.

support user designation of the MISO/MOSI/SS/SC at the API level. So I think I'll have to go deeper into the SPI library.
.....
My question is simply this. Where can I hard code a change in the pinouts for SPI to suit my needs?

The SPI library supports reassigning the pins. It's documented here (scroll down to "Alternate SPI pins")

You can find examples of using these in the Audio library. Click File > Examples > Audio > WavFilePlayer.

https://www.pjrc.com/teensy/td_libs_SPI.html#altpins

A finder check doesn't even find SPI.H on my Mac.

On your Mac, control-click Arduino and choose "Show Package Contents".

Then navigate to Contents/Java/hardware/teensy/avr/libraries/SPI. However, you'd do better to use the web page documentation and example programs than digging into SPI.h. But if you really want to look at the code, that's where it's installed on your Mac. The code is also on github:

https://github.com/PaulStoffregen/SPI/blob/master/SPI.h
 
On the SCK topic, I set up a network of three LIS3DH acceleration sensors with 1m long cables (each) in a star configuration. I know that's pushing it for SPI, but it did not work until I moved SCK over one pin. That is a fact. I knocked that setup down and took a different direction (I want 6dof now), so I will wait until I have the BMI160's working on SPI. Right now, I'm having another problem I posted about where Arduino won't play nice with Teensy Duino on my Mac.

Thanks again for the great detail and response time.
 
For driving such long wires, usually adding a series resistor between Teensy and the wire helps. 100 ohms is usually about right, but the optimal value to use depends on the type of wire.

The SPI library uses different drive strength settings for the pin mux on pin 13 vs 14. Normally this doesn't matter. But higher drive strength does drive the pin harder, which can result in more high speed noise issues on long wires. Again, the resistors for impedance matching can really help.
 
Status
Not open for further replies.
Back
Top