STM32 USART Pt2: Basic UART

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how'd he do the uh alright so now in there I am in this video we're gonna go just over the code and maybe any little details I forgot to mention this video is gonna be just the basic UART will be constantly checking the status register in our code to see if we receive data and all that stuff and then in the next video we're gonna implement the interrupts all right let's see all right let's do it and I am going to be using um truce to do it just in case you're wondering what IDE this is okay so first things first like any peripheral we're going to activate the clocks for both the peripheral itself and whatever port the pins are so the porch for this UART are and I mean the pinch for it on GPIO a so we're gonna enable that clock and we're gonna enable the you what one itself easy enough done that a million times the next thing is the alternate function remapping now by default the pins for UART want are on pin a nine and ten if for some reason there is a need to move those pins to somewhere else because it conflicts with other hardware you can go ahead and do that if you look starting on page 175 of the reference manual it talks about alternate function and remapping if you look if you go down here to page 180 you'll see some of the you are towards ru or one here's our UART one and you see that default the default mapping for them is T X on a nine and rx on a 10 and again if you want to remap it then you would set a certain bit right here on this ur1 remap if you set that bit to one then you're you are TX and rx are going to be on port B obviously at that point then you have to change your your clock the you activated the port that you activated from A to B obviously and that this bit that you have to set is actually in the mapper register of the alternate function block where are we here so you can see here bit bit two is the setting we're looking for we're not really gonna do that but I'm just showing you so here's a bit to UART one remap right so when you put a 0 here you have the regular mapping pin mapping and when you put a 1 you have the alternate mapping should you need that of course right so since we're using just the regular mapping I'm gonna go ahead and set pin a 9 to alternate function push-pull I chose the 50 megahertz slew rate for it for no reason really you could choose anything so as long as it's not input so I did that now pin a which is the rx pin obviously that's an input right because we're not controlling that pin the external circuitry or whoever's transmitting on that line they're the ones are gonna push that pull that pin higher low so that's actually going to be an input floating now that just so happens to be the default state it has to be it's the state at reset so we don't really have to set anything because it's already like that once you turn on your mic controller so we don't have to do anything for the RX pin next we have setting the baud rate in our BRR register and I went over I went over that in the last video of how we derive this this value right here so you can check that out ultimately then we enabled our receiver we enable the transmitter and we enable the whole UART block itself and all of this obviously is in control register 1 now this program user hears I mean a while loop all that's doing is again whatever data we're getting we're sending right back it's just an echo program and what we're doing here is we're checking the status register if this rx any flag is set so we're checking to see if the RX is not if it's not empty it means we've received data then we get our data right restore into this variable temp we get our data from the data register we store it in temp and then we put it back in the data register now remember that the data register what I explained before to us from a programming perspective it seems like we're reading data from a register and then putting it right back it seems I would you know what's the point of that but recall that when you are reading from the data register hardware is kind of pushing you to a different physical place in the microcontroller and when you're writing to it it's going to a different place now these are called shadow registers so it's abstracted from you know from us but in essence when you're reading and writing to what seems to be the same register you really are not so keep that in mind so that's why we're gonna read out our data and then put it right back to where we read it from to transmit it and then obviously when it check the status register for our transmission to be complete and that's about it so I'm gonna go ahead and compile this should be fine no errors and then we're gonna upload it to the board again no errors we're going to hear that clear that we set the board and again whatever I send this is my where I'm sending and this is where I'm receiving so it's almost instant right it's not going to be instant because it's real life here but whatever I'm sending it's transmitting it right back to me and that's really it as far as the code goes for a simple UART communication obviously there's no interrupts now the interrupts version is gonna be the next video and it's easy it's gonna be just as easy as this alright so we'll check that out in the next video again if you have any questions go to the blog everything is more thought-out and written and you can ask questions if maybe I forgot something or I just didn't make any sense on the all right guys all right thanks
Info
Channel: Eddie Amaya
Views: 12,559
Rating: undefined out of 5
Keywords: stm32, stm32f1, stm32f103, stm32f103c8, microcontroller, arduino, programming, tutorial, embedded systems, code, maker, keil
Id: PVTjEloqTx4
Channel Id: undefined
Length: 6min 42sec (402 seconds)
Published: Sun Feb 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.