int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
Init_CLK(); //初始化时钟
Init_Port();
Init_UART();
Init_IIC(); //IIC初始化
MPU9255_Init(); // //MPU9255初始化
_EINT(); //打开全局中断控制
while(1)
{
MPU9255ReadAcc(Accel);
Uart_Putchar(Accel[0]);
Uart_Putchar(Accel[1]);
Uart_Putchar(Accel[2]);
MPU9255ReadGyro(Gyro);
Uart_Putchar(Gyro[0]);
Uart_Putchar(Gyro[1]);
Uart_Putchar(Gyro[2]);
}
}
void Init_UART()
{
UCA0CTL0 = 0;
UCA0CTL1 |= UCSWRST; // Set SW Reset
UCA0CTL1 |= UCSSEL_2; // Use SMCLK
UCA0BR0 = 0xA0; // 4MHz/416=9600KHz
UCA0BR1 = 0x01; //9600
UCA0MCTL=0xC0;
3SEL |= 0x30; //P3.1 3.3作为IIC的SDA和SCL端口,P3.4 P3.5作为调试串口的TXD和RXD端口
3DIR |= BIT4;
3DIR &=~BIT5; //Set
ting P3.5 input
UCA0CTL1 &= ~UCSWRST; // Resume operation
IFG2 &=~UCA0TXIFG; //因为UCA0TXIFG默认为1,如果不置0,下面的发送中断使能会直接进入中断函数
__bis_SR_register(GIE);
}
void Uart_Putchar(unsigned char c)
{
while((IFG2 & UCA0TXIFG)); //待发送为空
UCA0TXBUF=c;
IE2 |= UCA0TXIE;
}
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
IFG2 &=~UCA0TXIFG;
IE2 &= ~UCA0TXIE;
}
目的很简单,就是把Accel,Gyro里面的数据通过串口发送到PC机显示出来,是不是我对430串口的理解不到位,欢迎各位批评指正。
int main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
 3SEL |= 0x30; // 3.4,5 = USART0 TXD/RXD
BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_3; // MCLK = LFXT1 (safe)
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x74; // 3.58Mhz/9600 - 372
UBR10 = 0x01; //
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}
一周热门 更多>