Hello everyone.
For one of my projects, I need to get the measurements of several accelerometers, at precise time intervalls, and log the data obtained on an SD card.
As I want the sampling rate to be as high as possible, I choosed SPI working accelerometers, the LSM6DSOX IMU, and Bought brand new teensy boards to run the programs (I have both the 4.0 and 4.1).
I don't use specialised libraries as I want to give the most appropriate filtering parameters for my accelerometers, and want to be able to add a 9-DOF IMU (LSM9DS1) to the system, I also use the legacy IDE, the new IDE doesn't work on my laptop (less than a year old, but after 10 minutes of loading without anything, I gave up).
To do my early tests and make bit by bit my programs I first started with the teensy and an accelerometer.
My connections :
sensor <-> teensy
Vin <-> 5V (regulated by the adafruit breakout board)
Gnd <-> G
Scl (Sck) <-> 13
Sda (DI) <-> 11 (MOSI)
DO <-> 12 (MOSI)
CS <-> 10
I have two issues :
1) the SPI communication doesn't work : I tried to check the contents of the 0x0F register (WHO_AM_I), and it always returns a 0, instead of the expected answer : 01101100, the programs works flawlessly with an arduino uno and a levelshifter in beetween (5V MCU, 3.3V sensor).
It SHOULDN'T be an issue of SPI mode as my sensor is designed to work either with mode 0 or mode 3 (see LSM6DSOX datasheet)
2) The Serial interface is full of glitches :
in port selection , if I select teensy port COMX (Teensy 4.x) (X being 4 for the 4.0 and 7 for the 4.1 board) the COM port is always busy and the serial monitor can't be oppened
if I select Serial port COMX (Teensy 3.1/3.2) I get a little error message at each end of programming, the issue being that I need to always close the serial monitor elseway I get big warnings
I should explain that switching to a teensy board seemed a logic choice as it's way faster, has several SPI interfaces, works in 3.3V (no level-shifting required) and more compact than an UNO or other arduino boards, but if I can't get my programs runnning, I will really have wasted 80€ for nothing (not to mention being stuck with a MCU too slow for my project)
For one of my projects, I need to get the measurements of several accelerometers, at precise time intervalls, and log the data obtained on an SD card.
As I want the sampling rate to be as high as possible, I choosed SPI working accelerometers, the LSM6DSOX IMU, and Bought brand new teensy boards to run the programs (I have both the 4.0 and 4.1).
I don't use specialised libraries as I want to give the most appropriate filtering parameters for my accelerometers, and want to be able to add a 9-DOF IMU (LSM9DS1) to the system, I also use the legacy IDE, the new IDE doesn't work on my laptop (less than a year old, but after 10 minutes of loading without anything, I gave up).
To do my early tests and make bit by bit my programs I first started with the teensy and an accelerometer.
My connections :
sensor <-> teensy
Vin <-> 5V (regulated by the adafruit breakout board)
Gnd <-> G
Scl (Sck) <-> 13
Sda (DI) <-> 11 (MOSI)
DO <-> 12 (MOSI)
CS <-> 10
Code:
#include <SPI.h>
const byte CS_ax = 10;
const byte who_reg = 0x0F;
const byte READ = 0b10000000;
//bool read_rq;
//bool req_done = false;
byte who;
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN,OUTPUT);
pinMode(CS_ax, OUTPUT);
digitalWrite(CS_ax,HIGH);
digitalWrite(LED_BUILTIN,LOW);
Serial.begin(9600);
SPI.begin();
//SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE3));
//SPI.endTransaction();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
}
void loop() {
who = read_1_reg(CS_ax,who_reg);
Serial.println(who,BIN);
delay(1000);
// put your main code here, to run repeatedly:
}
byte read_1_reg(byte CS,byte adress){
int result;
// LSM9DS1 expects the read order on the first bit,
//as the registers adresses begin by 0, we add the corresponding read bit
adress = adress | READ;
digitalWrite(CS, LOW);
// send the device the register you want to read:
SPI.transfer(adress);
// send a value of 0 to read the first byte returned:
result = SPI.transfer(0x00);
digitalWrite(CS, HIGH);
return (result);
I have two issues :
1) the SPI communication doesn't work : I tried to check the contents of the 0x0F register (WHO_AM_I), and it always returns a 0, instead of the expected answer : 01101100, the programs works flawlessly with an arduino uno and a levelshifter in beetween (5V MCU, 3.3V sensor).
It SHOULDN'T be an issue of SPI mode as my sensor is designed to work either with mode 0 or mode 3 (see LSM6DSOX datasheet)
2) The Serial interface is full of glitches :
in port selection , if I select teensy port COMX (Teensy 4.x) (X being 4 for the 4.0 and 7 for the 4.1 board) the COM port is always busy and the serial monitor can't be oppened
if I select Serial port COMX (Teensy 3.1/3.2) I get a little error message at each end of programming, the issue being that I need to always close the serial monitor elseway I get big warnings
I should explain that switching to a teensy board seemed a logic choice as it's way faster, has several SPI interfaces, works in 3.3V (no level-shifting required) and more compact than an UNO or other arduino boards, but if I can't get my programs runnning, I will really have wasted 80€ for nothing (not to mention being stuck with a MCU too slow for my project)