Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 216565

Forum Post: RE: Source code for reading a TMP006 with an MSP430?

$
0
0

[quote user="Gaurav Pratim Talukdar"]#define slv_addr_tx 0x80
#define slv_addr_rx 0x81[/quote]

There is only one slave address, and it is the same for read and write. And it is 7 bit. What you define here, is the start byte, which contains the slave address and the R/W bit. The USIC assembles the start byte automatically, taking the slave address and the (inverted) UCTR bit.

 [quote user="Gaurav Pratim Talukdar"]case 10:                                                         // Vector 10: RXIFG
            temp_MSB = UCB1RXBUF;                 // Move RX data to address PRxData
            temp_LSB = UCB1RXBUF;
            UCB1CTL1 |= UCTXSTP;                      // Generate I2C stop condition
[/quote]

You only get one byte at a time. Reading RXBUF doesn’t wait until a new byte has arrived. When you get the RX interrupt, you got one byte. You need to count how many you received, and set the stop when there is only one left (because when the interrupt comes, you not only received a byte, but receiving the next has already started).

 [quote user="Gaurav Pratim Talukdar"]/* ------------------Transmit slave address (write) and get acknowledgement-------------------*/

UCB1I2CSA = 0x80;
UCB1CTL1 |= UCTXSTT;                                                       // I2C start condition[/quote]

As I already said, you do not have to set the slave address separately. Set it once when you decide to talk to this device.
But for transmitting, you need to set the UCTR bit (and to receive later, you need to clear it again). Either before or when you set UTXSTT.

 [quote user="Gaurav Pratim Talukdar"]case 12:                                                         // Vector 12: TXIFG
            UCB1TXBUF = internal_reg_addr_T;      // Load TX buffer to transmit register address
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
            break;[/quote]

Here again, you need to count the number of bytes you send. You either send something, or, when there is nothing more to send, set UCTXSTP (unless you want to do a repeated start – in this case clear UCTXIFG, so the USCI doesn’t ask for more bytes to send)


Viewing all articles
Browse latest Browse all 216565

Trending Articles



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