编辑:这篇文章忽略了这个问题。我想这很清楚。您没有任何问题与端口寄存器写入或清除。你的问题是你不知道你什么时候写这个或写清楚。你的ADC代码只做了以下几点:你的图形LCD代码ALONE做如下:如果你的中断在错误的地方出现,结果是明显的:所以你的ADC的CS太早就被清除了。我不知道你的DISI是怎么做的。GN应该工作。如果设置CS线路,ADC和LCD如何知道,你想与哪两个通信?在中断之后,这种机制可能也会变得混乱。CS对ADC或LCD有意义,并对其进行帧通信?首先,是否有可能中断你正在使用ADC所做的事情,而与LCD进行通信,然后继续使用ADC的东西?如果答案是“否”,那么你需要通过禁用LCD中断之前的ADC代码部分原子,并在关键部分之后重新启用它们,如RISC所描述的。或者可以更改优先级设置,并将LCD中断置于与ADC中断相同的级别,这样它们就不能相互中断。在这两种情况下,中断可能彼此延迟。如果答案是“是”,那么您也可以检查LCD中断代码,CS是否已经设置,并且在LCD中断结束时仅在尚未设置CS时重置CS。然而,要小心,因为你可以很容易地犯很多错误,这是很难察觉的。
以上来自于百度翻译
以下为原文
Edit: This post misses the issue. See below.
I think this is quite clear. You don't have any issue with writes or clears with the port register. Your issue is that you don't know when you want to do this write or clear.
Your ADC code alone does the following:
set chip select
do some ADC stuff (while chip select is set)
do some more ADC stuff (while chip select is set)
clear chip select
Your graphics LCD code allone does the following:
- LCD interrupt occurs
- set chip select
- do some LCD stuff (while chip select is set)
- clear chip select
- LCD interrupt finished
The result is obvious, if your interrupt hits at the wrong place:
set chip select
do some ADC stuff (while chip select is set)
- LCD interrupt occurs
- set chip select
- do some LCD stuff (while chip select is set)
- clear chip select
- LCD interrupt finished
do some more ADC stuff (WHILE CHIP SELECT IS NOT SET !!!)
clear chip select
So your CS for the ADC gets cleared too early.
I don't know how your design is supposed to work.
If you set the CS line, how does your ADC and LCD know, to which of the two you want to communicate? Probably this mechanism also gets confused, after the interrupt.
And does the CS have a meaning to the ADC or LCD and frame the communication?
And in the first place, is it even possible to interrupt the stuff you are doing with the ADC, and communicate with the LCD instead, and then continue with the ADC stuff?
If the answer is "No" then you need to make the ADC code section atomic by disabling the LCD interrupt before and re-enabling them after the critical section, as described by RISC. Or you could change the priority settings, and place the LCD interrupt at the same level as the ADC interrupt, so they cannot interrupt each other. In both of these cases, the interrupts may delay each other.
If the answer is "Yes" then you could also check in the LCD interrupt code, whether the CS is already set, and at the end of the LCD interrupt reset the CS only if it was not already set. However, be VERY careful with that, because you can easily make a lot of mistakes, which are hard to detect.