This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi, below is my program
I am trying to modify the I2c master program used for F5969 to be used for F5529, but the part about I2c setting in line 28, 34 and 89 keeps reporting undefined
Can you point out or fix the problem for me
Thanks and ragardsFullscreen123456789101112131415161718192021#include <msp430.h> #include <stdio.h>#include <stdint.h>volatile uint8_t TxCount, Control_Byte, i;volatile uint8_t *PTxData; // Pointer to TX datavolatile uint8_t TxData[3], Msg1[]={1,2,3}, Msg2[]={4,5,6};void main(void) { WDTCTL = WDTPW | WDTHOLD; //Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; //Unlocks GPIO pins at power-up P1DIR |= BIT0 + BIT2 + BIT3 + BIT4 + BIT5 ; P3DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7; P4SEL |= 0xFF; //Setup I2C P1OUT = BIT1; // Pull-up resistor on P1.1 P1REN = BIT1; // Select pull-up mode for P1.1 P1IES = BIT1; // P1.1 Hi/Lo edge P1IFG = 0; // Clear all interrupt flagsXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#include <msp430.h>
#include <stdio.h>
#include <stdint.h>
volatile uint8_t TxCount, Control_Byte, i;
volatile uint8_t *PTxData; // Pointer to TX data
volatile uint8_t TxData[3], Msg1[]={1,2,3}, Msg2[]={4,5,6};
void main(void) {
WDTCTL = WDTPW | WDTHOLD; //Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; //Unlocks GPIO pins at power-up
P1DIR |= BIT0 + BIT2 + BIT3 + BIT4 + BIT5 ;
P3DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P4SEL |= 0xFF; //Setup I2C
P1OUT = BIT1; // Pull-up resistor on P1.1
P1REN = BIT1; // Select pull-up mode for P1.1
P1IES = BIT1; // P1.1 Hi/Lo edge
P1IFG = 0; // Clear all interrupt flags
P1IE = BIT1; // P1.1 interrupt enabled
P4OUT &= ~BIT7; //green LED off
P1OUT &= ~BIT0; //red LED off
// Configure the eUSCI_B0 module for I2C at 100 kHz
UCB1CTLW0 |= UCSWRST;
UCB1CTLW0 |= UCSSEL__SMCLK + UCMST + UCTR + UCSYNC + UCMODE_3; //Select SMCLK, master, transmitter, synchronous, I2C
UCB1BRW = 10; //Divide SMCLK by 10 to get ~100 kHz
UCB1I2CSA = 0x77; // FR2355 address
UCB1CTLW1 &= ~UCSWRST; // Clear reset
UCB1IE |= UCTXIE11; //Enable I2C transmission interrupt
__enable_interrupt(); //Enable global interrupts.
Control_Byte=0x01;
while(1)
{
LPM4; //Wait for pushbutton interrupt in low power mode
Control_Byte ^= BIT0; //Toggle control byte
if(Control_Byte == 0x01)
{
for(i=0;i<3;i++)TxData[i]=Msg1[i];
P1OUT |= BIT0; //Red LED
}
else
{
for(i=0;i<3;i++)TxData[i]=Msg2[i];
P4OUT |= BIT7; //Green LED on
}
PTxData = (uint8_t *)TxData; //Set pointer to start of TX array
TxCount = 3; //Send bytes to slave
UCB1CTLW1 |= UCTXSTT; // Set to transmit and start
LPM0; // Remain in LPM0 until all data transmitted
while (UCB1CTLW1 & UCTXSTP); // Ensure stop condition got sent
__delay_cycles(10000);
P1OUT &= ~BIT0; //LEDs off
P4OUT &= ~BIT7;
}
}
#pragma vector = USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void)
{
switch(__even_in_range(UCB0IV,30))
{
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: RXIFG3
case 12: break; // Vector 12: TXIFG3
case 14: break; // Vector 14: RXIFG2
case 16: break; // Vector 16: TXIFG2
case 18: break; // Vector 18: RXIFG1
case 20: break; // Vector 20: TXIFG1
case 22: break; // Vector 22: RXIFG0
case 24: // Vector 24: TXIFG0
if (TxCount) // Check if TX byte counter not empty
{
UCB1TXBUF = *PTxData++; // Load TX buffer
TxCount--; // Decrement TX byte counter
}
else
{
UCB1CTL1 |= UCTXSTP; // I2C stop condition
UCB1IFG &= ~UCTXIFG1; // Clear USCI_B0 TX int flag
LPM0_EXIT; // Exit LPM0
}
break;
case 26: break; // Vector 26: BCNTIFG
case 28: break; // Vector 28: clock low timeout
case 30: break; // Vector 30: 9th bit
default: break;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT1; // Clear P1.1 IFG
LPM4_EXIT; // Exit LPM4
}
line 28 :我编译了你的程序后并没有报错,应该是没问题,你可以查看下你头文件中的定义。
line 34 :头文件中并没有UCTXIE11这个定义,你可以直接使用UCTXIE。
line 89 :同样的,头文件中没有UCTXIFG1定义,你可以直接使用UCTXIFG。
非常感谢帮忙,修改过后line 34、line 89的未定义问题皆解决了,不过现在于line 32的Clear reset部分也显示了未定义,想请教这部分应如何修改