2. After you have a general understanding of hardware resources, you need to understand the bridge between software and hardware - registers.
There is the same address, but the envelopes you write and others send you are the same. It is automatically controlled when used.
Receive completion set 1
Read data clear 0
UCSRB
RXCIE
Receive interrupt enable
RXEN, TXEN setting will change the normal IO port, or use it as a multiplexed port. Set it when sending data, and it will take effect after all the data is sent.
RXB8, TXB8 needs to be read and written first
UCSRC
URSEL
register selects
Need to be set to 1 when writing
There is a shared register
Baud rate register: UBRRL
Please pay attention to the setting of URSEL: 0
Read UBRRH, the first time is the content of the bit rate.
When using it, you can check the quick lookup table and directly use the ICCAVR generation tool.
3. Related operations
1. Initialize and turn off
TXC
and the data can be put into the sending buffer
2. Note that after the interrupt
Some bus standard
RS232 9-pin D-type interface
needs to use level conversion circuit
5. Serial Ports in Industrial Design
If you see this, it is better to pay attention to it. There are not many articles on the Internet. I also summarized it from engineering practice and searching a lot of reference books.
The design idea is based on the state machine and the protocol is customized. At the same time, CRC check and simple encryption technology are used in the protocol.
The idea is: master-slave mode, the upper computer sends data packets, the lower computer receives them in the interrupt, and when receiving data, it must confirm bit by bit and switch continuously, the position status of the send, put the preliminary confirmed data into the receive buffer, and wait for all the data to be received, the program enters the big loop, and executes the uart operation function added to the main program. This function first determines whether the command and setting sent by the host are accepted, and verifies the correctness in the completed state. After verification, according to the host command, assemble the data packet and store the host's setting data, and put the data packet to be sent or the setting completion data packet in the data buffer to be sent, and then change the state at this time: It is assembled for me, ready to send data, and then trigger the interrupt, you can directly send data to the serial port. After normal transmission, the microcontroller will execute other programs. After the upper computer receives the trigger data, the lower computer will interrupt. The interrupt program will generate the data in the buffer bit by bit according to the state until all the data is sent. After the sending is completed, it must be set to the receiving data state 0.
My environment is atmega128
initialization
uchar LED_Temp=0xFF;
uchar OUT_temp=0x04;
static uchar Uart_Status;
static uchar R_Data_Lenth;
float Tx_Buf[TxBufSize];
float Rx_Buf[RxBufSize];
float *P_Uart_Rx;
float *P_Uart_Tx;
float Rx_Count;
float Tx_Count;
void Uart_Init(void)
{
}
//
void Com_baudrate (unsigned int baudrate)
{
}
//
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
}
//Function description: Serial port transmission completion interrupt function
#pragma interrupt_handler uart0_tx_isr:iv_USART0_TXC
void uart0_tx_isr(void)
{
}
//
void Uart_Process(void)
{
}
//Function description: uart test program
void Uart_Test(uchar data)
{
}
//- Function description: Function of sending bytes through the serial port
//
//
void UART_Send_Byte(unsigned char mydata)
{
}
Previous article:Reading and Writing EEPROM of AVR Microcontroller
Next article:AVR MCU reads PS2 mouse
Recommended ReadingLatest update time:2024-11-16 22:20
- 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.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Contactless face recognition access control system] + 6-EFR32BG22 using GPIO
- EEWORLD University ---- Linear Regulator_Low Dropout Regulator and Switching Power Supply Introduction
- MicroPython programming environment——Pycharm
- Serial port printing problem of domestic AC7801X chip (with program)
- EEWORLD University Hall--Introduction to the system and software and hardware implementation of the vehicle external amplifier
- Constraint and Delay Analysis
- EEWORLD University ---- IC front-end design
- Last 3 days: Apply for EC-01F-Kit, the official website of Essence, for free.
- Have you ever thought about the issue of program efficiency?
- Anyone who has used Eagle, please help me convert Eagle files into PADs files, thank you