工具/软件:
大家好、我目前正在开发一个程序、以便在 MSP430 和 Arduino 之间进行通信。现在、我面临同步问题、我需要同步 Arduino 和 MSP 之间的通信。
当我尝试在 Arduino 中从 TX 模式切换到 Rx 模式、并在 MSP430 中从 Rx 切换到 TX 时、我似乎无法通信、我认为这是由于同步问题、因为当我尝试仅执行其中一种模式 (RX 或 TX) 而不是在 Arduino 和 mps430 可以通信的模式之间切换我认为这是由于 Arduino 正在与池使用的事实,所以如果同步字失败它将重复任何一种方式,并触发 GDO 中断和 MSP 最终将读取缓冲区(在 Arduino (TX) 和 MSP (RX) 的情况下)。
在这里我有两个代码,以缩短代码我将只包括更重要的部分:
Arduino
/* ARDUINO CODE - NOTE: the wakeUp routine dosent do nothing */
while (1)
{
digitalWrite(4, HIGH);
sendPacketINT(buffer_tx, 5);
delay(500);
attachInterrupt(2, wakeUp, FALLING);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(2);
digitalWrite(4, LOW);
SendStrobe(CC2500_SIDLE);
SendStrobe(CC2500_SFTX);
SendStrobe(CC2500_SFRX);
// RX
SendStrobe(CC2500_SRX);
delay(500);
attachInterrupt(2, wakeUp, FALLING);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(2);
//while(digitalRead(GDO0));
listenForPacket(buffer_rx, 5);
if (buffer_rx[4] == length)
{
digitalWrite(4, HIGH);
}
}MSP
// GDO init: P2.0 - reg 0x02 | val 0x06
P2DIR &= ~BIT0; // input
P2REN |= BIT0; // enable pull up/pull down resistor
P2OUT |= BIT0; // use as pull up resistor
P2IES |= BIT0; // interrupt edge (H -> L)
P2IFG &= ~BIT0;
P2IE &= ~BIT0;
while (1)
{
// LER
P2IFG &= ~BIT0;
P2IE |= BIT0;
sendStrobe(CC2500_SRX);
__bis_SR_register(GIE + LPM0_bits);
for (int i = 0; i < 5; i++)
{
buffer_rx[i] = CC2500_read_register(CC2500_RXFIFO);
}
if (length == buffer_rx[4])
{
P1OUT |= BIT0;
received = 1;
}
sendStrobe(CC2500_SIDLE);
// Flush RX FIFO
sendStrobe(CC2500_SFRX);
for (int i = 0; i < 5; i++)
{
write(*(point_tx + i),CC2500_TXFIFO);
}
// Transmitter mode
sendStrobe(CC2500_STX);
__delay_cycles(500000); // 500 ms
// reativar interrupt gdo e escrever tudo no TXFIFO
P2IFG &= ~BIT0;
P2IE |= BIT0;
__bis_SR_register(GIE + LPM0_bits);
// go back to rx mode and flush TX FIFO
sendStrobe(CC2500_SIDLE);
//__delay_cycles(100);
sendStrobe(CC2500_SFTX);
P1OUT &= ~BIT0;系统方框图:

目标是让 Arduino 发送一条消息、然后由 MSP430 发送另一条消息。
我已经尝试使用延迟的 Arduino,但发现相当快,它不高效,也许使用计时器的两个?
非常感谢您的帮助、感谢您抽出宝贵的时间!