1327 views|0 replies

1662

Posts

0

Resources
The OP
 

MSP430IO Driver [Copy link]

What we are involved in is the use of GPIO. You may have some impression of the demonstration of lighting an LED we talked about last time. But last time we directly called the code generated by the sample provided by CSS, not by our own written code. Here we also need to remind you that there are many development boards on the market that always come with their supporting codes when they are sold, and the codes can be used after testing. But in this way, we often say that we can compile his code, download it, and then skip this part if it can be used. It is equivalent to learning it, but it is not like this. Only when you do it yourself will you find out how many details and how many mistakes you have missed. This is a good learning process. But I can't tell you the specific method. There are also many people who do projects after learning the microcontroller. This is also the best way to test whether you have learned this microcontroller.
We will also add specific cases later. You can collect the specific cases to see what you want to do with 430. In addition, the FR5969 development board given by TI here has relatively few peripherals. We will also make some peripheral modules by drawing the board ourselves, and then open it to everyone.
Without further ado, let's get started!
The first step is to select a workspace. I'd like to mention here that CSS is developed based on Eclipse, so everyone will be shocked by the power of Eclipse. It can develop STM32, Freescale, Java applications, Android, etc.

Click
OK and enter the homepage.
Select New Project to create a project. We have already talked about the specific method last time, so I will not repeat it here.


There are two differences here. One is that the location of our project storage has changed to facilitate our management, and the other is the engineer Empty Project (with main.c) we created.

Click Finish to complete the project creation.


Get the code here. There is a line of code in main.c. Let's explain what it is.
Through the English comments at the end, we know that this is to stop the watchdog clock, which leads to several questions. What is a watchdog and why should it be disabled?
Learning is the process of asking questions! It is recommended that you have your own notebook to write down these knowledge points. It will be better to develop this habit. This is just a suggestion. It depends on your personal learning method.
Here we need to use the information we shared with you in the first lecture!
Here we will take a look at what these documents are.
1. MSP-EXP430FR5969 LaunchPad Development Kit Quick Start Guide.pdf
This is the promotional page when we got the board. It explains the characteristics of the board, as well as some management definitions in the board.
2. MSP430FR5969 LaunchPad Development Kit (MSP-EXP430FR5969) User's Guide.pdf
This document is an overall introduction to the FR5969 board we use, including some hardware structures and related schematics. If we need to modify the hardware later, we can find reference information here.
3. MSP430FR59xx Mixed Signal Microcontroller.pdf
This is the data sheet of our device, in which some related internal designs and related design resources are explained in this document.
4. MSP430FR58xx, MSP430FR59xx, MSP430FR68xx, and MSP430FR69xx Family User's Guide.pdf
This document is the document we will use more frequently in the future. We will find the relevant register definitions and the like here.
5. MSP430 Hardware Tools User's Guide.pdf
430 Hardware Tools User's Guide, etc. These reference documents can be found on the official website, so how do we use them? Don't worry too much. At first, you may not understand why the register is like this. You will understand it as you study more. Now that
we know the relevant content of the reference material, let's see how to use it. You must also pay attention that many materials are in English. Of course, it is better to find Chinese, but it will also help you develop a habit of reading English materials. See the
first line of code:


Here we understand what a watchdog is. Its full name is Watch Dog Timer. It is a very important on-chip peripheral of a microcontroller. So what is it used for? (Here is an explanation of the meaning of peripherals. In fact, a microcontroller is made up of a core and some peripherals. The core is probably the arithmetic unit and the controller. The language may not be very reasonable, but everyone should understand the basic structure.) To put it simply, it is a timer. The concept of a timer is the same as that of an alarm clock. When the time comes, we should get up. The same is true for a microcontroller. When the time comes, we should do other things. However, the watchdog "timer" is different from other timers in that when the time comes, the system will be reset. Therefore, we can use this feature to monitor the system, set some related flags to detect whether the system is working properly, and clear its count value within the watchdog set time, otherwise it will be cleared when it reaches the count time. At the same time, if the system flag is abnormal, we can also set it to reset.
Then let's take a look at why these three English words are used and what they represent.


We open the file, MSP430FR58xx, MSP430FR59xx, MSP430FR68xx, and MSP430FR69xx Family User's Guide.pdf
and find the label


This document will give the internal structure of the watchdog and related introduction. We will not go into details here for the time being. Let's first see how to use and configure it here.


The red box in the figure shows the register block diagram of the watchdog timer. Here, the definition of each bit is also given. It can be seen that the watchdog configuration is configured by a 16-bit register. At the same time, the document gives an introduction to each bit, giving their functions and usage.
We want to turn off the watchdog here. According to the following description, we need to enter the watchdog "password" because the watchdog register is locked. You can find its description in the document, which is the red part below.


So if we want to modify the watchdog, we first need to enter the "password" before we can configure it.
So our first line of code is:
WDTCTL = WDTPW; //Here is the code for "unlocking"
Okay, now we can modify the value inside. From the table above, we can see that the WDTHOLD bit is used to turn it off. So our next line is:
WDTCTL = WDTHOLD; //Turn off the watchdog.
So we have completed the first line of code.
But why is there a "+" sign here? This is a binary operation, we will not explain it here. If you are interested, you can right-click the definition name to find its hexadecimal number, and then calculate it to understand. Here we demonstrate an example, I hope you can explore it yourself next time.


Double-click the definition name, right-click the red box, and jump to the bottom.


Here are some macro definitions of some registers inside the 430. These definitions help us to develop better. If you use all the hexadecimal codes on the right, you may be happy at the beginning, but you will be discouraged after two days of using 430.
Okay, so that our 430 will not reset automatically. Next, we need to control the IO port. First, let's understand what we need to do to control an IO port? The first step is to configure the IO function, including setting it as a basic IO, not a multiplexing function such as IIC or UART. Now you may not understand this, but you can understand it first. The second step is to set the basic input and output, and then the application of IO. This is probably the process. It is basically similar to other microcontrollers. Some also need to configure the clock, etc. This will be seen when you apply other microcontrollers yourself. Here we explain the use of 430 IO. Return to
the PDF document we just opened.


Open Chapter 10, there is such a sequence in I/O Configuration.


(All in English, so English is very important, learn it well)
Translated
1. The first step is to initialize the IO port and configure the relevant registers, including PxDIR, PxREN, PxOUT, and PxIES.
We explain these four registers here:
(1) PxDIR Direction setting register
(2) PxREN Pull-up or pull-down resistor enable register
Explanation of pull-up and pull-down resistors:
Pull-up is to clamp an uncertain signal at a high level through a resistor, and the resistor also acts as a current limiter. Pull-down is similar, and it also clamps an uncertain signal at a low level through a resistor. It may take a long time to explain here, so you can go and look it up specifically, which is relatively easy to understand. For pull-up, the resistor connects the signal line to VCC, and for pull-down, the resistor connects to GND.


(3) PxOUT Set the output register, you can set the output high or low here
(4) PxIES Set the interrupt edge selection register, which can be set to rising edge or falling edge trigger
2. Clear LOCKLPM5.
You need to turn off the LPM5 mode. This is one of the low power modes of FR5969. We will not explain this here for the time being. Here we only need to understand that if this mode is not turned off, our settings for the IO port will be invalid.
3. If you do not wake up from LPMx.5, we need to clear PxIFGs here to avoid erroneous port interrupts.
4. Enable port interrupts, the register is PxIE.
OK, now we should understand how to write it.
Let's turn off LPM5 first.


In chapter 2.3.4 we find the register description of PM5CTL0. The red border shows that this bit needs to be unlocked to set the port. So the code is as follows:
PM5CTL0 &= ~LOCKLPM5;
Here we see the use of & and ~ symbols, why is this? From the register description we see that the LOCKLPM5 bit needs to be set to 0, right click to find the value defined for LOCKLPM5:


After inversion, it is 0x111E (binary number is 1111_1111_1111_1110) and then bitwise AND with PM5CTL0.
What is the benefit of this? This ensures that other bits do not change. For example:
(PM5CTL0 = 1110 1101 0110 1101) & 1111 1111 1111 1110 =
1110 1101 0110 1100;
it can be clearly seen that other bits do not change, only one bit is changed!
Next we need to set the port:
MSP430FR5969 LaunchPad Development Kit (MSP-EXP430FR5969) User's Guide.pdfYou
need to open this file, find the schematic, and find the following figure on the last few pages of the file:


We can see that LED2 is connected to P1.0. Here we need to set P1.0 to output and output high level at the same time, and then change to low level after a delay.
Step 1: Set the port to output.
P1DIR |= 0x01; The use of "|" here is the same as the above inverted and does not change the original data of other bits.
Step 2: Set the high and low levels of the output. Finally, we get the following code.
Here is a little trick:
open the preference under the windows menu in CCS


Follow steps 1.2.3 to set up the code auto-completion function.


Okay, compile and download it, and we can see the light flashing.

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list