|
msp430f5529 的UART模块485通讯问题
[复制链接]
我想问下我这程序有什么问题,为什么老是出错。我是想让程序每一秒发一组数据,receive_Data才4个数据,但是i==6才能发送出5个数据“0xf0 0xf1 0xf2 0xf3 0xfe”如果i==5的话又变成“0xf0 0xf1 0xf2 0xfe”了。。。用的MAX3485连接MPU,再转成RS232到电脑上的串口调试程序。如果我想接收和发送多个数据,我应该怎么配置寄存器?发送和接收多个数据是进一次中断还是进多个(数据的字节数)中断
- #include <msp430.h>
- #include "UCA0_UART.h"
- #include "TIMER_A0.h"
- void main()
- {
- WDTCTL = WDTPW + WDTHOLD;
- UCA0_Init();
- TIMERA0_Init();
- _EINT();
- while(1);
- }
- #include <msp430.h>
- #include "TIMER_A0.h"
- #include "UCA0_UART.h"
- /******************************
- 名 称:TIMERA0_Init
- 功 能:初始化TIMERA0寄存器操作
- 参 数:无
- 返 回:无
- ******************************/
- void TIMERA0_Init(void)
- {
- P8DIR |= BIT0;
- TA0CCR0 = 32768-1;
- TA0CTL = TASSEL_1 + MC_1 + TACLR + TAIE; // ACLK, contmode, clear TAR
- // enable interrupt
- }
- #pragma vector=TIMER0_A1_VECTOR
- __interrupt void TIMER0_A1_ISR(void)
- {
- switch(__even_in_range(TA0IV,14))
- {
- case 0: break; // No interrupt
- case 2: break; // CCR1 not used
- case 4: break; // CCR2 not used
- case 6: break; // reserved
- case 8: break; // reserved
- case 10: break; // reserved
- case 12: break; // reserved
- case 14: // overflow
- P8OUT ^= BIT0;
- RS485_T;
- UCA0IE |= UCTXIE;
- break;
- default: break;
- }
- }
- #include <msp430.h>
- #include "UCA0_UART.h"
- unsigned char receive_Data[4] = {0x00,0x00,0x00,0x00};
- unsigned char transmit_Data[4] = {0xf0,0xf1,0xf2,0xf3};
- unsigned char i = 0;
- /******************************
- 名 称:UCA0_Init
- 功 能:初始化UCA0寄存器操作,波特率9600,奇偶校验位无,数据位8位,停止位1位,
- 参 数:无
- 返 回:无
- ******************************/
- void UCA0_Init(void)
- {
- P3SEL = BIT3 + BIT4;
- UCA0CTL1 |= UCSWRST;
- UCA0CTL1 |= UCSSEL_2; // SMCLK = 1.048576MHz
- UCA0BR0 = 6; // 1.048576MHz 9600 N = 1.048576/(16*9600 )= 6
- UCA0BR1 = 0; // 1.048576MHz 9600
- UCA0MCTL |= UCBRS_0 + UCBRF_13 + UCOS16; // Modulation UCBRSx=1, UCBRFx=0
- // over sampling
- UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
- UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
- RS485_OUT;
- RS485_R;
- }
- #pragma vector=USCI_A0_VECTOR
- __interrupt void USCI_A0_ISR(void)
- {
- switch(__even_in_range(UCA0IV,4))
- {
- case 0:break;
- case 2:
- case 4:
- while(UCA0IFG&UCTXIFG);
- TA0CTL &=~ TAIE;
- UCA0IE &=~ UCRXIE;
- UCA0TXBUF = transmit_Data[i++];
- if(i == 4)
- {
- i = 0;
- UCA0IFG &=~ UCTXIFG;
- UCA0IE &=~ UCTXIE;
- TA0CTL |= TAIE;
- RS485_R;
- return;
- }
- break;
- default: break;
- }
- }
复制代码
|
|