Jump to content
StrangerM

FR6989 - internal RTS & Temperature sensor

Recommended Posts

In addition to 2 examples. Examle for FR4133.

#include <msp430.h>

#define CALADC_15V_30C  *((unsigned int *)0x1A1A)                 // Temperature Sensor Calibration-30 C
                                                                  // See device datasheet for TLV table memory mapping
#define CALADC_15V_85C  *((unsigned int *)0x1A1C)                 // Temperature Sensor Calibration-85 C

float temp;
float IntDegF;
float IntDegC;
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600) ;
   Serial.println(12);
 //   WDTCTL = WDTPW | WDTHOLD;                                     // Stop WDT

    PM5CTL0 &= ~LOCKLPM5;                                         // Disable high-impedance mode

    TA0CCTL0 |= CCIE;                                             // TACCR0 interrupt enabled
    TA0CCR0 = 65535;
    TA0CTL = TASSEL__ACLK | MC__UP;                               // ACLK, UP mode

    // Configure ADC - Pulse sample mode; ADCSC trigger
    ADCCTL0 |= ADCSHT_8 | ADCON;                                  // ADC ON,temperature sample period>30us
    ADCCTL1 |= ADCSHP;                                            // s/w trig, single ch/conv, MODOSC
    ADCCTL2 |= ADCRES;                                            // 10-bit conversion results
    ADCMCTL0 |= ADCSREF_1 | ADCINCH_12;                           // ADC input ch A12 => temp sense
    ADCIE |=ADCIE0;                                               // Enable the Interrupt request for a completed ADC_B conversion

    // Configure reference
    PMMCTL0_H = PMMPW_H;                                          // Unlock the PMM registers
    PMMCTL2 |= INTREFEN | TSENSOREN;                              // Enable internal reference and temperature sensor
  
    __delay_cycles(400);                                          // Delay for reference settling

  //  __bis_SR_register(LPM0_bits | GIE);                           // LPM3 with interrupts enabled
 //   __no_operation();                                             // Only for debugger
}

void loop()
{
 
  Serial.println(IntDegC);
 
delay(500);
}

// ADC interrupt service routine
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
{
     //  __delay_cycles(400);  
            temp = ADCMEM0;
            // Temperature in Celsius
            IntDegC = (temp-CALADC_15V_30C)*(85-30)/(CALADC_15V_85C-CALADC_15V_30C)+30;

            // Temperature in Fahrenheit
            IntDegF = 9*IntDegC/5+32;
    
}

// Timer A0 interrupt service routine

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)

{
    ADCCTL0 |= ADCENC | ADCSC;                                    // Sampling and conversion start
}

All examples were taken from MSP430Ware_3_60_00_10 and adapted for Energia

Share this post


Link to post
Share on other sites

In low-power mode. CPU is stopped & runs only in interrupt subroutine.

FR6989 - RTC & Temperature sensor by RTC interrupt 1 per sec

#include "LCD_Launchpad.h"
int n ;
int s ;
int m ;
int h ;
int d ;
int M ;
int y ;
LCD_LAUNCHPAD myLCD ;
void setup()
{
  pinMode(P1_0, OUTPUT);
  digitalWrite(P1_0,LOW) ;
  Serial.begin(9600) ;
  myLCD.init();
   WDTCTL = WDTPW | WDTHOLD;               // Stop Watchdog Timer
PJSEL0 = BIT4 | BIT5;                   // Initialize LFXT pins
  // Configure LFXT 32kHz crystal
    CSCTL0_H = CSKEY >> 8;                  // Unlock CS registers
    CSCTL4 &= ~LFXTOFF;                     // Enable LFXT
    do
    {
      CSCTL5 &= ~LFXTOFFG;                  // Clear LFXT fault flag
      SFRIFG1 &= ~OFIFG;
    } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
    CSCTL0_H = 0;                           // Lock CS registers

    // Configure RTC_C
    RTCCTL0_H = RTCKEY_H;                   // Unlock RTC
 
  //  RTCCTL0_L = RTCTEVIE | RTCRDYIE;        // enable RTC read ready interrupt
                                            // enable RTC time event interrupt

    RTCCTL1 = RTCBCD | RTCHOLD | RTCMODE;   // RTC enable, BCD mode, RTC hold
/*
    RTCYEAR = 0x2017;                       // Year = 0x2017
    RTCMON = 0x2;                           // Month = 0x02 = Feb
    RTCDAY = 0x18;                          // Day = 0x18 = 18
    RTCDOW = 0x07;                          // Day of week = 0x07 = Sun 
    RTCHOUR = 0x21;                         // Hour = 0x21
    RTCMIN = 0x46;                          // Minute = 0x46
    RTCSEC = 0x45;                          // Seconds = 0x45

    RTCADOWDAY = 0x2;                       // RTC Day of week alarm = 0x2
    RTCADAY = 0x20;                         // RTC Day Alarm = 0x20
    RTCAHOUR = 0x10;                        // RTC Hour Alarm
    RTCAMIN = 0x23;
//*/    
  RTCCTL1 &= ~(RTCHOLD);  // Start RTC
  RTCCTL0_L = RTCRDYIE;        // enable RTC read ready interrupt
                                            // enable RTC time event interrupt
  __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3 mode w/ interrupts 
}

void loop()
{
 // Serial.print(14);
  
//  Serial.println(100);
/*
 if(RTCSEC!=n){
  Serial.print(RTCSEC, HEX);
  Serial.print(":");
  Serial.print(RTCMIN, HEX);
   Serial.print(":");
  Serial.print(RTCHOUR, HEX);
   Serial.print(":");
  Serial.print(RTCDAY, HEX);
   Serial.print(":");
  Serial.print(RTCMON, HEX);
   Serial.print(":");
  Serial.println(RTCYEAR, HEX);
 n=RTCSEC ;
 //if(n==59){n=-2;}
 //RTCCTL0_L = RTCTEVIE | RTCRDYIE;        // enable RTC read ready interrupt
                                            // enable RTC time event interrupt
 //  __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3 mode w/ interrupts
*/
 }
 
}
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)

{
 // __bic_SR_register_on_exit(LPM3_bits); // Exit active CPU
 //  Serial.println(116); 
 s=RTCSEC ;
 m=RTCMIN ;
 h=RTCHOUR ;
 d=RTCDAY ;
 M=RTCMON ;
 y=RTCYEAR ;
  myLCD.clear();
  myLCD.print(h,HEX); myLCD.print(m,HEX);myLCD.println(s,HEX);
 RTCCTL0_L = RTCRDYIE; 
__bis_SR_register(LPM3_bits | GIE);
}

#include "LCD_Launchpad.h"
 #define CALADC12_12V_30C  *((unsigned int *)0x1A1A)   // Temperature Sensor Calibration-30 C
                                                      //See device datasheet for TLV table memory mapping
#define CALADC12_12V_85C  *((unsigned int *)0x1A1C)   // Temperature Sensor Calibration-85 C

unsigned int temp;
volatile float temperatureDegC;
volatile float temperatureDegF;

int n ; 
int s ; 
int m ;
int h ;
int d ;
int M ;
int y ;
LCD_LAUNCHPAD myLCD ;
void setup()
{
 // pinMode(P1_0, OUTPUT);
 // digitalWrite(P1_0,LOW) ;
 // Serial.begin(9600) ;
  myLCD.init();
   WDTCTL = WDTPW | WDTHOLD;               // Stop Watchdog Timer
   ////////////////////////////////
   REFCTL0 |= REFVSEL_0 + REFON;             // Enable internal 1.2V reference
analogReference(INTERNAL1V2) ;
   /* Initialize ADC12_A */
  ADC12CTL0 &= ~ADC12ENC;                   // Disable ADC12
  ADC12CTL0 = ADC12SHT0_8 + ADC12ON;        // Set sample time
  ADC12CTL1 = ADC12SHP;                     // Enable sample timer
  ADC12CTL3 = ADC12TCMAP;                   // Enable internal temperature sensor
  ADC12MCTL0 = ADC12VRSEL_1 + ADC12INCH_30; // ADC input ch A30 => temp sense
  ADC12IER0 = 0x001;                        // ADC_IFG upon conv result-ADCMEMO

//  while(!(REFCTL0 & REFGENRDY));            // Wait for reference generator
                                            // to settle
  ADC12CTL0 |= ADC12ENC; 
   
   ///////////////////////////////
PJSEL0 = BIT4 | BIT5;                   // Initialize LFXT pins
  // Configure LFXT 32kHz crystal
    CSCTL0_H = CSKEY >> 8;                  // Unlock CS registers
    CSCTL4 &= ~LFXTOFF;                     // Enable LFXT
    do
    {
      CSCTL5 &= ~LFXTOFFG;                  // Clear LFXT fault flag
      SFRIFG1 &= ~OFIFG;
    } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
    CSCTL0_H = 0;                           // Lock CS registers

    // Configure RTC_C
    RTCCTL0_H = RTCKEY_H;                   // Unlock RTC
 
  //  RTCCTL0_L = RTCTEVIE | RTCRDYIE;        // enable RTC read ready interrupt
                                            // enable RTC time event interrupt

    RTCCTL1 = RTCBCD | RTCHOLD | RTCMODE;   // RTC enable, BCD mode, RTC hold
/*
    RTCYEAR = 0x2017;                       // Year = 0x2017
    RTCMON = 0x2;                           // Month = 0x02 = Feb
    RTCDAY = 0x18;                          // Day = 0x18 = 18
    RTCDOW = 0x07;                          // Day of week = 0x07 = Sun 
    RTCHOUR = 0x21;                         // Hour = 0x21
    RTCMIN = 0x46;                          // Minute = 0x46
    RTCSEC = 0x45;                          // Seconds = 0x45

    RTCADOWDAY = 0x2;                       // RTC Day of week alarm = 0x2
    RTCADAY = 0x20;                         // RTC Day Alarm = 0x20
    RTCAHOUR = 0x10;                        // RTC Hour Alarm
    RTCAMIN = 0x23;
//*/    
  RTCCTL1 &= ~(RTCHOLD);  // Start RTC
 // ADC12CTL0 |= ADC12SC;                   // Sampling and conversion start
  RTCCTL0_L = RTCRDYIE;        // enable RTC read ready interrupt
                                            // enable RTC time event interrupt
  __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3 mode w/ interrupts 
}

void loop()
{
 Serial.print(14);
 
}
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)

{
 // __bic_SR_register_on_exit(LPM3_bits); // Exit active CPU
 //  Serial.println(116); 
 s=RTCSEC ;
 m=RTCMIN ;
 h=RTCHOUR ;
 d=RTCDAY ;
 M=RTCMON ;
 y=RTCYEAR ;
 temp = ADC12MEM0;
 
  temperatureDegC = (float)(((long)temp - CALADC12_12V_30C) * (85 - 30)) /
            (CALADC12_12V_85C - CALADC12_12V_30C) + 30.0f;

    // Temperature in Fahrenheit Tf = (9/5)*Tc + 32
    temperatureDegF = temperatureDegC * 9.0f / 5.0f + 32.0f;
  myLCD.clear();
  myLCD.println(temperatureDegC); //
ADC12CTL0 |= ADC12SC;      
 RTCCTL0_L = RTCRDYIE; 
__bis_SR_register(LPM3_bits | GIE);
}

FR4133 - Temperature sensor by ADC iterrupt
#include <msp430.h>
 #include "LCD_Launchpad.h"
#define CALADC_15V_30C  *((unsigned int *)0x1A1A)                 // Temperature Sensor Calibration-30 C
                                                                  // See device datasheet for TLV table memory mapping
#define CALADC_15V_85C  *((unsigned int *)0x1A1C)                 // Temperature Sensor Calibration-85 C

float temp;
float IntDegF;
float IntDegC;
LCD_LAUNCHPAD myLCD ; 
void setup()
{
  // put your setup code here, to run once:
  myLCD.init();
 // Serial.begin(9600) ;
  // Serial.println(12);
    WDTCTL = WDTPW | WDTHOLD;                                     // Stop WDT

    PM5CTL0 &= ~LOCKLPM5;                                         // Disable high-impedance mode

    TA0CCTL0 |= CCIE;                                             // TACCR0 interrupt enabled
    TA0CCR0 = 65535;
    TA0CTL = TASSEL__ACLK | MC__UP;                               // ACLK, UP mode

    // Configure ADC - Pulse sample mode; ADCSC trigger
    ADCCTL0 |= ADCSHT_8 | ADCON;                                  // ADC ON,temperature sample period>30us
    ADCCTL1 |= ADCSHP;                                            // s/w trig, single ch/conv, MODOSC
    ADCCTL2 |= ADCRES;                                            // 10-bit conversion results
    ADCMCTL0 |= ADCSREF_1 | ADCINCH_12;                           // ADC input ch A12 => temp sense
    ADCIE |=ADCIE0;                                               // Enable the Interrupt request for a completed ADC_B conversion

    // Configure reference
    PMMCTL0_H = PMMPW_H;                                          // Unlock the PMM registers
    PMMCTL2 |= INTREFEN | TSENSOREN;                              // Enable internal reference and temperature sensor
  
    __delay_cycles(400);                                          // Delay for reference settling

    __bis_SR_register(LPM3_bits | GIE);                           // LPM3 with interrupts enabled
 //   __no_operation();   // Only for debugger
  myLCD.clear();
}

void loop()
{
 // myLCD.clear();
 // myLCD.print(int(IntDegC)); myLCD.println("C");
//  Serial.println(IntDegC);
 
//delay(500);
}

// ADC interrupt service routine
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
{
     //  __delay_cycles(400);  
            temp = ADCMEM0;
            // Temperature in Celsius
            IntDegC = (temp-CALADC_15V_30C)*(85-30)/(CALADC_15V_85C-CALADC_15V_30C)+30;

            // Temperature in Fahrenheit
            IntDegF = 9*IntDegC/5+32;
             myLCD.clear();
  myLCD.print(int(IntDegC)); myLCD.println("C");
  __delay_cycles(400);
    
}

// Timer A0 interrupt service routine

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)

{
    ADCCTL0 |= ADCENC | ADCSC;                                    // Sampling and conversion start
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...