Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

USCI I2C : Sending single byte without ISR

$
0
0

Hi!

I'm trying to send a single byte over UCSI B0 configured as I2C with the following function. The initialization code of the I2C is not shown. My problem is that if I run the function without debugging line-by-line, only the START condition and the address are transmitted and then comes the STOP condition (as observed at the scope). On the other hand, if I debug the function with the debugger, I can see that after the address, then comes the transmitted data and then the STOP condition.

I guess that the problem is that I set the UCTXSTP bit before the data in the TXBUF has started transmission, that's why only the address is transmitted and then the STOP condition. However, I cannot understand where is the error in my code  and what else should I do, since after loading my data at the TXBUF, I wait until the TXSTT bit has been cleared and then I set the TXSTP bit. Is there another way to understand when the data in the TXBUF has started to be transmitted?

By the way I don't wish to have an ISR handling with all these, since I call this function from another ISR and this creates some difficulties.

Thank you,

Nikos

 

//===========================================================================

void I2c_TxSingleByte (u8t txByte)

//===========================================================================

{

UCB0CTL1 |= UCTR + UCTXSTT;// I2C transmitter mode (TX), send START condition

while (UCB0IFG & !UCTXIFG);// Wait until start condition has been sent

UCB0IFG &= ~UCTXIFG;// Clear USCI TX int flag

UCB0TXBUF = *PTxData++;// Load TX buffer

while (UCB0CTL1 & !UCTXSTT);// Ensure start condition got sent

UCB0IFG &= ~UCTXIFG;// Clear USCI TX int flag

UCB0CTL1 |= UCTXSTP;// I2C stop condition

while (UCB0CTL1 & UCTXSTP);// Ensure stop condition got sent

}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>