correct
It is found that the reason is that TI/RI will be turned on together as long as the interrupt enters. In this case, it is necessary to set it low in the interrupt service function, otherwise the interrupt response will always exist. It is recommended to set TI low in addition to setting RI low in the serial port interrupt (the code has been modified). In addition, the send_data_to_uart1() function used in the receiving interrupt when I tested it two years ago will set TI low before sending, and then set it low by hardware after sending. It may be because of this reason that the interrupt can run smoothly.
Once again, I would like to express my gratitude to the big guy who found the reason, and apologize to the students who were misled by me.
original
For the configuration of the related registers of serial port 1 and serial port 0 interrupts, please refer to N76E003 dual serial port interrupt configuration, problems and solutions
The complete code has been posted in this article. If you encounter problems that cannot be compiled, you can consider downloading the project file of this article
The serial port 1 control register and the serial port 0 control register are named with a suffix "_1" and will not be repeated here. The official technical manual states that
The N76E003 includes two full-duplex serial ports with enhanced automatic address recognition and frame error detection.
Similarly, to distinguish the two serial port control bits, the control bit of serial port 1 ends with "_1" (for example, SCON_1)
In addition, please note that debug and serial port 1 cannot be used at the same time.
N76E003 UART1 pin is also occupied by debug pin,
please remove Nu-link or not in debug mode to test UART1 function.
External UART1 connect also disturb debug download
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"
#include #define uchar unsigned char #define uint unsigned int uchar IRCOM[7]; uchar ZTJ=0,flag=0,count=0; uchar UART0_RX_BUF[2],UART1_RX_BUF[2]; //Serial port 0, serial port 1 data receiving buffer uchar UART0_RX_STA=0,UART1_RX_STA=0; //Serial port 0, serial port 1 receiving counter bit riflag; void delay(uchar x) { uchar y; while(x--) { for(y = 0; y<158; y++) { _nop_(); } } } /******************************************************************/ //Wait for the delay program. Note that if you use the official delay program, it may conflict with other interrupt programs. void delay1(int ms) { unsigned char y; while(ms--) { for(y = 0; y<250; y++) { _nop_(); _nop_(); _nop_(); _nop_(); } } } /**************************************************************************/ int main() { Set_All_GPIO_Quasi_Mode; //——————Serial port 0, serial port 1 pin initialization------------- set_P02; set_P06; set_P07; set_P16; //----------Serial port 1, serial port 0 configuration---------------- IE = 0x90; // Allow total interrupt, serial port 0 interrupt set_ES_1; // Enable serial port 1 interrupt InitialUART0_Timer1(9600); InitialUART1_Timer3(9600); //Without configuring SM1 and SM2 registers, the default mode is 0 (half-duplex) //---------Enter your own code------------------- while(1) { } } /******************Interrupt service routine********************************/ /****************Serial port 0 interrupt service program*******************************/ void Uart0_test() interrupt 4 { if(RI) //Serial port 0 receive interrupt flag (set to 1 by hardware when there is data) { RI=0; //software set to 0 TI=0; //Open at the same time, TI also needs to be set low UART0_RX_BUF[UART0_RX_STA]=SBUF ; //Read received data from SBUF buffer UART0_RX_STA++; //Calculate the received length // if(){}//Perform data verification through RX_BUF&RX_STA // UART0_RX_STA=0; // Clear the receive counter // Send_Data_To_UART0(); //Sending function, this function automatically clears TI (TI register is set by hardware after sending is completed) } } /****************Serial port 1 interrupt service program*******************************/ void Uart1_test() interrupt 15 { if(RI_1) //Enter interrupt { RI_1=0; TI_1=0; //Open at the same time, TI also needs to be set low UART1_RX_BUF[UART1_RX_STA]=SBUF_1 ; //Read received data from SBUF_1 buffer UART1_RX_STA++; //Calculate the receiving length // if(){}//Perform data verification through RX_BUF&RX_STA // UART1_RX_STA=0; // Clear the receive counter // Send_Data_To_UART1(); //Sending function, this function automatically clears TI_1 } }
Previous article:N76E003 PWM Program and Analysis 2 (Complementary Mode & Dead Zone Insertion)
Next article:N76E003 PWM polarity control
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [Synopsys IP Resources] Automotive cybersecurity starts with chips and IP
- From design to market launch - how many batons are needed in this 5G terminal relay race?
- Ferroelectric Random Access Memory (F-RAM) and Device System Design
- 【FAQ】Secure Boot of Microprocessors | Microchip Security Solutions Seminar Series 7
- Application of “C2000+TMS570” dual-chip solution in automotive electric drive functional safety
- I recently played with RTT's MicroPython on STM32407, and the IDE is really easy to use.
- Introduction to F28335 ADC configuration code modules and their sorting methods
- High-performance fully integrated successive approximation register analog-to-digital converter
- What is the difference between SMT inductors and SMD inductors?
- Inside the DLP NIRscan Nano Evaluation Module