STM32F407 Discovery Board Motion Sensor Usage - Page 1
Forum section: electronics / general

author: elefurtronik
author_rank: Regular Contributor
timestamp: June 25, 2023, 09:34:16 pm
content: Hello,I am studying embedded systems with stm32f407 discovery card. There is a motion sensor on the board. I would like to read sensor datas over I2C but I couldn’t find any information in stm documentation about it. How can I use this sensor? Please help. I am studying bare metal programming.

author: langwadt
author_rank: Super Contributor
timestamp: June 25, 2023, 09:41:46 pm
content: you figure out how to use I2C and then you look at the datasheet for the sensor

author: newbrain
author_rank: Super Contributor
timestamp: June 26, 2023, 08:58:38 am
content: Quote from: langwadt on June 25, 2023, 09:41:46 pmAnd that's be the best way to gain an insight of how to manage sensors and I2C in a baremetal environment.That's what I would do - have done - a good learning experience.But I'll spoil the suggestion, though, by letting you know that the Cube FW board support package (BSP) for the STM32F4 Disco supports themotion sensor, sparing (usually) quite a bit of grunt work and bring you closer (and 'closer' here is doing some heavy lifting) to a working project if you are e.g. time constrained.Choose your poison!

author: elefurtronik
author_rank: Regular Contributor
timestamp: June 26, 2023, 05:30:12 pm
content: Hi,As motion sensor is on the discovery board I dont know which pin to read to get motion sensor data.

author: langwadt
author_rank: Super Contributor
timestamp: June 26, 2023, 06:01:40 pm
content: Quote from: elefurtronik on June 26, 2023, 05:30:12 pmso look at the schematic for the discovery board

author: liaifat85
author_rank: Regular Contributor
timestamp: June 26, 2023, 07:32:26 pm
content: There is a youtube video series on Motion Sensing on the STM32L4 IoT Node. But I could not find the same for your STM32F407 discovery board. You can take a look at those videos if they help. You can also post your question to the STM forum.

author: avaqsemi
author_rank: Newbie
timestamp: June 27, 2023, 06:49:19 am
content: To use the motion sensor on the STM32F407 Discovery board over I2C, you need to follow these steps:1. Identify the motion sensor: Find out the specific model of the motion sensor on your STM32F407 Discovery board. This information will help you locate the datasheet and understand its communication protocol.2. Obtain the datasheet: Look for the datasheet of the motion sensor online using its model number. The datasheet will provide you with detailed information about the sensor's registers, communication protocol, and programming instructions.3. Connect the motion sensor: Ensure that the necessary connections are made between the motion sensor and the STM32F407 Discovery board. Typically, I2C requires connecting the sensor's SDA (data line) and SCL (clock line) pins to the corresponding I2C pins on the STM32F407 board.4. Initialize I2C: Set up the I2C peripheral on the STM32F407 Discovery board. Refer to the STM32F407 reference manual and programming examples to learn how to initialize and configure the I2C hardware.5. Read the datasheet: Study the datasheet of the motion sensor to understand its register map, including the addresses of the relevant registers you need to access for reading sensor data.6. Implement I2C communication: Write code to perform I2C communication with the motion sensor. This typically involves sending appropriate commands or requests to read specific registers and receiving the response from the sensor.7. Parse sensor data: Once you receive the sensor data over I2C, you need to parse it according to the specifications provided in the datasheet. The datasheet will explain the format of the data and how to interpret it correctly.8. Integrate with your bare metal application: Incorporate the I2C communication and data parsing code into your bare metal application for the STM32F407 Discovery board. You may need to write functions or drivers specific to the motion sensor to facilitate easier access to the sensor's data.

author: ozcar
author_rank: Frequent Contributor
timestamp: June 27, 2023, 07:08:17 am
content: 9. Conclude that perhaps it would have been easier to use SPI to talk to the sensor, as the board maker intended.

author: wek
author_rank: Frequent Contributor
timestamp: June 27, 2023, 10:06:52 am
content: Quote from: avaqsemi on June 27, 2023, 06:49:19 amWhile formally mostly correct, this sounds an awful lot like ChatGPT."Mostly correct" because 3. speaks of the sensor as if it would be external to the board.JW

author: ArdWar
author_rank: Frequent Contributor
timestamp: June 27, 2023, 10:20:03 am
content: For ST MEMS, you really need to look at the accompanying Application Notes in addition to their Datasheets. The datasheets are very "dry". Most of the walkthrough at how to actually set up the sensors, acquire their data, or even explanation of what the configuration registers actually do are contained in the appnotes instead.

author: peter-h
author_rank: Super Contributor
timestamp: June 27, 2023, 12:54:03 pm
content: QuoteI was thinking exactly the same.The chip is probably LIS3DHhttps://www.mouser.co.uk/datasheet/2/389/lis3dh-1849589.pdfwhich can do I2C or SPI and I would definitely use SPI for it. Much more widely used.It's actually quite a good chip; 0.001g resolution and 0.0005g/degC zero drift. I am toying with building a navigation product but AFAICT (my maths is crap) you need a 3 axis accelerometer and you need three yaw gyros because slowly spinning the accelerometer(s) around their centre will not register anything but will result in a completely bogus direction in space.So one needs to be pretty clear what this is to be used for. The 1G gravity vector is easily detected but you can't detect yaw around the vertical axis.

author: elefurtronik
author_rank: Regular Contributor
timestamp: June 27, 2023, 06:14:29 pm
content: Thanks for all the answers. I actually checked the documentation and couldnt find that which pin the stm connected this sensor on board. Sensor is on board but there is no schematic to see thag which pin is the sensor connected

author: peter-h
author_rank: Super Contributor
timestamp: June 27, 2023, 07:10:46 pm
content: It is probably jumpered. I have the circuits of the 407-DISCO and had a look and could not find it; it may have been on a standalone sheet which I discarded (since my project doesn't use it).

author: langwadt
author_rank: Super Contributor
timestamp: June 27, 2023, 07:53:45 pm
content: Quote from: elefurtronik on June 27, 2023, 06:14:29 pmhttps://www.st.com/en/evaluation-tools/stm32f4discovery.html#cad-resources

author: eutectique
author_rank: Frequent Contributor
timestamp: June 27, 2023, 07:53:49 pm
content: Quote from: elefurtronik on June 27, 2023, 06:14:29 pmClick here:https://www.st.com/content/ccc/resource/technical/layouts_and_diagrams/schematic_pack/group1/0f/91/8b/39/b3/78/4d/c4/MB997-F407VGT6-B02_Schematic/files/MB997-F407VGT6-B02_Schematic.pdf/jcr:content/translations/en.MB997-F407VGT6-B02_Schematic.pdfPage 6, bottom left, U5.SPI1_MOSI -- PA7SPI1_SCK -- PA5etc...

author: ozcar
author_rank: Frequent Contributor
timestamp: June 27, 2023, 08:01:26 pm
content: Quote from: peter-h on June 27, 2023, 12:54:03 pmQuote from: elefurtronik on June 27, 2023, 06:14:29 pmWhen I went looking for a schematic yesterday, this is what I turned up:https://www.st.com/content/ccc/resource/technical/layouts_and_diagrams/schematic_pack/group1/0f/91/8b/39/b3/78/4d/c4/MB997-F407VGT6-B02_Schematic/files/MB997-F407VGT6-B02_Schematic.pdf/jcr:content/translations/en.MB997-F407VGT6-B02_Schematic.pdfIf that is the correct schematic, then it does show the MEMS sensor connections (on the last page).Again, assuming that is the correct schematic, it shows the sensor as a LIS302DL, which supports either I2C or SPI. However, given the MCU pins it is connected to, it seems to me that the intention is for the SPI1 peripheral to be used, hence my addition to the possibly ChatGPT generated narrative above.I did not check what alternate peripheral functions can be mapped to those pins, so I2C may still be possible (or worst case, bit-bang it). But why swim against the tide unless perhaps as a pure learning exercise?