The avr serial port configuration is very simple, just configure a few registers to send and receive;
But there are a few things to understand:
1. Once the serial port is successfully configured, the IO function is automatically occupied, which is different from LPC or STM8/32 (registered configuration is required);
2. There is no dedicated serial port opening or closing position (the entire serial port);
3. When reading and writing control register C, the URSEL bit needs to be written as 1, and when reading and writing the UBRRH register, URSEL needs to be written as 0;
1: //Crystal oscillator frequency
2: #define F_CPU 6000000UL
3: //Baud rate
4: #define BAUD 9600
5:
6: //M8 serial port 1 initialization
7: void UsartInit(void)
8: {
9: unsigned int tmp;
10: FifoInit(&RxFifo, sizeof(RxFifo.data));
11: FifoInit(&TxFifo, sizeof(TxFifo.data));
12: tmp= F_CPU/BAUD/16-1;
13: SetBit(SREG, 7);
14: UCSRB = 0;
15: UCSRC = 0;
16: UBRRH=(unsigned char)(tmp>>8);
17: UBRRL=(unsigned char)tmp;
18: UCSRB |= (1<
Previous article:AVR official charger
Next article:FreeModbus Lite Version (Only RTU) for M128 (Modbus Slave)
Recommended ReadingLatest update time:2024-11-15 15:39
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Squelch Tuning Audio Switching/Mixing Circuit Diagram
- Principles of peripheral expansion of single-chip microcomputer hardware system
- [Last few days] Free to get | Espressif ESP32-S3-Korvo-2, Raspberry Pi 400 and other good boards
- [ESK32-360 Review] + RTC Timer
- [N32L43x Review] Create a DEMO routine to test the SHT20 temperature and humidity sensor
- [RVB2601 Creative Application Development] I2C reads ultrasonic pressure sensor data
- Please recommend some good university textbooks on STM32. Thank you.
- LED flashing program, can't enter interrupt
- How to output full load of power module
- Qinheng MCU CH55X — USB application example source code sharing