Gyro_L3GD20

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Gyro_L3GD20

Post by Lord Grezington »

Hi Everyone

I am trying to use the Gyro L3GD20 in SPI mode, but it seems I cant re-map the pins even if I try software channel. If I use a standard SPI master it allows me to re-map the pins.

I am using the 18F24Q10

Thanks

Note - I also seem to be having problems compiling when the gyro is added to to the panel, below are the compiling errors

C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC\PIC_CAL_SPI.c:209:1: error: (192) undefined identifier "tris"
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC\PIC_CAL_SPI.c:280:1: error: (192) undefined identifier "tris"
ZDBLSYC BLDC POC V1.0.c:1533:2: error: (192) undefined identifier "FCP_TRIS_Unconnected_Port"
ZDBLSYC BLDC POC V1.0.c:1533:35: error: (192) undefined identifier "FCP_PORT_Unconnected_Port"
ZDBLSYC BLDC POC V1.0.c:1533:64: error: (192) undefined identifier "FCP_LAT_Unconnected_Port"
ZDBLSYC BLDC POC V1.0.c:1533:100: error: (195) expression syntax
ZDBLSYC BLDC POC V1.0.c:1538:2: error: (192) undefined identifier "FCP_TRIS_Unconnected_Port"
ZDBLSYC BLDC POC V1.0.c:1538:35: error: (192) undefined identifier "FCP_PORT_Unconnected_Port"
ZDBLSYC BLDC POC V1.0.c:1538:64: error: (192) undefined identifier "FCP_LAT_Unconnected_Port"
ZDBLSYC BLDC POC V1.0.c:1538:100: error: (195) expression syntax
(908) exit status = 1

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Gyro_L3GD20

Post by Benj »

Hello,

I take it the problem is in Flowcode 8. I think I have now found the cause of this and fixed the problem for you.

The latest component should now be available via the update system.

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

Thanks Ben, again I will update and give it a go

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

Hi Ben

I have the SPI MAster connected to the same pins as the SPI Gyro (MOSI, MISO, CLK) but with different SS for another component. The program compiles fine, but when I test it on hardware the it freezes. When I then set the Gyro to software mode it does not freeze.

Is it possible to use the same SPI channel for two different devices in hardware mode? (with differnet SS)

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Gyro_L3GD20

Post by Benj »

Hello,

Yes this should be possible, maybe try disable the second call to the initialise to avoid initialising the peripheral twice. Maybe we could track if the peripheral is already initialised and automatically stop this from happening to make this process easier.

Just checking your not calling one from inside an interrupt are you as that might explain the lockup?

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

Hi Ben

Thanks for the reply.

If I disable the SPI component compelty, and then try run in hardware the program freezes (the OLED backlight comes on, but shows blank screen). I can get data if I run in software mode. I have attached my program for you to see.

I also seem to be having reading the data from the Gyro, I get data on the bus but nothing seems to be saved into a variable. I have attached a trace of the SPI bus for you to take a look at.

**EDIT - I now seem to be reading data (by taking the DEN pin low), but seems values seem to be random**

Any idea where I am going wrong?

Thanks
Attachments
GYRO V1.3.fcfx
(23.22 KiB) Downloaded 178 times
SPI.jpg
SPI.jpg (116.31 KiB) Viewed 6851 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Gyro_L3GD20

Post by Benj »

Hmm I wonder if the two components have a different SPI mode, there are generally 4 modes involving the state and sequence of clock and the data but generally two of the 4 modes will work on any one slave device.

As for what's causing the lockup if you could find out the specific component macro call that is doing this then I can investigate for you. I don't think it will be the low level SPI code though there is a while loop here in the send function this hopefully shouldn't cause any problems. It could instead be something higher up that isn't getting the value it wants and therefore staying in a loop.

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

Thanks Ben

I will do some tests to see which component is the culprit.

I have attached the latest testing variant of the Gyro test (still in software). When running I seem to be getting some data on Data2, but nothing on Data0 or Data1. Do you think you can take a look and let me know how I can distinguish between data on the various axis?

Thanks
Attachments
GYRO V1.5.fcfx
(24.48 KiB) Downloaded 172 times

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

Hi Ben

Any luck with this? I just need an example of how I can extract say the z-axis data.

Thanks

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

I found the issue with this

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Gyro_L3GD20

Post by Lord Grezington »

Hi Ben

I am modifying this with more boards, and it seems like every Gygo has a different steady state. This was previously OK, but some of these new ones coming in have very high stationary values (above 15000). Is there some way I can easily set the default to 0, or do I need to do this in code to calibrate the stationary offset?

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Gyro_L3GD20

Post by Benj »

Hello,

Might be worth playing with the high pass filter settings for CTRL_REG2 0x21 as if this is on and enabled then I beleive it should remove any static DC values.

Otherwise you may be able to take an initial reading on power on. then subtract this reading from any of the measurements you take.

Or you could apply a software high pass filter to the data to remove any DC values.

If the reading is too high to get sensible values out of it then could the sensor be damaged? e.g. too much shock on their way to you in the post?

Post Reply