#4 ARM Microcontroller Tutorial - USART Communication Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the next set of videos i'm going to be describing and teaching you how to use the communication protocol called use art also called uart usart is universal synchronous asynchronous receive transmit this is a communication protocol that allows two devices to communicate using a transmit and receive the devices that can be used for use art have to be devices that have the ability to communicate using the usart communication protocol the devices that i'll be using in this next set of videos is the arm microcontroller the stm32 and a servo by dynamixel the ax-12 plus or the ax-18a both of these have the capability to communicate using usart usart is also one of the most flexible ways to communicate between two devices you can communicate with either one or two lines between them so you can have the transmit and receive on a single line which is called half duplex which is the way this one works because you can see that there's a power ground and a communication wire that's it there are two connectors here so you can have multiple devices working at the same time connected to this a single microcontroller like this you don't have this kind of flexibility with a lot of other communication protocols for instance if you wanted to communicate using the i squared c you have to use two lines one for clock which is the sda like this accelerometer uses and scl you still have to use the lines for power so you still have to power the board with two lines and you also have to have two other lines for the clock and the data another form of communication is spi which you also have to use two lines miso and mosi master enslave out master out slave in so if you wanted to let's say have two microcontrollers communicate you could use the spi communications protocol and have these two devices communicate with spi communications you have three lines you have a clock line you have a master enslave out and a master out slave in and the clock allows you to synchronize the communication between the two devices with uart both devices agree on a single speed so when you transmit from one and then receive from the other the transmission will be at a specific speed that both of them will be transmitting and receiving imagine i am a microcontroller and i am set to a baud rate of 9600 bob imagine i am another microcontroller and i am set to a baud rate of 57600 baud that microcontroller probably won't be able to understand me so it's really important to set the communication speed on both devices to the same speed or baud rate the actual data that is transmitted from one device to the other is in the form of a data frame the data frame starts with a start bit that informs the destination device that the communication has started and then a set number of bits to form a byte or a word you can think of a byte as say a letter in the alphabet a parity bit which checks to make sure that the the data in the data frame is going to be correct the stop bit just like the communication speed needs to be the same on both devices the data frame specifications must also be the same on both devices meaning there's always going to be a start bit there's always going to be a stop bit there's always going to be a parity bit or not on both devices and there's always going to be the same number of bits in each data frame and we'll get more into the specifics of that when we start programming so we've gone over the items that you need to know to configure use art that is both devices have to be set for the communication for speed for the if you're going to have parity or not and the number of bits for in the data frame you're going to find that usart is a really easy communication protocol because all you're going to be doing is you're going to be is you're going to be putting your character or whatever you want to communicate into a shift register it's like a little buffer and what it does is it it sends that character out onto the transmit line and then simply wait for the mock controller to tell you that it has been transmitted you can do this over and over for as many characters that you want to transmit for the receiving when you want to receive information from another device you're going to be waiting for something to appear in a another buffer for a receiving and then once the microcontroller tells you that something is in the buffer you can take it and use it however you need to so let's talk about the hardware for a moment we need to find the pin that's used for the usart so let's go to newbiehack.com and take a look at the the map of all the pins you can just click on this big banner here and you'll see the actual board here that it'll light up the pin when you hover over it so you know which pin you're looking at so if you can look at this little circle here this is the number one pin right here so you'll know your orientation it's opposite the skull and you can take a look at the alternate or i'm calling them additional here alternate here look at the alternate or additional functions for the pins and you'll see user 2 so this particular microcontroller has user number two and it also has let's see this is one side of it so let's go to the other side here's usart 1 user 1 user 1 user 1 and user 1 here i'll probably be using the user 1 section over here and we're looking for the tx and rx and it looks like the tx and rx are here so the tx is here and the rx is here and that's 42 and 43. you can also click on these pins here to find out what functions they are so 43 is the rx or receiving and 42 is the tx or the transmit you can also go to the reference manual and there's a link here to the reference manual you can also look up the reference manual for the chip that you're using if you're using a different one you can also look at the ide and take a look at the ioc file let's use this project as an example here the ioc is here the ioc file when you start up a new project you're going to see this first anyway so you can take a look at the pin that you need okay so you'll see that there's pins all the way around here and when you hover over it it tells you the pin number so the ones that we were going to be using is pin number 43 and 42 pa 10 and pa 9 so we can look in there and you can see that you have special functions that you can select so we could do that on here and the where is it oh yeah was it oh yeah it was 42. so the use heart 1tx so you're telling the programming that you're going to be using these two pins we're not going to be doing it this way at first but we we will delve into setting the mic controller up using this file as well the pins that we're going to be using is number 43 and 42 which is located right here and the in this project since i want to use half duplex because i'm going to be using the servo that uses only a single receive and transmit line i'm going to take pins number 42 and 43. and tie them together so i'll be able to transmit and receive on the same line i've never tied these two together the data sheet for the servo says that you need to tie the separate pins through a chip that allows us to shift the receiving and transmitting i still may need to do that but i want to try this experiment anyway just to see if it'll work the schematic they use is using a chip with the part number 74lvc2g241 which is not the easiest chip to find and also they show five volts here so that's something that really concerns me for the rx and tx lines i have to make sure that the rx and tx on the microcontroller are five volt tolerant so i will be able to do that and they also show that it's pull this the rx is pulled up with a 10k resistor and the tx is pulled down with the 10k resistor i want to see if i can um not have to worry about that and only put a 10k resistor pull up on the on both lines as they're showing on this side there are alternate chips that i can use instead of the 74 lvc2 g241 i may just use a a tri-state buffer chip to do the same thing but that will only be investigated after i see if this works or not looking at the data sheet from st micro for this particular controller i can see that the 43 and 42 are 5 volt tolerant the ft means that the pin is 5 volt tolerant you can see on page 28 the descriptions of the i o structure and the tolerances and what is allowed on each pin another consideration we may need to make is that we may need to use a crystal oscillator instead of the internal rc resistor capacitor type of clock that it's used the clock inside the microcontroller is not as accurate as a crystal oscillator i will most likely not have to use a crystal oscillator but when it comes to projects that are very critical it is best to use a crystal oscillator just so you can make sure you can ensure that all of the data going back and forth is always going to be accurate in the next video i'm going to increase the speed of the microcontroller to 48 megahertz and that will be fast enough that i can scale it down and make a very accurate baud rate for the usart also the servo is able to communicate up to one megahertz so one megahertz is easily divisible by 48 megahertz so that should be that shouldn't be a problem getting a good communication speed matched with the servo there's also a really cool feature built into the microcontroller it's called the one bit feature and it is a majority vote feature that evaluates bits being communicated so it evaluates the stream of voltage either zero or one voltage that creates a one bit or voltage that creates a zero bit the one bit feature will evaluate the communication of a zero and a one so a clean signal would be something like this this is a one this is a zero this is a one maybe there's another one here and then it goes back down to zero but the communication may not be as clean it may be kind of messy and then it goes back down goes up stays up goes back down maybe it comes up a little bit so it's kind of messy looking but what the one bit feature does is it divides this up to into three sections and if it looks like this one is a one it will put a one here if it looks like this is a zero because it kind of looks like a zero it'll put a zero there and this one kind of looks like a one so this is a majority vote and one wins this one should be a zero and it looks they all look pretty good so that would be zero zero zero so that would definitely be a zero this one looks like it would be a one a zero and a one that would be a one so we definitely have one zero one and this one looks like it would be a one zero one again so that would be a one and this one looks like it would be a zero zero one which would be still a zero these are majorities and the majority wins if you have a scenario where it's supposed to be zero but it shows two ones then the ones win and that may not be a good a good thing so the microcontroller gives you another feature with the majority vote and it flags the ones that don't have all ones or all zeros so you can use this in your error catching and if you see any of those flags you can re transmit the information or re-receive the information for those of you that have the book since we're going to be working with the clock and increasing the clock we need to pre-scale the clock or divide the clock and use a couple timer functions so if you look at chapter 26 on page 268 you can take a look at some of the information here maybe do this project i'll be going over the prescaler the psc and the arr registers and if you don't have the book don't worry i'll be going over it but it won't be in as great detail as it is in the book you
Info
Channel: BuildYourCNC
Views: 14,539
Rating: undefined out of 5
Keywords: arm microcontroller tutorial, ARM programming and circuit building, arduino, arduino tutorial, USART, UART, Microcontroller Communication, uart communication, embedded systems, embedded systems tutorial for beginners, embedded systems course, embedded systems full course, embedded systems tutorial, embedded systems lectures, uart communication protocol, uart communication arduino, uart communication in stm32, uart communication error, embedded systems c++
Id: lOD4KcQ8mpY
Channel Id: undefined
Length: 15min 30sec (930 seconds)
Published: Fri Feb 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.