0

我正在使用 MSP430 Launchpad。更具体地说,我使用的是微控制器 MS430G2553。我试图编译一些为 MS430G2230 设计的代码,但问题是代码的某些部分与 MS430G2553 不匹配。这是代码

void USI_Init (void)
{
 // configure SPI
 USICTL0 |= USISWRST;                      // USI in reset
 USICTL0 = USICTL0 | USILSB;               // Least Significant Bit first
 USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI Master
 USICTL1 |= USICKPH;                       // flag remains set
 USICKCTL = USIDIV_1 + USISSEL_2;          // /2 SMCLK
 USICTL0 &= ~USISWRST;                     // USI released for operation
 USICNT = USICNT | 0x50;                   // 16 bit mode; 16 bit to be    transmitted/received
 return;
}


这是第二个不起作用的例程


#pragma vector=WDT_VECTOR
__interrupt void Write_Matrix(void)
{
static unsigned char index=0;

 P1OUT |= DATA_LATCH_PIN;
 P1OUT &= ~DATA_LATCH_PIN;

  USICTL1 &= ~USIIFG;           // Clears the interrupt flag
  USISRH = 1<<index;            // Move the index of the column in the high bits of USISR
  USISRL = Matrix[index];       // Move the index of the rows (value of Matrix[index]) in the low bits of USIRS
  USICNT = USICNT | 0x10;       // 16 bit format
 index = (index+1) & 7;

 return;
}

有任何想法吗?谢谢

4

1 回答 1

2

首先,您不应该期望在这两个处理器系列之间拥有 100% 可移植的代码。MSP430G2553 是一款超值系列处理器,并配备了比 MSP430G2230 更多的外设。

请参考以下图表:

MSP430G2230 功能图

MSP430G2230 功能图

MSP430G2553 功能图

MSP430G2553 功能图

如您所见,这些 MCU 非常不同。

您的第一个例程不起作用,因为 MSP430G2553 没有USI外围设备。相反,SPI 通信是使用USCI外围设备执行的。您将需要修改代码以使用此外围设备。请参考用户指南了解更多信息。

USI由于再次缺少外围设备,您的第二个例程无法正常工作。注意对USI寄存器的引用:USICTL1 &= ~USIIFG;等。您需要再次修改代码以使用USCI外围设备。

于 2014-02-10T13:25:07.210 回答