MSP430F4152的USCI UART地址位多处理器通讯怎么做?
我的代码为:
void init_uart0(void)
{P6SEL |= BIT5+BIT6;// P6.5,6 = USCI_A0 TXD/RXDUCA0CTL0 = 0x04;//0000 0100UCA0CTL1 |= UCSSEL_2;// SMCLK 2MUCA0BR0 = 0xD0;UCA0BR1 = 0x00;UCA0MCTL = 0x40;// Modulation UCBRSx = 1UCA0CTL1 &= ~UCSWRST;// **Initialize USCI state machine**IE2 |= UCA0RXIE;// Enable USCI_A0 RX interrupt__enable_interrupt();//开全部中断
}#pragma vector=USCIAB0RX_VECTOR
__interrupt void UART0_isr(void)
{unsigned char new, add;if(UCA0STAT & UCADDR){add = UCA0RXBUF;}else{new = UCA0RXBUF;}
}
但是,什么也收不到,是不是用的不对?
Triton Zhang:
这段代码使用来配置接收带地址位的UART通信,你上位机是如何发送的?如果你的上位机发送不带地址位的数据,就会接收不到正确的数据。
qingmin zhang:
回复 Triton Zhang:
上位机是STM32做的。它采用STM32的库配置为9位的方式:USART_InitStructure.USART_BaudRate = 4800;USART_InitStructure.USART_WordLength = USART_WordLength_9b;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_Parity = USART_Parity_No;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;发送时,USART_SendData(USART1, Buffer);Buffer赋值9位数据。
qingmin zhang:
回复 Triton Zhang:
这段代码的设置方法正确吗?
qingmin zhang:
回复 Triton Zhang:
谢谢。配置是正确的,下面就好办了