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.
Hello everyone,
i am currently working in interfacing the NFC NTAG I2C (NT3H1101/NT3H1201 )with the MSP430, so i want to receive 16 bytes of data, in my code when i run it step by step my code stop at the while(UCB0CTL1 & UCTXSTT); // Ensure START condition got sent
(UCB0CTL1 & UCTXSTT); // Ensure START condition got sent
i have looked at the example given by TI msp430g2x55_uscib0_i2c_04.c and still have failed to understand why they statred by this instruction as the msp430 is the responsible for sending a stop condiction
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
here below you can see my code
#include <msp430g2955.h> /* * main.c */ //***declaration of global variable*************************** unsigned char *ptrRx; unsigned char RXData[10]; int main(void) { WDTCTL = WDTPW + WDTHOLD;//Stop the WDT to prevent reset BCSCTL1 = CALBC1_16MHZ; // Set DCO to 16MHz DCOCTL = CALDCO_16MHZ; i2c_init( ); while(1){ i2c_read_interrupt_init(RXData,1); } return 0; } //initialization void i2c_init(void){ // configure P3.1(SDA) an P3.2(SCL) for I2C P3SEL =BIT1|BIT2; P3SEL2 &=~(BIT1|BIT2); //Ensure that the USCI_B0 is reset before the configuration UCB0CTL1 |=UCSWRST; //slve adrres with 7 bit UCB0CTL1 &=~UCSLA10; //set the MSP430 to master mode UCB0CTL0 |=UCMST|UCMODE_3|UCSYNC; //take USCi clock source from SMCLK UCB0CTL1|=UCSSEL_3; //configure the baud rate registers for 100Khz when sourcing from SMCLK,SMCLK=16Mhz UCB0BR0 =80;//lower byte of UCBRx UCB0BR1 =0; //writing the slave address UCB0I2CSA =0xAA; // Clear SW reset, take the USCI module out of reset UCB0CTL1 &=~UCSWRST; // enable Rx interrupt IE2 |=UCB0RXIE; } //receive function void i2c_read_interrupt_init(unsigned char *rxbuf,unsigned char length){ unsigned char i; //receiver mode UCB0CTL1 &=~UCTR; UCB0CTL1 |= UCTXSTT; // I2C start condition while (UCB0CTL1 & UCTXSTT); // Ensure START condition got sent __bis_SR_register(LPM0 | GIE); // Enter LPM0 w/ interrupt for(i=0;i<length;i++){ while(!(IFG2&UCB0RXIFG)); //wait tiill we receive the data *rxbuf=RXByte; rxbuf++; } if(length==1){ //stop reception UCB0CTL1 |=UCTXSTP; } } // interrupt #pragma vector = USCIAB0RX_VECTOR __interrupt void USCIAB0RX_ISR(void) { //clear interrrupt flag RXByte = UCB0RXBUF; // Get RX data __bic_SR_register_on_exit(LPM0); // Exit LPM0 }
void i2c_read_interrupt_mem(unsigned char *rxbuf,unsigned char length,unsigned char MEMA){ unsigned char i; //transmitter mode for memory address UCB0CTL1 |=UCTR; //transmitter UCB0CTL1 |= UCTXSTT; // I2C start condition while (UCB0CTL1 & UCTXSTT); // Ensure START condition got sent //send memory address UCB0TXBUF=MEMA; while ((UCB0CTL1 & UCTXSTT) && (!(IFG2 & UCB0TXIFG))); // Ensure START condition got sent and memory address is being read //stop condition UCB0CTL1 |=UCTXSTP; //receiver mode UCB0CTL1 &=~UCTR; UCB0CTL1 |= UCTXSTT; // I2C start condition //receiver mode __bis_SR_register(LPM0 | GIE); // Enter LPM0 w/ interrupt for(i=0;i<length;i++){ while(!(IFG2 & UCB0RXIFG)); //wait till we receive the data *rxbuf=RXByte; rxbuf++; } if(i==1){ //stop reception UCB0CTL1 |=UCTXSTP; } }
Hi KC,
thank you for clearing my doubt.Now, i get the point. however i have modified my code according to the NTAG NFC and still my code stops at this line of code:
while (UCB0CTL1 & UCTXSTT); // Ensure START condition got sent
and while checking on the Logic Analyser,the SCL is All the time high and i see many random data on the SDA which does not make any sense
i have run my code with the address of 0x55 because i thought i have to shift it by my self and i made a mistake by choosing the clock of 200kh i get an ack with adress 0xAA.nevertheless, i have seen the SCL frequency at 200khz without any problem. but since that i keep seeing the SCL high whenever i burn the code on the msp430, which makes it weird. i run as well the last change i made to 100khz clock but still the same problem
**Attention** This is a public forum