第 36 页 EMX 用户手册指出:“可以使用可选的毛刺滤波器在上升沿或下降沿激活中断。” 然而 Redpine Signals RS9110-N-11-21 数据表指出:“高电平有效,电平触发。” 中断由 WiFi 设备触发。在 C# 代码中,如果我使用 InterruptEdgeLevelHigh 或 InterruptEdgeLevelLow 的参数,我会收到一个参数异常。没关系,因为它与 EMX 用户手册一致。如果我使用 InterruptEdgeBoth、InterruptEdgeHigh 或 InterruptEdgeLow,我将无法接收到中断。我不确定这是否是因为设备正在使用“高电平有效,电平触发”。
如果 RedPine 被限制为“电平触发”,我是否应该能够在 Edge 触发时检测到它们的中断,或者中断检测是否绝对限制为电平?
这是我用来测试触发器的部分代码:
public static void Main()
{
config = new SPI.Configuration((Cpu.Pin)EMX.Pin.IO2, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
SPI1 = new SPI(config);
WiFiReset = new OutputPort((Cpu.Pin)EMX.Pin.IO3, true);
WiFiInterrupt = new InterruptPort((Cpu.Pin)EMX.Pin.IO26, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
// "Interrupts can be activated on rising or falling edges with an optional glitch filter." Page 36 EMX User Manual.
// Redpine Datasheet: "Active high, level triggered."
// NETMF interrupt event: "If an InterruptEdgeLevelHigh or InterruptEdgeLevelLow interrupt event occurs, an application must call the ClearInterrupt method to re-enable this event."
WiFiInterrupt.OnInterrupt += new NativeEventHandler(WiFiInterrupt_OnInterrupt);
try
{
byte[] in_initialise = { 0x15, 0x00 }; //initialisation
byte[] out_initialise = new byte[2];
SPI1.WriteRead(in_initialise, out_initialise);
if (out_initialise[1] != 0x58) //SUCCESSFUL
{
WiFiReset.Write(false);
Thread.Sleep(1);
WiFiReset.Write(true);
SPI1.WriteRead(in_initialise, out_initialise);
}
if (out_initialise[1] == 0x58)
{
Debug.Print("WiFi is Initialised.");
WiFiInterrupt.ClearInterrupt();
intFlag = false;
byte[] in_bandStart = { 0x7c, 0x04, 0x10, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00 }; //Band
byte[] out_bandStart = new byte[20];
SPI1.WriteRead(in_bandStart, out_bandStart);
if (out_bandStart[19] == 0x58) //SUCCESSFUL
{
//Debug.Print("WiFi established Band Command Start.");
while (intFlag == false && delay < maxDelay)
{
++delay; //waiting for interrupt
SPI1.WriteRead(tx_data, rx_data);
if (rx_data[0] == 0x55)
break;
Thread.Sleep(1);
}
if (delay != maxDelay)
{
*****************************************************************************************************
static void WiFiInterrupt_OnInterrupt(uint data1, uint data2, DateTime time)
{
byte[] in_intStart = { 0x5c, 0x00, 0x10, 0x00 }; //Band Start
byte[] out_intStart = new byte[4];
SPI1.WriteRead(in_intStart, out_intStart);
intFlag = true;
intTime = time;
}
在第一次中断到期时,我已经多次收到 0x58 确认接收(请参阅“等待中断”)。
Band Command Start
Send : 7c Recv : 00
Send : 04 Recv : 58
Send : 10 Recv : 58
Send : 00 Recv : 58
Send : 02 Recv : 58
Send : 18 Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 04 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Wait for interrupt
Interrupt received, Do master read
Send : 5c Recv : 00
Send : 00 Recv : 58
Send : 10 Recv : 58
Send : 00 Recv : 58
wait for start token
Send : Dummy 00 Recv : 58
Send : Dummy 00 Recv : 58
Send : Dummy 00 Recv : 55
Read descriptor is
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 97 .........Band Success Response
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 55
Send : Dummy 00 Recv : 88
Send : Dummy 00 Recv : 01
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : 00
Send : Dummy 00 Recv : d1
Send : Dummy 00 Recv : 27
Send : Dummy 00 Recv : 04
Send : Dummy 00 Recv : 00
Band Response =97 Status=00
--------------------------------------------
Init Start
Send : 7c Recv : 80
Send : 04 Recv : 58
Send : 10 Recv : 58
Send : 00 Recv : 58
Send : 00 Recv : 58
Send : 10 Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
Send : 00 Dummy Recv : 58
任何意见将不胜感激。
凯文。