A look of a serial port to send and receive experiment
The main function code is as follows:
Opens the receiving interrupt
The interrupt function is as follows:
The experiment purpose:
By sending a character to the development board, then it is sent back;
After completion of interruption in trying to achieve is to receive, LED lights flashing a
Download to the development board
To send a character a phenomenon is: serial debugging assistant continuously receives aaaaaaaaaaaaaaaaaa...
LED lights have no flicker,
Feeling did not enter the interrupt function
Excuse me
Where is the problems
CodePudding user response:
Your main program has been to send and receive dataCodePudding user response:
Don't judge whether your program wrote to receive data in a machine to send data up ah, and you receive written in the interrupt, receives data state flip, also is not flashing actionCodePudding user response:
Following tutorials to learn again and again, the pace is too big to learn things will miss a lot of important things, led to twinkle, twinkle at least more than 100 ms, is unlikely to wait in the interrupt 100 ms, of course, is not recommended to do this, a better approach is the main function after entering the while case flag, assignment in the interrupt flag, in case the following while, when the flag change out of circulation, in a loop, you can delay, flashing led, the serial port to send, single-chip microcomputer sends data to the computer, to send and receive, MCU received back, to the logic, you need to know now, what is sent to the single-chip microcomputer data on your computer, sent many, under the procedure how to perform, execute to step one, you can use the serial port to send back a 01 and 02, 03, representative where the run, so according to the Numbers you can easily know, microcontroller how code is running, in short, when you think to do something difficult to must hold to, always more and more simple, more and more growth,CodePudding user response:
Interrupt function not to deal with too many things, but also delay, this is the big fear,CodePudding user response:
First, don't delay, interrupt it can go inside the main function to monitor a sign flag, and then in the terminal to set this flag;Second, the LED best is more than 100 ms delay time; Flashing a suggestion 1 s;
Third, has been receiving aaaaaa, can make sure your PC sent only once? Or in the loop to send a?
CodePudding user response:
Your main program has been calling on the serial port to send, interrupt as simple as possible, to deal with things, the less the better, can't delay.,CodePudding user response:
Thank you bosses solution, benefit a lotCodePudding user response:
Inside the interrupt function can't handle too much work, don't put the time delay functionCodePudding user response:
Thank you for your bosses learnedCodePudding user response:
I just saw you remove a serial port interrupt flags, but does not remove the array, is equal to the serial port you accept in the array, has always been kept 'a', you in the main function, simply send, therefore, appeared a series of 'a', there is a reason,CodePudding user response:
Reason one, I only saw you remove a serial port interrupt flag bits, but did not remove array, array is equal to the serial port you accept, always holds the 'a', in the main function, you simply send, therefore, appeared a series of 'a', there is a reason,Reason two, I don't think with leds turn state have direct relationship with the code, according to your logic, this part must be carried out, you can switch to the simplest LED=0; LED=1; Have a try,