STM32 Programming Tutorial for Custom Hardware | SWD, PWM, USB, SPI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so here's the latest batch of pcbs that just derived from jlc pcb and as you can see this looks very similar to the pcb we made together in the tutorial video which you can see on my channel um pretty much the centerpiece is an stm32 microcontroller and stm32f405 with floating point you to be precise and i've added a few more different components to this board just to make it a tiny bit more interesting so we can have a play around with software and actually writing drivers and stuff like that for it um you can see some of the components haven't been soldered on yet because jlc pcb doesn't support throughout components for example and some connectors so i'm gonna have to add those myself which i'll do later but let's talk about what else is actually on this board so we have a usb connector which i'll put on here a power connector and various connectors on the outside as well just to interface with the stm32 microcontroller the power either 5 volts from a usb or up to about 12 volts on this power connector here goes to the buck regulator which sets it down to 3.3 volts which feeds the remaining part of the board uh yeah so we have a high speed external crystal over here and we have the first interesting ship over here this tiny one here is an inertial measurement unit by bosch it's a bmi 088 and it interfaces with stm32 microcontroller via spi so that's an accelerometer and gyroscope in one package here we have a one gigabit size flash memory which also interfaces with the stm32 via spi and up here it's quite hard to see and quite small that's uh it's either bosch bmp 280 barometric pressure sensor or in this case i've used a cheap alternative which is the spl06 but it's the same thing by spi again relays the data pressure data to the mcu other things i've added are this rgb led so red green and blue which i've connected three timer channels on the stm32 so we can control that via or the brightness rather via pwm i've also added a serial wired connector up here and a boot mode select switch and that's pretty much all there is to this board nothing too crazy or fancy but it lets us test out a few different peripherals and see how we can interface them and see how we can actually program this stm32 microcontroller which is going to be the main part of this video but as you can see i just wanted to show you the kind of soldering assembly results from jlc pcb i'm using really tiny components all the smallest ones you see here are 0.402 so it looks looks really neat i think so it came out pretty well yeah um i'll just show you the back side as well there's nothing too crazy in the back side you can see all the vias i've added some some silk screw and some indicators where the ground and positive terminals are and that's pretty much it so very similar to the board we designed together in the tutorial but i've just added some more interesting components i'll put the gerber files and the assembly files in the description and i'll also show you how to order this board so you can essentially play along at home so as you can see here i've added these three components which weren't assembled by glc pcb one of them is the boot mode select switch so i can select between run and boot essentially that just pulls the boot zero pin high or low i've added a serial wire debug connector up here which is a 10 pin 1.27 millimeter pitch connector and i've added this micro usb connector up here that's pretty much all we need we're going to use this essentially to power the board and to relay data kind of like a virtual com port this to program the device and this essentially to put it into run or boot mode so here i am at my desk now and the first thing i typically do when i have a new board and i've just soldered on some additional parts is to make sure i haven't created any shorts or there aren't any shorts from the assembly process and then i apply a voltage to the power pins slowly ramp up the voltage and see if the current drawn is what i would expect the current drone is too high you probably got a short somewhere and so on and then i just make sure all the voltages on the board are what they should be and from that i can then actually connect it to my st link and via usb connector to my computer but before that just make sure all the voltages and currents are in order just to make sure you're not going to fry anything okay so what you need is an st link i've got this i think version two over here with an adapter cable to one of these mini connectors and i also have a micro usb cable which is going to hook into my computer so all you have to do is fit that onto the debug connector and then plug in the micro usb and with any luck things will kind of turn on so i've got this green led here which is kind of my power good led this is for the three volt um buck regulator and the led the rgb led has lit up as well because i've already played around a bit with the firmware but now let's have a look at the computer and see how we can write drivers and the software for this board before we get started let me just show you how to order these boards with jlc pcb including assembly in case you'd like to try these out for yourself at home and just kind of follow along so first thing you need to do is go to my github repository under this link github slash bms67 then click on repositories and it should be here in little brain sm3204 sensorboard and i've put all the things you need here so that's all the gerber files just to get the pcb produced and in the assembly folder the billing materials and the footprint position files and that's what i use to order my boards as well so once you have those you can either clone the repository or just download it go to glc pcb and click on quote now then in the gerber folder in the github repository just upload the raw file so once the board had files have uploaded you can see a little preview here you can also check out the gerber viewer it's a four layer board 55 by 55 millimeters let's just order five for now uh impedance we want impedance control for the usb traces i typically uh with lead free hot air service leveling or enig all of this is fine i've also hidden the order number under the chip so that's why you can click on specify location we want smt assembly we want the top side assembled five parts and i've already added the tooling holes we can agree and click confirm click add builder materials navigate to the assembly folder and upload builder materials same thing for the position files once you're happy with that click next so click on next i've already adjusted the footprint rotations just to make sure everything is kind of correct so you can see some of the parts aren't available just now but i'm sure they'll be available soon and then you can use all the board for this video i'm going to be using the stm32 cube ide development environment which you can download for free off from st's website now there's loads of different development environments you could use for example embed all those these id's such as keel and a to atollic i prefer this because everything's really nice and integrated all the pin outs are there a lot of the low level drivers are already written that's what i typically go for and i'll also be using c in this video you could also use c plus but for my needs c is all i need and that's essentially down to your personal choice there's also a thing with stm32 called the hardware abstraction layer or hell for short and that's kind of st's help to write a lot of the low-level drivers and low-level interfaces instead of you having to mess around with registers and so on on the chip you can use this how now the hell is it often times kind of bloaty in terms of code it adds and a lot of times you can it can also be quite buggy so just be careful when using the hardware abstraction layer and but for something as simple as this and just testing the board and making sure things work this is completely fine so without further ado let's get started with stm32 cube so here we are on stm32 cube ide and the first thing you want to do is start a new project so click on file new stm32 project this will initialize this target selector and this is where you type in essentially what board or what ship you're going to be using so you either use one of these development boards or discovery boards but what we'll be doing for our custom board is typing in the mcu number so it's an stm32f405rg this will appear in this list down here you can check that's the right package and the right chip then select it and click next now we need to enter a project name so i'm just going to be calling it little brain firmware uh you can put in a different location if you want i'm going to be using c and you can all leave this as it is click next you can choose which firmware package you're going to be using for the hardware extraction layer but always just use the latest one i would say click on finish and it'll start creating some code the next thing we need to do is actually do the pin assignment for this chip so this pin out view will open and this will enable us to choose peripherals and select pin outs for the chip so we can either click on the individual pins and see what functions they may have or we can use this toolbar on the left so the first thing we need to enable is the debug so we're going to be using serial wire debug so click on system call cis debug and we want serial wire but we also want uh the swo trace which is then you have to click here so swo means we can do printf f5 the debugger for example so click on that and you can see in the right view here it's actually enabled the data pin the clock pin and the serial wire trace next thing we want is the external high speed crystal and that's under rcc high speed crystal and click crystal chromatic resonator and this will enable these two pins over here so that's pretty much all the essentials which i always start with so the high speed crystal and the zero wire debug the next thing we need to do is actually enable the peripherals and that depends on of course the board as well so we might want spi we might want a couple of timers we want usb and so on the way i typically do that is i will have my project in keycard which will also be in the github repository and here you can see the pin out for for for my hardware so we've already added the crystal we've added some of the serial wire debug stuff but now we need to add the connections to the different peripherals and we'll just be testing for example the inertial measurement unit which is an sbi we'll be testing the usb and we'll be testing the rgb led for this video which are these three timer channels so all you have to do is transfer what you need over to stm32 cube ide so let's do that quickly so the first thing i need is a usb and i'm using usb full speed it's going to be a device only and this will enable pins pa 11 and pa 12. so the data plus and data minus okay the next thing we need is the spi-1 which is somewhere down here so we want a full duplex master because we want to be able to receive and transmit at the same time and these pins are enabled so you can either use a hardware chip select signal as an output if it's a master or just assign gpi outputs and just do the chip select in software and that's what we're going to be able they're doing so we have two chip selects because we have an accelerometer and a gyroscope pa4 i just click on it and select gpio output pc4 i select and click gpio output if you right click on one of these you can enter a user label that's kind of useful so i want to call it accelerometer underscore chip select actually it should be ncs because it's inverted logic and for pc4 this is the gyroscope chip select okay so we've set up the crystal we set up the debug we set up usb and we've set up spi i would also like uh three timers because we're going to be using timers to control the rgb led intensity via pwm and i believe my timers should be up here so i have time three channel one timer three channel two and timer four channel one so this is the rgb channels for my led as you can see they're yellow we should always enable them over here so go to timer time of three we want to choose the clock source as internal clock channel one we want pwm generation channel two we also want pdm pwm generation let's do something similar for time before which is this third one here we select the internal clock and we choose channel one is pwm generation now this is pretty much it so far there are some things you have to change for example we want to select the pwm frequency we want to select the board rate for the sbi but before we can do that you might notice up here i have this little cross and this means that there's some error or problem with the clock configuration so let's click on that it'll tell you to if you want to run automatic clock solver we don't want to do that just yet because we have to change some values so first thing we want to do is i've chosen a 16 megahertz crystal so i will type that in here 16 as my pll source i want to use the high speed external crystal not the internal one then i also want to run my system at the maximum clock frequency which uh stm32q by d tells me is at 168 megahertz so i type that in now i want to run the automatic clock issue solver to make sure all these pll values are correct so just click enter click ok it'll try and figure out a solution and it has so we have no more cross up here everything looks fine we've chosen our 16 megahertz high speed external crystal and we've chosen the maximum system frequency and sm32 cube id has set up all of our clocks and routing for us which is really nice so we can go back to pin out and configuration and now we can actually um set up the baud rate and stuff like that one thing i would also like to do for the usb part is i want to be using this to relay data back to the host computer so i want to have essentially a virtual communications port luckily there's a drive with that for st already if you go down here middleware usb device and choose a class so you could have for example an audio class if you want a mass storage class some sort of human interface but what we want is this communication device class virtual comport click on that and that makes sure when we create the remaining files for this project we include the drivers for that as well okay so let's look at the spi to change the board rate you can always see down here we have these various tabs if we want to use dma and so on but for now we just want to look at the parameter settings you can choose the frame format data size if we want msp or lsb first but what's interesting at the moment is we want to change the board rate as you can see the baud rate right now with these clock configurations is at 42 megabits per second and that's rather too fast we want something at max maybe 12 megabits for the most cases so the way you do that is change the prescaler and let's set that maybe to eight for now and you can see that has now changed the baud rate to 10.5 megabits per second and that's that's plenty fast for our purposes a bit more complicated now is the setup for the timers all right we want to generate pwm which then drives the led so let's look at timer three and we'll copy those settings then to timer four the important things for pwm are effectively the prescaler and the counter period now we want to we have some sort of input clock frequency we want to scale that down using the prescaler and then the counter period to give us essentially 100 hertz the question is what is the source clock frequency which one of these is the source clock frequency and again look at the data sheet this is the stm32f405 datasheet and section 2.2 we can see down here timer 3 and timer 4 are connected to the apb-1 bus go back to cube ide apb-1 bus is over here and normally running at 42 megahertz but the timers are connected or rather doubled at 84 megahertz okay so from the datasheet we can see what the timers are connected to so we want to scale down 84 megahertz down to 100 hertz the way you can do that is 84 times 10 to the 6 divided by 8400 gives us 10 000 10 000 divided by 100 gives us 10 hertz okay so we scale down 84 megahertz to 10 000 to 100 hertz okay um we also need to subtract one from both of these because some small quirk that actually these pre-scale and counter period values will be added one two later so always i either do it explicitly by just subtracting one or just write a 399 and 99. okay and we need to do the same settings for time before because it's on the same bus so we do 8400 and 100 and all the remaining settings here i believe are pretty much fine we're not doing anything flashy just pwm running at 100 hats with a counter period of a hundred okay i think that's pretty much it we set up the timers we set up the debug we set up the usb with the communications device class we set up the spi the baud rate the software chip select signals and the high speed external crystal and that's pretty much it all that's left to do is now click on save you click on save stm32 cube ide will generate all of the low level drivers for you which is really nice so once it's finished go to the core folder source folder and click on main.c and you can see here all of these things have been created so it's created all the handles for the spi for the timer it's created initialization functions and our main function block right so basically you could start and just write code in here and everything would kind of work okay but let's look at the rgb led first so i've cleaned up the code a tiny bit i've just removed all the comments from st now they have a purpose because st will tell you where you can put your own code without it being deleted every time you make a change in this file but for now i've just cleaned it up just to make sure we can see things a bit easier so we're going to start off with the rgb led and for that let's just have a look in keycard again how it's hooked up so you can see this is the rgb package in the schematic and it's actually hooked up to 3.3 volts and the gpi oh outputs are essentially syncs so when the outputs are low uh the led will turn on and when outputs are high the led will turn off so it's kind of inverted pwm let's just call it so let's just keep that in mind okay but the first thing we need to do is before we go to the while loop is actually start the pwm timers so we can do that by using a hardware abstraction layer and there's a function called howell tim pwm start we then need to pass it essentially which instance or which time you want to use in this case we want to use the first channel of h timer 3. so we then type in we want to start the first channel and we would do that the same thing for timer 3 channel 2 and then time of four channel one okay the way we then set the intensity is by modifying a property of the struct htm3 and we'll do that in the in the main while loop but let's essentially just make a program that then increases the intended c until it hits the maximum and then resets so for that let's create an 8-bit unsight integer called intensity and start it off at zero then in the while loop let's say we want to set the intensity so whatever this variable holds we want to set the intensity or the pwm duty cycle of the output the way we do that is we access the struct and essentially want uh to access this register ccr1 and that'll then essentially set the the counter period for how long it is on and that in turn will be our duty cycle because we had set 100 hertz the counter period is 100 so that'll be our duty cycle remember we could just say it's equal to intensity but i said before it's essentially inverted so we want to invert that by saying it's a hundred so the maximum duty cycle minus intensity then every loop iteration we want to increase the intensity and if the intensity is essentially above the maximum value we want to reset it right because we can run from zero to 100 but as soon as it's above 100 meter we set the intensity because it's wrong value now if we just were to run this we wouldn't be able to see a difference because this is running essentially the maximum speed this while loop can execute so the delay function with the hardware extraction layer is called how underscore delay and that's in milliseconds so let's say we want 100 milliseconds delay between each change right so to start we started the timer in pwm mode we're using a variable to store the intensity and in the main while loop we're setting the intensity using registers right and just making sure the intensity is in valid ranges and then setting delay so let's check if this code is correct we can use that using the build this little hammer up here and we see aha zero errors are warnings perfect so the next thing we want to do is actually debug and send it to our microcontroller so i've hooked everything up with zero wire debug and i've got power to the board then i can click this bug icon and then we need to create a debug configuration and pretty much the default settings are fine the interesting settings are in this debugger tab here you can choose if you want to connect a particular st link what type of server you want to create how you want to connect to it if it's under hardware reset software reset if you want to enable the trace output but for now let's just keep everything as it is and just click ok you can see it's going to start the launch it's going to connect to the debugger down here you can see uh-huh it's recognized the device let me just scroll up again it's recognized the device it's of this family it tells you what flash size it is and so on so it looks like everything's working well on a board and it's connected it's uploaded the memory and now it's ready to run by default it always puts a break point at the first line of main so right now it's poor so you can see here so to start the program we click on resume and now i can see i'll show you in a second i'll switch the camera and now the led the red led is going and increasing your brightness so let me just show you that now so as you can see the red led is going from zero intensity to maximum intensity and you can see that st probe is doing its thing as well so that seems to be working i've added these two functions to the main c file just to clean things up a tiny bit ideally you would put these all in separate c and dot h files and make this into a proper little little project but for our purposes we just want to test the board so i've made two rgb led functions one is to initialize so we had the the timer start functions and i'm doing that for timer three channel one and channel two as well as for timer for channel one right so we don't have to always uh just write that in the main file and then i just call this this function led rgb in it and that'll then call all that the second function is just to set the intensity of the red green and blue channels so i pass red green and blue as arguments and then i just set the registers so ccr1 is for the first channel and ccr2 is for the second channel of the relevant timer instance yeah so it's pretty simple just clean it up a tiny bit and then i can just call the set intensity function and for now i've just let it all be equal so now i have essentially white light because all the intensities are equal okay so let's move on to the next thing which will be usb so i've cleared up some of this led rgb code over here in this while loop um just so we can focus on usb for now remember in this in the pin out file we already configured usb and we also added the drivers for the cdc virtual com port and we're going to be using this virtual com port to relay data back to the host computer so we can look at it our h term so some or putty or any program you use or for later if you want to develop your own applications you can just log and debug data so it's already included usbdevice.h but we also need to include another file which i find rather strange that doesn't auto include automatically so this is one of the files that's already available and linked in the system so it's usb underscore cdc on a school i f and this is needed for a particular function we're going to use to transmit essentially a string of characters okay so we have that included that's important now let's just create for example a buffer a character buffer where we can send i know let's say numbers running from one to one hundred so i'm just going to give it some ample space i don't know how many eight is probably far too much far too many characters but just a buffer that can store the information want to send i also just put in um a counter counting essentially from i say let's say 100 so we started counted one now in the main while loop so on every iteration we want to essentially set the transmit buffer characters so i use espringer for that that's probably elegant ways but it's really simple to do that way and in the buffer i would like to put an unsigned integer so percent u and the carriage return new line and in that untimed integer i want to put count so this is standard c syntax right uh sprint f i can fill this into the buffer with the variables here that's all i'm doing so i'm filling the character buffer which will then transmit my usb and i'm incrementing the count i'm also checking the count if it's larger than 100 i would like to reset it back to one okay now comes the important part so now we want to transmit whatever's in this trans tx buffer via um the virtual comport and the command for that is or the function rather the cdc underscore transmit underscore fs so for full speed now it's its character which is pretty much almost equivalent to un8 but we still need to cast it otherwise um uh stm32qid will complain so we can't set to a pointer of viewing eight to type and i'm just going to use the stringling command just to tell this function how many characters you want to transmit so there's a really simple function this is the name we want to transmit a character buffer or array of this length and that's all we need to do and so uh then we just wait um ten a 10th of a second and transmit it so click on build with any luck this should compile and then we can pretty much just so you can either click on debug and then step through the program or if you just want to have it run immediately you can click on this run button without any debugging so let's do that now okay so it's connected to the serial eye debug it's gonna start uploading now okay apps upload and it's done as you can see there's no pause button because it's just running on the microcontroller now so if i go to my device manager you can see it's now enumerated in my ports list so it's enumerated as a stm virtual comport and it's on a com5 so let's see what happens if we now try and connect to that so i'm using h term i'm choosing my port com5 and the baud rate doesn't matter this is now usb it isn't uart or anything so just click connect and you see we get this arrow down here and it says it can't connect the problem with uh stm32 or with uploading code which has to do with usb is the enumeration and the way you can just get around that is by unplugging plugging in the usb cable and then it should work so let me just do that so i'm unplugging it now and i'm plugging it back in let's give it a couple seconds and i can click connect and as you can see here the number's now being listed all right so it'll go through past the 100 or at 100 and then look back around so exactly the code we have here and this is going by the usb cable so that's pretty neat okay and of course you can make this maybe probably quite a bit neater right you could try and root printf to do this so you don't have to do all this sprint f stuff or you can make something that checks if bytes are being still being transmitted to usb and make sure that you're not transmitting when it's already transmitting something and so on so but this is just the idea that it's that is actually fairly straightforward to implement a usb communications protocol okay so the next thing is well let's implement the driver for the spi device or one of the spi devices and that is the bmi 088 so the driver we'll be writing is for the bmi 088 which is a three axis gyroscope and three axis accelerometer in one single package and we can either interface via sbi or i squared c and i've chosen spi so we're going to write a really really simple spi driver just so you can see how you might approach this and it's going to be polling so nothing like dma or with interrupts really the really simplest and in effect kind of worst type of driver you could write spi because polling mode essentially takes away from your processing power from this from the mcu but it's it's the quickest way to test the driver you don't have to worry about dmas any sort of buffers or anything it's really simple to test and that's what this whole purpose is this video is to test drivers and test this board okay so when we're writing device drivers we always want to look at the data sheet and this is a fairly long 50 page data sheet but it tells us everything about what registers there are how we can read from registers how we can set up interrupts how we can set parameters of this and how the protocol generally works what kind of bytes it expects and how we read and write to it so section 6.1 of the bmi o8a datasheet details the serial peripheral interface or spi that's what we're going to be using so there's a lot to read through but in essence both accelerometer and gyroscope share the same main spi pins so mostly miso and sck so the clock but they each have different chip select bits and that's how you interface with the sensors and the interfacing with each of these parts accelerant and gyroscope is slightly different and well we can read that over here in six one one and six one two i believe yeah so for the for the gyroscope part this is effectively telling us how we read and write so we send one byte that's the address and depending if the first bit also the most significant bit is either zero one we either write or when it's a 1 we read all right so we send the register address with either 1 or 0 in the most significant bit that tells it to read or write and after that the device then sends us the contents of that register or we write the contents of that register so really simple the accelerometers is similar but after the first address byte the accelerometer sends a dummy a dummy byte and then only the true data all right so when in read mode these bits contain unpredictable values so it sends a dummy byte and then it sends the true data so this is a kind of a three byte cycle for the accelerometer and there's a two byte cycle for the gyroscope we'll see how to implement that so i've written a very simple gyroscope read function and very simple gyroscope write function and they either write or read to or from the register one byte okay so let's briefly go over how they work they take one of the arguments they take as the register address so what from which register do we want to read and here we take a pointer to where we want to store the contents of that register this function either returns a zero if the read failed or one if the read succeeded okay now from the data sheet we saw that we have to to read a byte we have to send the register address and we have to flip the most significant bit to a one and this is how we do it so we or the address of the register with the bitmask of one followed by seven zeros which in hexadecimal is 80. okay you'll see in a second why we need to send a second byte but this is pretty much just taken from the register now with the generic spi read or write you can also find this in the register we want to pull the ship select line low this is how we do it with this command so there's the hell gpio right pin and we say which bank it is uh what the pin name is and we say we want to put it low then we do our transaction which we'll look at in just a second and then we pull the chip select line high again okay so our transaction is how spi transmit receive and we can only do this because we're using a full duplex spi so we can transmit and receive at the same time which will save time overall the problem is we now need to send two bytes of data we first will send um the register address with the most significant bit flipped to one and then we need to send a byte of dummy data we need to send a data dummy data otherwise this uh transaction won't work and there won't be anything read so while we read we also have to write and vice versa okay the most significant part or the most important part is here and then we just send a bit of dummy data so actually the register contents will then be in the second byte of this rx buffer okay so we pass the handle which is hspi-1 which you can see up here so we've passed which api do you want to use we say the transmit buffer the receive butter and how many bytes of data you want to use and what timeout we want to have okay and this function will return hello k if the transaction succeeded or how busy or how error if it didn't work and then we indicate this by the status bit which we then return so if the status is zero then it didn't work if the status at one is one it doesn't work so after this hopefully it went well we then um put the data of the buffer the second byte into um this memory location here and this is then will be the register contents yeah so it's actually pretty straightforward essentially pull the chip select low do the transaction transmit receive and then pull the chip select high and return the data the write function down here functions very similar because it's a right function we actually don't need to flip the most significant bit all right that can be that can be zero but then the second byte we want to write is actually the data so we have address and then we send the data so what register we want to write to and what do we want to put into that register then it's the same thing again all the chipset low this time we're using transmit and then we're pulling a chipset high again so really really easy and we can do something similar for the accelerometer but now let's just test this to see if we can read some data from the gyroscope so if we take another look at the data sheet we can see on this page in section 5.4 we actually have the register map the register map tells us what address a certain register has what the name is and what that register also contains so something which is really useful to always do is just for example a read the chip id so if you read the register at address zero that chip id should be oxo f let's try and read that so let's go back to cube id and let's just i know just read it in a loop let's just say so we need some place to store the results because we're going to be passing this uh by reference and then we want to call our the function we just wrote so that's gyrate eight the register address is zero that's the chip id address and we want to pass that by reference okay so we can save that just build and then we'll actually have a look at the contents of this register um by doing some break points and using the debugger so we click on debug then to launch it and upload it upload the firmware to the stm32 okay just wait until that loads there we go okay of course we have the first breakpoint here we want what we want to do is just set a breakpoint directly after the read operation so double click on the left side here and that sets a breakpoint and then we can just click resume okay and we can see on the right here the variable data which is this one here or we can have on top of it has the value 15 and the value of 15 in decimal is oxf or rather oxof and x which is exactly what it should be right so the gyro chip id is oxoff and we see that using the debugger so we didn't even have to print this via usb or something okay so that's pretty much it now of course we have to package this and make this into actually a proper nice driver package where that would be too long for this video but i'll attach to the code in the git repo so basically but this is the basis if you want to do a gyroscope read the gyroscope right we need these functions and everything is in the datasheet we do the same for accelerometer we figure out what settings we want for this gyroscope and accelerometer and then we put that in a neat little header file and a dot c file so as a final test i've kind of put everything together and refined some of the drivers a tiny bit you see i've written a header file and actual proper drive for the vmi 088 i've also added callbacks because the bmi 088 has interrupts whenever there's data ready and so whenever there's data ready i'm just going to read the accelerometer or read the gyroscope and i've added the led i've added the usb logging and so on just to combine everything we've looked at in this video so i'm just going to be printing all the accelerometer data or the gyroscope data to usb i'm going to be changing the rgb led colors and essentially reading from the gyroscope and just initializing and setting it up and all this will be available in the git repo for you to check out okay so let's just take a look at that with a different camera when i move the board how the values change and then that's pretty much it for this video so the program's been loaded onto this micro controller onto the board you can see the led is flashing away doing its job i don't have the debugger connected anymore i've got uh the boot mode switch in run mode so boot zero is pulled low and i've got just this usb cable providing power and it's connected to my main computer over here so as you can see in the device manager it is enumerated as com5 and let's see if that actually logs the data so here in h term i'm connecting com five so as you can see every pretty much half a second we have data being logged so if the accelerometer values so xyz so y z should be about 9.81 which it is if i move the board around so if i just rotate the board the values will change so i've put it on its side now the x component is 9.81 but on the other side it's minus 9.81 and yeah so the gyroscopes are the three values on the right and you can see as i'm as i'm rotating the board around those values change as well so that pretty much brings us to the end of this video we saw how to actually interface with our custom little board how to program this stm32 microcontroller setup peripherals such as the high speed external crystal and so on how to trigger a pwm rgb led how to talk to some spi interfaces and so forth and also of course connect to usb and then print stuff over usb so i hope you thought this video is useful if you did please leave a like hit subscribe if you haven't already and let me know if you have any comments if you would like to see something future video maybe some more programming tutorials but yeah but thank you for watching and until next time
Info
Channel: Phil’s Lab
Views: 123,253
Rating: 4.9687028 out of 5
Keywords:
Id: x_5rYfAyqq0
Channel Id: undefined
Length: 39min 58sec (2398 seconds)
Published: Sun Oct 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.