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, I have posted in the forum about this before and have gotten some much appreciated help but I am still struggling with getting my code to work. Let me state that I am very new to this and alot of this has been very confusing. I have read through the TMP101 datasheet and some of the 430 datasheet but a lot of it still does not make sense. I have reached a point where I can ask some questions that I hope can make some sense to someone out there. Please respond with the fact in mind that I am a beginner. Thank you. Alot of this code is snippets I took from example code and changed some stuff to try and make it work to do what I need. In my code, I activate and map out the ports in the Initialize function in my code. After that, the code goes through what I call the mainLoop. This is just a continous while loop. In the loop, it comes to a line of code that says _bis_SR_register(CPUOFF + GIE) [I have highlighted this in red in the code]. From the datasheet, I get that this is some sort of low power mode and apparently it only exits this mode when an interrupt occurs. The problem I'm having is understanding if my code is actually executing the USCI_B0_ISR that is supposed to return an int variable entitled RxWord that corresponds to the temperature. That is the part of the code I am just lost on right now. I also don't understand the TimerA interrupt that occurs in the same loop (I have also highlighted this line of code in red). The loop came from an example code from TI so I assume that it is correct but I already have found some discrepancies so I'm not sure. Here is the code and thanks in advance for the help:
//******************************************************************************
// CC430F613x Demo - USCI_B0 I2C Master RX single bytes from MSP430 Slave
//
// Description: This demo connects two MSP430's via the I2C bus. The master
// reads from the slave. This is the MASTER CODE. The data from the slave
// transmitter begins at 0 and increments with each transfer. The received
// data is in R5 and is checked for validity. If the received data is
// incorrect, the CPU is trapped and the P1.0 LED will stay on. The USCI_B0
// RX interrupt is used to know when new data has been received.
// ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1.045MHz
#include "cc430x613x.h"
//#define RED_LED BIT6
#define GRN_LED BIT0
unsigned int RxByteCtr;
unsigned int RxWord = 0;
//volatile unsigned char RxBuffer[1]; // Allocate 128 byte of RAM
void Initialize(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1OUT = 0xFF; //Enables Port 1 Output as 1111 1111 (binary) //Outputs are all high
;
P1DIR |= GRN_LED;
PMAPPWD = 0x02D52; // Get write-access to port mapping registers//Same as PMAPKEYID-Chapter 9 FamilyUsersGuide
P2MAP6 = PM_UCB0SDA; // Map UCB0SDA output to P2.6//USCI_B0 I2C data (open drain and direction controlled by USCI) /page 323 FamilyUsersGuide
P2MAP7 = PM_UCB0SCL; // Map UCB0SCL output to P2.7 //USCI_B0 I2C clock
PMAPPWD = 0; // Mapping complete, lock port mapping registers with an invalid key (anything other than 0x02D52)
P2SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0 By OR'ing.
UCB0CTL1 |= UCSWRST; // Enable software reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // UCMST Selects Master Mode, UCSYNC is bit 0-enables Synchronous Mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; / fSCL = SMCLK/12 = ~100kHz //SMCLK runs at apprx. 1MHZ, which would actually be fSCL=83.3kHz
UCB0BR1 = 0;
//UCB0BR0 and UCB0BR1 work together to form a prescaler value, not sure how it works Pg 523 of FUG
UCB0I2CSA = 0x48;
// Set slave address //UCB0I2CSA is the Slave Address Register pg. 525 FUG //The master must first address slave devices via a slave address byte. 0x48 corresponds
//to the slave address 0100 1000 given in Table 12 of the TMP101 datasheet pg 8.
UCB0CTL1 &= ~UCSWRST;// Clear software reset, resume operation//
UCB0IE |= UCRXIE; // Enable RX interrupt
TA1CTL = TASSEL_2 + MC_2; // ACLK, upmode, clear TAR --?
}
void mainLoop(void)
{
while(1)
{
RxByteCtr = 2; // Load RX byte counter //2 bytes
UCB0CTL1 |= UCTXNACK;
UCB0CTL1 |= UCTXSTT; // I2C start condition // UCB0CTL1 Register pg. 523 FUG)
__bis_SR_register(CPUOFF + GIE); // Enter LPM0, enable interrupts //LMP0 --Table 1-2 Operation Modes pg. 32 FUG
//The bis_SR_register is a low power mode that will not exit until interrupt occurs -- I think.
//UCSCTL6 &= ~SMCLKOFF;---Do I need this?
// Remain in LPM0 until all data
// is RX'd
if(RxWord < 000110010000)//25 deg C
P1OUT |= 0x01;
// Yes, P1.0 = 1
else
P1OUT &= ~0x01;
// No, P1.0 = 0
__disable_interrupt();
TA1CCTL0 = CCIE;
__bis_SR_register(CPUOFF + GIE); // Enter LPM0, enable interrupts
TA1CCTL0 &= ~CCIE; // Remain in LPM0 until TACCR0 ----WHAT DOES THIS MEAN???
TA1CCTL0 &= ~CCIE;
}
}
void main(void)
{
Initialize();
mainLoop();
}
// The USCIAB0TX_ISR is structured such that it can be used to receive any
// 2+ number of bytes by pre-loading RxByteCtr with the byte count.
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
if (RxByteCtr) //if RxByteCtr not equal to 0?
{
RxWord = UCB0RXBUF << 4; // Get received byte
RxByteCtr--; // Decrement RX byte counter
if (RxByteCtr == 1) // Only one byte left?
RxWord |= UCB0RXBUF >> 4; // Get final received byte // Combine MSB and LSB
}
else
{
RxWord = UCB0RXBUF; /Should never happen in the code..Not even really needed.
}
UCB0CTL1 |= UCTXNACK;
UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
// Timer A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
**Attention** This is a public forum