Quantcast
Channel: Wireless Connectivity
Viewing all articles
Browse latest Browse all 116964

Forum Post: RE: ez430-TMS37157 target board write to eeprom

$
0
0

So I solve the problem here is my new code:



#include <msp430f2274.h>
#include "stdlib.h"
#include "string.h"
#include "intrinsics.h"
#include "PaLFI_Transponder.h"
#include "DCO_Library.h"


#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR    TIMERA1_VECTOR
#define TIMER0_A0_VECTOR    TIMERA0_VECTOR
#endif


void lepagina();

unsigned int i,first_run;

unsigned char  status;

volatile long tempRaw;

    unsigned char ucPageData[5] = {0};        // one Page is always 5 Byte
        unsigned char ucPageDataTemp[5] = {0};        // one Page is always 5 Byte
    unsigned char ucMSPAccessData[6] = {0};    // MSP Access Data is always 6 Byte


void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);

void main(void)
{
  MSP430_SPI_Init();
  ConfigWDT();
  ConfigClocks();
  ConfigPins();
  ConfigADC10();
  ConfigTimerA2();
   _BIS_SR(GIE);
  while(1)
  {
          P1IFG|=BIT2;                                // disable interupt flag
      P2IFG|=CU_BUSY;                            // disable busy interupt flag
      P1IE&=~BIT2;                                // enable Push Button Interrupt
      P2IE&=~CU_BUSY;                            // enable Busy Interupt
 
   __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, enable interrupts
  }
}

void ConfigWDT(void)
 {
 WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
 }

void ConfigClocks(void)
 {
 if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
   FaultRoutine();                         // If calibration data is erased
                                                  // run FaultRoutine()
  BCSCTL1 = CALBC1_1MHZ;                    // Set range
  DCOCTL = CALDCO_1MHZ;                     // Set DCO step + modulation
  BCSCTL3 |= LFXT1S_2;                     // LFXT1 = VLO
  IFG1 &= ~OFIFG;                          // Clear OSCFault flag
  BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;     // MCLK = DCO/8, SMCLK = DCO/8
 }

void FaultRoutine(void)
 {
   P1OUT = BIT0;                           // P1.0 on (red LED)
   while(1);                              // TRAP
 }

void ConfigPins(void)
 {
  P1DIR = ~BIT3;                          // P1.3 input, others output
  P1OUT = 0;                              // clear output pins
 }

void ConfigADC10(void)
 {
  ADC10CTL1 = INCH_10 + ADC10DIV_0;        // Temp Sensor ADC10CLK
 }

void ConfigTimerA2(void)
 {
   CCTL0 = CCIE;                     // diz que o comparador vai usar interrupções
   CCR0 = 36000;                     // Quando o timer atingir este valor vai gerar a interrupção
   TACTL = TASSEL_1 + MC_2;          // seleciona o ACLK como entrada do timer e MC_2 coloca-o em modo continuo
 }

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
 {
  ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE ;
  __delay_cycles(4);                        // Wait for ADC Ref to settle
  ADC10CTL0 |= ENC + ADC10SC;              // Sampling and conversion start
  P1OUT |= BIT0;
  CCR0 +=36000;                               // add 6 seconds to the timer
   P1OUT &= ~BIT0;
  __bic_SR_register_on_exit(LPM3_bits + GIE);
 }

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10 (void)
 {
  ADC10CTL0 &= ~ADC10IFG;                 // clear interrupt flag
  ADC10CTL0 &= ~ENC;                       // Disable ADC conversion
  ADC10CTL0 &= ~(REFON + ADC10ON);         // Ref and ADC10 off
  tempRaw = ADC10MEM;                       // Read conversion value
  lepagina();
  if (tempRaw>725){
    P1OUT |= BIT1;
  }else{
  P1OUT &= ~BIT1;
  }  
   
  __bic_SR_register_on_exit(LPM3_bits + GIE);
 }
 
void lepagina(){
              Wake_PaLFI();                        // Wake up PaLFI
        
        UCB0CTL1 &= ~UCSWRST;                // activate SPI State machine  
        
        SPI_Read_PCU_State();                    // read PCU State
        
        SPI_Read_SerialNum();                   // First PaLFI access defines selective address! (not implemented in PaLFI)
        
        SPI_Read_UserPage(Page2,ucPageData);    // if PaLFI trimmed Page2 = 0x01
      
        SPI_Read_UserPage(Page9,ucPageData);    // read Page9, how often should green LED blink
        SPI_Program_UserPage(Page11,ucPageData);// programm Data in Page 11
                
          /*****************  Prograna quando carrega no botão   ********************/
               SPI_Read_UserPage(Page9,ucPageDataTemp);
                ucPageDataTemp[0]=tempRaw;
                SPI_Program_UserPage(Page10,ucPageDataTemp);// programm Data in Page 10
             ucPageDataTemp[2]=tempRaw;
                SPI_Program_UserPage(Page12,ucPageDataTemp);// programm Data in Page 12
                /*****************  Prograna quando carrega no botão   ********************/
        SPI_Power_Down();                        // Power down PaLFI
        
        UCB0CTL1 |= UCSWRST;                    // deactivate SPI State machine
                 P1OUT |= BIT0;
    CCR0 +=72000;                               // add 6 seconds to the timer
   P1OUT &= ~BIT0;
         
 }


Viewing all articles
Browse latest Browse all 116964

Trending Articles



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