在发送数据过程中,为什么只发送了几个byte就从ISR中跳出来了?而且在发送数据过程中,STAT寄存器中SCLLOW位始终置位,这是对的吗?我的程序如下所示:- #include "msp430x54xA.h"
- unsigned char *PTxData; // Pointer to TX data
- unsigned char TXByteCtr;
- #define VCC3P3_PwrOn (P8OUT |= BIT5)
- #define VCC3P3_PwrGood (P8IN & BIT6)
- #define LED_ON (P3OUT &= ~(BIT6))
- #define LED_OFF (P3OUT |= BIT6)
- const unsigned char TxData[] = // Table of data to transmit
- {
- 0x01,
- 0x0b,
- 0x02,
- 0x00,
- 0x00,
- 0x03,
- 0x32,
- 0x00,
- };
- void test_mcu_port_init(void);
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- test_mcu_port_init();
- VCC3P3_PwrOn;
- while(!(VCC3P3_PwrGood))
- {
- ;
- }
- LED_ON;
- P3SEL |= 0x80; // Assign I2C pins to USCI_B0
- P5SEL |= 0x10;
- UCB1CTL1 |= UCSWRST; // Enable SW reset
- UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
- UCB1CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
- UCB1BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
- UCB1BR1 = 0;
- UCB1I2CSA = 0x4a; // Slave Address is 048h
- UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
- UCB1IE |= UCTXIE; // Enable TX interrupt
- // while (1)
- // {
- __delay_cycles(50); // Delay required between transaction
- PTxData = (unsigned char *)TxData; // TX array start address
- // Place breakpoint here to see each
- // transmit operation.
- TXByteCtr = sizeof TxData; // Load TX byte counter
- UCB1CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
- __bis_SR_register(GIE); // Enter LPM0, enable interrupts
- __no_operation(); // Remain in LPM0 until all data
- // is TX'd
- while (UCB1CTL1 & UCTXSTP); // Ensure stop condition got sent
- // }
- }
- void test_mcu_port_init(void)
- {
- /*将所有端口恢复到初始值*/
- P1OUT &= 0x00;
- P2OUT &= 0x00;
- P3OUT &= 0x00;
- /*LED为关闭状态*/
- LED_OFF;
- P4OUT &= 0x00;
- /*I/O扩展芯片中断管脚拉高*/
- P4OUT |= BIT6;
- P5OUT &= 0x00;
- P6OUT &= 0x00;
- P7OUT &= 0x00;
- /*关闭1.8V的MOSFET*/
- P7OUT |= BIT4;
- P8OUT |= 0x00;
- /*定义所有端口方向和功能选择*/
- P1SEL |= 0x00;
- P1DIR |= 0x5b;
- P2SEL |= 0x00;
- P2DIR |= 0xe7;
- P3SEL |= 0xbf;
- P3DIR |= 0x40;
- P4SEL |= 0x59;
- P4DIR |= 0xae;
- P5SEL |= 0xd0;
- P5DIR |= 0x25;
- P6SEL |= 0x03;
- P6DIR |= 0x78;
- P7SEL |= 0x0b;
- P7DIR |= 0xb4;
- P8SEL |= 0x00;
- P8DIR |= 0x3f;
- }
- //------------------------------------------------------------------------------
- // The USCIAB0TX_ISR is structured such that it can be used to transmit any
- // number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
- // points to the next byte to transmit.
- //------------------------------------------------------------------------------
- #pragma vector = USCI_B1_VECTOR
- __interrupt void USCI_B1_ISR(void)
- {
- switch(__even_in_range(UCB1IV,12))
- {
- case 0: break; // Vector 0: No interrupts
- case 2: break; // Vector 2: ALIFG
- case 4: break; // Vector 4: NACKIFG
- case 6: break; // Vector 6: STTIFG
- case 8: break; // Vector 8: STPIFG
- case 10: break; // Vector 10: RXIFG
- case 12: // Vector 12: TXIFG
- if (TXByteCtr) // Check TX byte counter
- {
- UCB1TXBUF = *PTxData++; // Load TX buffer
- TXByteCtr--; // Decrement TX byte counter
- }
- else
- {
- UCB1CTL1 |= UCTXSTP; // I2C stop condition
- UCB1IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
- }
- default: break;
- }
- }
- 请帮忙解答一下
复制代码
请帮忙解答一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
ACK之后,才会继续发送下一个数据吗?
一周热门 更多>