STM32 Learning Experience (supplement)

Source: Internet
Author: User

2016/3/23

1. Today, the Development Board on the RS232 chip burned out, so the next to complete the use of Stlink, to download the program, but also try to debug the program, is also forced to learn a very useful tool, originally I do not want to learn stlink.

2. First learn the STM32 timer, the process, add stlink download and debugging.

3. Timer: Stm32 High-level timers (TIM1 and TIM8), Universal Timers (TIM2-5), basic Timers (tim6,7).

4. The universal Timer (TIM2-5): 1) is located on the low-speed APB1 bus. 2) Prescaler: Reduce the counter clock frequency. 3) Each general timer is completely independent. 4) Count up: from 0 to load value, other similar. 5) The clock source of the timer can be derived from the internal APB1 clock multiplier, which is one of the clock sources, but the use of more, but also relatively simple.

5. The general timer work process, as long as the impression can be, in the configuration of the time know what to configure.

6. This is the clock calculation method, where APB1 's clock originates from AHB, if APB1 = AHB, that is APB1 = 1 * AHB, then Ck_int = APB1 at this time, and if APB1 = AHB/2, then Ck_int = 2 * A The PB1 clock, which gets the timer's original clock.

7. Overflow time Tout = (ARR + 1) * (psc+1)/TCLK, which is the reciprocal of TCLK/(psc+1), gets the frequency after the original clock is divided, the countdown is the clock period, then multiplied by the reload value, the overflow time is obtained. The general clock TCLK is 72MHz.

8. Now for the battleship Development Board, LED0->PB5 red Led1->pe5 Blue

9. Note: In order to use the corresponding library functions, you need to add the library functions of the. c files to Fwlib, but in the use of template project templates do not consider, have been loaded in, we just write their own function function can be.

10. Timer initialization step: 1) Enable timer clock to APB1. 2) Initialize timer, configure ARR,PSC, and Count mode. 3) Enable timer interrupt, configure Nvic, do not forget to add a set interrupt priority group in the main function of the sentence! 4) enable the timer itself. 5) Write the interrupt service function. The specific parameter configuration is shown in the function function.

11. Note: The level of the flip, as if can use ~ or! Realize.

2016/3/24

1. Before learning the timer PWM wave, first learn how to debug the program Stlink.

2. Stlink Debug: 1) First about pins, pa13-15 and PB3 PB4 are all pins that are default to Jtag, so try not to use these pins in the project. 2) in the Debug window to see the variable changes, you can select the variables in the program, right-click, and then add Towatch1, you can.

3. NOTE: Simulation software simulation and hardware simulation, then the software simulation, there will be serial data output, but the hardware simulation must use the serial debugging software to see the serial printing data, the same, logical analysis is also the case, you can use Logic Analyzer to collect board pins, do logic analysis, Then the use of debug on Keil is to observe the variables, as well as register changes, and you can see the hardware performance by stepping through the debugging. It doesn't seem to be very useful. But Keil's load is really convenient, can go down to the board directly, without my additional use of software download.

4. The timer Pwm:arr value determines the frequency, CCRX determines the duty ratio signal, can be understood as a critical value.

6. About the channel remapping problem: Channel remapping according to, you can see, timer three of the channel two partial remapping can be mapped to the pb5,led lamp output, easy to display. Note: Once the TIM3 is set to partially remap, then four channels are remapped, that is, now ch1->pb4, there is no specific mapping to set CH2 alone.

7. Working process Setup issues with PWM:

8. With respect to PWM mode of operation: The CCMR1 control is PWM pattern 1 or 2. Mode 1, when CNT < CCR, the output of the effective level (whether the effective level is low or high level according to Ccer), the rest is invalid level, then the PWM mode 2 is the opposite of mode 1.

9.7th, where the cc1p is high polarity, then the high level is active.

10.//Set duty ratio, duty-free = (Ccrx/arr) *100% or (tim_pulse/tim_period) *100%

Timocinitstructure.tim_pulse= 400-1; What I understand here is that this value is placed in the capture comparison register, the CCRX, which is used to output a fixed duty ratio of the PWM wave.

2016/3/25

1. Note: Battleship Development Board: 1) Buzzer received PB8, high-level sound. 2) Wk_up-->gpioa.0,key0->pe4,key1->pe3,key2->pe2

2016/3/31

1. About the 6050 gyroscope module problem

2. Start today to balance the car project, Bluetooth module do not care, as long as know can connect, and then judge the serial port to send instructions.

3. It seems relatively simple to use DMP, by combining DMP, we can convert our raw data into four element output, and then calculate Euler angle by four elements, thus obtaining yawroll and pitch.

4. Because it is to balance the car, then do not need roll and yaw, directly through the pitch can.

2016/4/1

1. Yesterday card in a more stupid problem, is that I rarely own configuration projects or something, so when the test sellers sent to the routine, the compilation does not pass, the final discovery is to open under the KEIL4 can be used, the issues involved in the issue I do not want to delve into, after all, the configuration of the project is not the focus of my study.

2. Today summed up an experience: To solve the problem, must be good at using the simplest method! Do not work hard, also can not waste precious time! For example, I found their routines to go in, the car can not move, troubleshooting, is certainly a data problem, I asked the seller, they sent a new information, became! Engineering compile errors, Baidu on the Internet, as if keil4 under normal use, it will be installed a KEIL4, became! This is the simplest way to solve the problem, do not kill themselves, can not turn niu Jiao Jian.

3. MPU6050: The first thing I want to do is to be able to use the routine to print out the data obtained by the MPU, so that it is easy to debug, it is easy for me to learn, and then to understand the 6050 way of working and communication (IIC communication), and then learn 6050 under the DMP method, The output of the data how can be set to the attitude of the car, then the balance of the car in the more critical content is over!

Because it is still written in the project log is relatively clear, so prepare to write the project log, pause writing until the balance Trolley project ends, re-start learning the other modules of the battleship Development Board.

2016/4/18 TFTLCD

1. Today is the balance of the car after the end, began to continue to learn stm32 the first day, the last teacher proposed to do in the mini2440 on the camera tracking car, is a car! Oh, my God, I can't stand it anymore, and arm's bare metal development and STM are very similar, there is no big difference, and arm is a mini board, few peripherals, learning the opportunity of the module is very few, so I think, later stm32 on the bare metal development, can also try to transplant Uc/os system, This supporting learning, certainly better than the arm on the bare metal development!

2. I now use a battleship 3.5-inch screen, IC for NT35310, resistor screen, 16-bit drive, resolution of 320*480, very high resolution has been considered.

3. I now want to use the 16-bit mode, RGB565 storage data, this model of the driver chip is NT35310 (ID5310). Through some commands, we can set the gram (LCD video memory) pointer growth direction, that is, the direction of each pixel, so as long as the setting of the beginning of the writing position, you can fill the data continuously, in the sc++ (x-coordinate starting position) encountered EC (x-coordinate termination position), At this time EC will return to SC, but also sp++, starting from the next line to fill in the pixels (in the pointer growth mode is left to right, from the top down mode), and do not need to care about the location, greatly facilitates our programming, the speed is more than the coordinates of each time the LCD screen to be faster.

4. When filling in pixels, the steps are: Set start position---Send write gram command---write gram.

5. FSMC: Flexible static storage controller. This is the STM32 board with the SRAM, NAND Flash, NOR Flash operation of the controller, then the operation of the LCD is the equivalent of FSMC to an SRAM in operation.

6. Directly into the LCD use it, anyway, the principle of poor understanding, and then to observe how they use it can.

2016/4/20 IIC Bus presented by Philips Corporation

1. Because the IIC bus is a very common and popular bus protocol, used to read and write the registers of various modules to be configured, similar to the SPI Bus protocol, although the microcontroller learned, but also almost forget, so today to review a bit.

2. Today's test is also a routine, using IIC to read and write operation of the 24C02, through the LCD screen display.

3. IIC: Start signal, stop signal, answer signal.

4. The hardware has been PB6 received on the IIC_SCL, will PB7 received IIC_SDA, this is because these two ports can be multiplexed into the IIC bus two lines, mode push-pull output.

5. GPIO: For flexible control of a port as input/output mode:

SDA is PB7 as the output, use 50MHz output speed, do the normal output (CNF1 CNF0 MODE1 MODE0 =0011); When SDA is input, use the Multiplexing function, mode is reserved (CNF1 CNF0 MODE1 MODE0 = 1000)

6. IIC use process, my personal summary is this: 1) to configure the IIC take the port, 2) to detect the existence of IIC devices, 3) from the IIC issued a starting signal, while sending the device address, and then wait for the response signal generation; 4) wait for the response signal to send data out, Also need to conduct a response signal detection; 5) So the reading is actually similar, the specific timing aspect, in fact, according to the manual sequence diagram simulation once again, pay attention to the correctness of the operation of the bit.

7. SPI protocol: Then review the SPI protocol, this agreement in fact, I use a single-chip microcomputer NRF24L01 RF Communication module When there has been a relatively profound understanding, why said deep, because at that time still do not want to be so impetuous, will withstand the temper, step by step from the communication protocol, configuration register start, Finally spent five or six days to basic straightened out each other, the first torment of the module.

8. SPI is the bus protocol proposed by Motorola, which is a synchronous, high-speed, full-duplex serial communication protocol.

9. For two sets of values, used to determine the clock idle signal and sampling time Cpol and Cpha.

Cpol=0, the idle state of the serial clock is low, the reverse is high, and cpha=0 is sampled when the first clock jumps, and cpha=1 when the second clock jumps.

11. How to memorize miso and mosi, can be disassembled to understand as Master in Slave out and master out Slave in.

12. According to my previous understanding, in layman's terms, the SPI protocol is, when you play the one I shot one, this rhythm is the clock, this high-fives process is the transmission of data lines, in fact, is still not appropriate. Should be like two children exchange the same number of toys, but they choose a change rhythm one by one, until their toys all Exchange complete, then a child has the original belongs to another child's toys, then these toys are data, used to install toys is the register, to a certain rhythm exchange is the clock.

13. Now the routine use is PB12 do w25q128 CS chip selection, PB13 do sck,pb14 do miso,pb15.

2016/4/21 485 Agreement

1.485 protocol: In the physical layer, half-duplex, multipoint communication, it is similar to RS232, but it is more stable and reliable, transmission distance is longer than RS232, anti-jamming is also good, so this protocol still need to do some understanding.

2. The warship is using the SP3485 chip, the chip schematic diagram clearly shows that when the re signal is low, for the receiving mode, when the re signal is high, set in order to send mode.

3. Well, in fact, and the serial port mode is very similar, but the two use a different voltage as high and low level, the rest is really not much difference.

2016/4/22

1. Can bus: is also a serial communication protocol, for the current European Automotive Network Standard protocol, can achieve high-speed, high-quality data transmission in the car's LAN, has been ISO-standardized serial communication protocol. It determines the level by the difference in the potential of the two wires, and the bus is divided into the dominant level and the recessive level, both of which must be one.

2. Can bus features: it is possible to decide according to priority; Do not need the concept of "address", to join the module convenient, communication speed is relatively far, in the field control enough; There are also error detection feedback and other functions to make it one of the most promising Fieldbus

3. Can bus level judgment: recessive level refers to the voltage difference between can_l and Can_h is 0V, and the dominant level of Can_h and can_l between the voltage difference is about 2.5V.

4. Can bus through five frames: data frame, remote control frame, error frame, overload frame, frame interval.

5. D: The dominant level, that is, 0, then the pressure difference is about 2V; R: The recessive level, or 1, at which the pressure difference is 0V. Then the priority of the arbitration is through the dominant level of how much to judge, the dominant level of the output of the high priority, generally the first Bus request priority is higher than later, and can not be interrupted.

6. Can controller: There are three mailboxes for sending! Send process: Idle mailbox (when there is an idle mailbox)----registered (waiting for the mailbox to be the highest priority)------scheduled (the mailbox becomes the highest priority)------sent (once the bus is idle, it can be sent)----idle (after sending, the bus becomes idle again).

7. Can controller: There is a three-level FIFO to cache data! Receive process: When there is a null in the FIFO, a valid data is received----the registered-----receive valid data again-----registered two------。。。。 More than three times when valid data is received but not read, there is an overflow, so the data in the FIFO needs to be read in a timely manner.

2016/4/24 Webcam OV7670

1. OV7670 is a CMOS VGA image sensor, controlled by the SCCB bus of the class IIC, the VGA can be up to 30 frames per second.

2. VGA, which is the output mode with 640*480 resolution. QVGA, that is, the resolution is 320*240 output mode, generally with this, because the OV7670 FIFO is only enough to store a frame of QVGA.

2016/6/11

After nearly two months, I started playing the camera on the board, because the need to participate in the game, the camera must be the principle and routine digestion, and then the camera can be used to collect gray image, and can be flexibly set the image threshold.

1. Using the SCCB (Serial camera control bus) similar to the IIC control bus, mainly using this bus protocol to the 7670 state configuration.

2016/6/15

The last time I was disturbed by the exam, today will be a day.

1. First, OV7670 can store a frame at a resolution size of 320*240, which is the QVGA format.

2. PCLK is a pixel clock, generally a pclk clock output a pixel, but if a pixel is two byte size, then two PCLK clock is required to output a complete pixel, for example: RGB565.

3. VSync is the frame synchronization signal, one frame appears once.

4. The href is the line synchronization signal, which is determined by how many rows in the resolution, such as the resolution of the 640*480, then 480 times in a frame of the line synchronization signal.

5. Image data is output via d[7-0] eight data lines.

6. According to the time series diagram can be seen, when the line synchronization signal is active high, the output of the data is valid, then according to the PCLK Rise along the MCU acquisition, falling along the data changes, you can realize the image data read. (two byte words, high byte in front)

7.7670 Workflow: First camera capture image data, and then stored in the FIFO chip al224b (384K), generally we just store one frame is enough, and then through the interface, using the MCU from the FIFO chip to read the camera before the data collected.

8.

This is the external interface for the FIFO operation, which is the pin that comes out under the camera.

9.

Starting from the first frame synchronization signal, the beginning of the acquisition of a frame, then let the write pointer reset, that is, from the 0 address to write, and then write enable Enable, the FIFO will start to receive 7670 of the input image data, after waiting for the second frame synchronization signal, a frame of image acquisition is complete, This time the write enable can be disabled, and then let the MCU to read the FIFO data, and will not let the new data to wash off the previous data, to ensure that the read correctly.

11. Note: PB3 4 is the interface used in Jtag, if you want to use these two pins as a normal IO port, then you must prohibit JTAG, in order to make these two pins as normal IO.

12. Using interrupts to obtain the frame synchronization signal, and then the OV7670 to the FIFO to write data, the MCU also began to read data from the FIFO, which can speed up the data acquisition.

2016/6/16

1. "Y" indicates the luminance (luminance or luma), which is the grayscale value, while "U" and "V" represent the chroma (chrominance or chroma), which is used to describe the color and saturation of the image for specifying the colors of the pixel.

2. That is, I mainly use the Y component.

3. Several important settings for setting the output of grayscale images need to be understood.

Register Address

Value of the Register setting

7654 3210

Explain

0x12

0x10 (0001 0000B)

Universal control Register, or set to QVGA format output, output YUV encoding method of image data

0x3a

0x14 (0001 0100B)

The row buffer test option, using a fixed UV output, is the value of the 0x67 and 0x68 two registers. The row buffer output sequence, determined by the Register's "3" (0) and 0x3d "0" (0) Two bits, is found to use the YUYV output, which is y:u:v=4:2:2.

0x3d

0x80 (0000B)

Common control registers, gamma Enable, and 0x3a.

0x67

0x11 (0001 0001B)

A register with a value of 0x11 that fills the U value

0x68

0xFF (1111 1111B)

A register with a value of 0xFF to fill the V value

0x40

0XC0 (1100 0000B)

The output range of the data is 0x00-0xff.

4. Note : It is still not very understanding output sequence YUYV output, that is, y:u:v=4:2:2. This means.

2016/6/17

1. After the setup is complete, the basic can realize the gray image collection, the speed is very fast.

2. From the Internet to understand the characteristics of the OV7670, only to understand the true meaning of the previous YUYV output order, in fact, whether Y or U or V are eight-bit binary representation, that is, a byte. Then the YUYV output format shows that when we are using, we can get Y (brightness) by reading the first byte, and this brightness can be further processed to determine the value of two value image, that is, black and white image.

3.

4. This is the logo on my clothes, I also added the manual setting of the valve value of the key operation, easy to debug later, in different light conditions can be adjusted.

5.

STM32 Learning Experience (supplement)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.