N76E003 serial port 1, serial port 0, interrupt program (mode 0)

Publisher:火箭少年Latest update time:2022-06-29 Source: eefocusKeywords:N76E003 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Write the picture description here
Write the picture description here

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

}

}


Keywords:N76E003 Reference address:N76E003 serial port 1, serial port 0, interrupt program (mode 0)

Previous article:N76E003 PWM Program and Analysis 2 (Complementary Mode & Dead Zone Insertion)
Next article:N76E003 PWM polarity control

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号