Melexis Gyro MLX90609
juanpablocanguro
Posts: 2
Hello everyone, last night I was going nuts since I couldn't make my new melexis gyro work, I wanted to know if someone had already plug theirs to the basic stamp using its SPI interface.
Anyhow, after overheating my brain I was able to do it, here's a working code if anyone needs it. The weird part is that I haven't found good documentation about its SPI interface, and for some reason when I tried polling the gyro for a reading, it· would give me the same as before, so finally what I·realized is that·I had to send the command that enables the ADC on board, and tells it which channel to use (Gyro or temperature sensor) for every poll, if you poll it again without sending the enabling command it wont work, I though that was weird, anyhow I hope Melexis comes out with better documentation about this great product or someone finds a way around this.
the ADC on·board the sensor·has 11 bit resolution, and the sensor I used here is the MLX90609 with 150°/sec resolution.
' {$STAMP BS2}
' {$PBASIC 2.5}
MOSI CON 0
MISO CON 1
SS CON 2
SCLK CON 3
answer VAR Word
main:
HIGH SS
LOW SS
SHIFTOUT MOSI,SCLK,MSBFIRST,[noparse][[/noparse]%10010100\8] 'start ADC and set channel to 0 (GYRO CHANNEL)
HIGH SS
LOW SS
SHIFTOUT MOSI,SCLK,MSBFIRST,[noparse][[/noparse]%10000000\8] 'poll for reading
SHIFTIN MISO,sclk,MSBPRE,[noparse][[/noparse]answer\16] 'save the answer in a variable
HIGH SS
answer=answer & %0000111111111110 'mask answer to extract data from ADC
answer=answer >> 1
DEBUG HOME,DEC answer,11
GOTO main
GOOD LUCK!!!
Pablo
·
Anyhow, after overheating my brain I was able to do it, here's a working code if anyone needs it. The weird part is that I haven't found good documentation about its SPI interface, and for some reason when I tried polling the gyro for a reading, it· would give me the same as before, so finally what I·realized is that·I had to send the command that enables the ADC on board, and tells it which channel to use (Gyro or temperature sensor) for every poll, if you poll it again without sending the enabling command it wont work, I though that was weird, anyhow I hope Melexis comes out with better documentation about this great product or someone finds a way around this.
the ADC on·board the sensor·has 11 bit resolution, and the sensor I used here is the MLX90609 with 150°/sec resolution.
' {$STAMP BS2}
' {$PBASIC 2.5}
MOSI CON 0
MISO CON 1
SS CON 2
SCLK CON 3
answer VAR Word
main:
HIGH SS
LOW SS
SHIFTOUT MOSI,SCLK,MSBFIRST,[noparse][[/noparse]%10010100\8] 'start ADC and set channel to 0 (GYRO CHANNEL)
HIGH SS
LOW SS
SHIFTOUT MOSI,SCLK,MSBFIRST,[noparse][[/noparse]%10000000\8] 'poll for reading
SHIFTIN MISO,sclk,MSBPRE,[noparse][[/noparse]answer\16] 'save the answer in a variable
HIGH SS
answer=answer & %0000111111111110 'mask answer to extract data from ADC
answer=answer >> 1
DEBUG HOME,DEC answer,11
GOTO main
GOOD LUCK!!!
Pablo
·
Comments