Rotary Sensor MLX90316

What are you developing?
Post Reply
Juli
Posts: 6
Joined: Mon Feb 27, 2017 5:38 pm

Rotary Sensor MLX90316

Post by Juli » Mon Feb 27, 2017 6:05 pm

Hi,
I try to connect the rotary sensor Melexis MLX90316 to an STM32F103 via the SPI serial communication. With an Arduino it works perfectly but with the STM32 I get no values from the MLX. Is there something wrong with my code? I get no error messages, it uploads without problems.
Thanks in advance

Code: Select all

// Endlosencoder for MELEXIS MLX90316 mit STM32F103
#include <MLX90316.h>
long enc_alt, enc_neu;											  // alter Wert , neuer Wert (roh aus sensor)
long rev;															     	// Zahl der 0-Durchl�ufe
long enc_pos;
MLX90316 mlx_1 = MLX90316();
int del = 25000;																

void setup() {
	Serial.begin(115200);
	mlx_1.attach(PA15,PB3,PB4);										// (pinSS, pinSCK, pinMOSI);
	enc_neu = mlx_1.readAngle();	enc_pos = enc_neu; enc_alt = enc_neu;
}

void loop() {
	enc_neu = mlx_1.readAngle();  delayMicroseconds(del);
	if (enc_neu - enc_alt > 1800) { rev--; }
	if (enc_neu - enc_alt < -1800) { rev++; }
	enc_pos = rev * 3600 + enc_neu;
	enc_pos = enc_pos * 0.22222222223;										// auf 800 P/rev runterrechnen
	Serial.println(enc_neu);															// Serial.print(" , "); Serial.println(enc_pos);
	enc_alt = enc_neu;
}

stevestrong
Posts: 1147
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Rotary Sensor MLX90316

Post by stevestrong » Mon Feb 27, 2017 7:57 pm

I assume the lib is using software SPI (bit banding).
Use other pins instead of PB3/4, at least one of them may be reserved for the debug port.
Or use the dedicated hardware SPI, on the corresponding pins.

Juli
Posts: 6
Joined: Mon Feb 27, 2017 5:38 pm

Re: Rotary Sensor MLX90316

Post by Juli » Wed Mar 01, 2017 5:51 pm

Thanks for the answer!
I have connected all possible pins to the SPI sensor but it still does not work !
Any more ideas ?

stevestrong
Posts: 1147
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Rotary Sensor MLX90316

Post by stevestrong » Thu Mar 02, 2017 1:34 pm

How do you upload? Over USB?
Be aware that "Serial" is the serial USB, and it takes up to 5 seconds for win10 to reenumerate the serial COM ports after board reset.

Juli
Posts: 6
Joined: Mon Feb 27, 2017 5:38 pm

Re: Rotary Sensor MLX90316

Post by Juli » Thu Mar 02, 2017 7:32 pm

Hi,
Yes I upload via "serial" the upload works perfect. I have added a timer interupt blinker for the PC13 Led in the same skech. The Led is blinking but the sensor doesn´t !

Thanks

Juli
Posts: 6
Joined: Mon Feb 27, 2017 5:38 pm

Re: Rotary Sensor MLX90316

Post by Juli » Thu Mar 09, 2017 5:55 pm

Problem solved !!
I have connected an external pullup-resistor to the MOSI pin - now it works !!
Thanks to all

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest