Jump to content
43oh

gwdeveloper

Members
  • Content Count

    618
  • Joined

  • Last visited

  • Days Won

    22

Posts posted by gwdeveloper

  1. Cool.  Are you involving him in the project? 

     

    Also, have you thought about adding a parental alert system?  Something simple that sounds an alarm when, for example, said nephew is actually planking between the tub and sink with the toothbrush hanging idly from his mouth instead of brushing.  Or maybe that's only my kid...

  2. @chicken  Perfect; that was the library I previously tried but no luck.  You've solved the issue with the PxSEL.

     

    I'm going to download and try your pins_energia.h.  Your pin numbering scheme was different than mine; I followed the same protocol as other boards with starting at 1 going counter clockwise to 18.  Also a few extra defines were added for my own convenience.

     

    Did you get Fade working with your pins file?  I bet we could wrap up this variant pretty quickly.

  3. Galago UltraPro arrived yesterday evening.  Very nice machine.  The display is bright and crisp.  My only complaint is the trackpad is a bit touchy; never been too fond of them anyway so wireless mouse it is.  Already up and running with CCS v6 too.

     

    post-136-0-67143400-1395943848_thumb.jpg

  4. I still don't have a new F5529 Launchpad but wanted to tinker a bit more with Energia.  Added another variant to use the MSP-EXP430F5529 http://www.ti.com/tool/msp-exp430f5529 It is not complete but the leds, buttons, i2c, and debug uart are all working.  Next is wrapping up the timers then adding drivers for the on-board LCD, SD and Accelerometer.

     

    Add this to /energia/hardware/msp430/boards.txt

    lpmsp430f5529_25.name=exp-msp430f5529 (25MHz)
    lpmsp430f5529_25.upload.protocol=tilib
    lpmsp430f5529_25.upload.maximum_size=131072
    lpmsp430f5529_25.build.mcu=msp430f5529
    lpmsp430f5529_25.build.f_cpu=25000000L
    lpmsp430f5529_25.build.core=msp430
    lpmsp430f5529_25.build.variant=exp_f5529
    lpmsp430f5529_25.upload.maximum_ram_size=1024
    

    And create /energia/hardware/msp430/variants/exp_f5529/pins_energia.h

    /*
      ************************************************************************
      *	pins_energia.h
      *
      *	Energia core files for MSP430
      *		Copyright (c) 2012 Robert Wessels. All right reserved.
      *
      *     Contribution: Rei VILO
      *
      ***********************************************************************
      Derived from:
      pins_arduino.h - Pin definition functions for Arduino
      Part of Arduino - http://www.arduino.cc/
    
      Copyright (c) 2007 David A. Mellis
    
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
      License as published by the Free Software Foundation; either
      version 2.1 of the License, or (at your option) any later version.
    
      This library is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Lesser General Public License for more details.
    
      You should have received a copy of the GNU Lesser General
      Public License along with this library; if not, write to the
      Free Software Foundation, Inc., 59 Temple Place, Suite 330,
      Boston, MA  02111-1307  USA
    */
    
    #ifndef Pins_Energia_h
    #define Pins_Energia_h
    #ifndef BV
    #define BV(x) (1 << (x))
    #endif
    
    #if defined(__MSP430_HAS_USCI_A0__) || defined(__MSP430_HAS_USCI_A1__)
    
    static const uint8_t SS      = 8;  /* P2.7 */
    static const uint8_t SCK     = 7;  /* P3.2 */
    static const uint8_t MOSI    = 15;  /* P3.0 */
    static const uint8_t MISO    = 14;  /* P3.1 */
    
    static const uint8_t TWISDA  = 37;  /* P3.0 */
    static const uint8_t TWISCL  = 26;  /* P3.1 */
    
    static const uint8_t DEBUG_UARTRXD = 2;  /* Receive  Data (RXD) at P4.5 */
    static const uint8_t DEBUG_UARTTXD = 3;  /* Transmit Data (TXD) at P4.4 */
    static const uint8_t AUX_UARTRXD = 2;  /* Receive  Data (RXD) at P4.5 */
    static const uint8_t AUX_UARTTXD = 3;  /* Transmit Data (TXD) at P4.4 */
    
    #define TWISDA_SET_MODE (PORT_SELECTION0)
    #define TWISCL_SET_MODE (PORT_SELECTION0)
    #define DEBUG_UARTRXD_SET_MODE (PORT_SELECTION0 | (PM_UCA1RXD << 8) | INPUT)
    #define DEBUG_UARTTXD_SET_MODE (PORT_SELECTION0 | (PM_UCA1TXD << 8) | OUTPUT)
    #define AUX_UARTRXD_SET_MODE (PORT_SELECTION0 | INPUT)
    #define AUX_UARTTXD_SET_MODE (PORT_SELECTION0 | OUTPUT)
    #define SPISCK_SET_MODE (PORT_SELECTION0)
    #define SPIMOSI_SET_MODE (PORT_SELECTION0)
    #define SPIMISO_SET_MODE (PORT_SELECTION0)
    #endif
    
    #define DEBUG_UART_MODULE_OFFSET 0x40
    #define AUX_UART_MODULE_OFFSET 0x0
    #define SERIAL1_AVAILABLE 1
    
    #if defined(__MSP430_HAS_USCI_A1__)
    #define USE_USCI_A1
    #endif
    
    static const uint8_t A0  = 0;
    static const uint8_t A1  = 1;
    static const uint8_t A2  = 2;
    static const uint8_t A3  = 3;
    static const uint8_t A4  = 4;
    static const uint8_t A5  = 5;
    static const uint8_t A6  = 6;
    static const uint8_t A7  = 7;
    static const uint8_t A10 = 10; // special. This is the internal temp sensor
    static const uint8_t A11  = 11;
    static const uint8_t A12  = 12;
    static const uint8_t A13  = 13;
    static const uint8_t A14  = 14;
    static const uint8_t A15  = 15;
    
    /*
     F5529 LaunchPad pin mapping ( * indicates redundancy)
     
    								J4
                                   +--\/--+
                              3.3v |1   12| P6.6 (CB6, A6)
               (UCA1RXD/SOMI) P4.5 |2   11| P8.1 (GPIO - LED2)
               (UCA1TXD/SIMO) P4.4 |3   10| P8.2 (GPIO - LED3)
    		      (GPIO - RF) P4.6 |4    9| P8.0 (GPIO - POT)
                  (GPIO - RF) P4.7 |5    *| P4.5 (UCA1RXD/SOMI)
                         (A9) P5.1 |6    *| P4.4 (UCA1TXD/SIMO)
                               GND |7    8| P6.7 (CB7, A7)
    							   +------+
    */
    /*						   		
    								J5
                                    +--\/--+
                               3.3v |13  24| P7.0 (CB8, A12)
           (UCB1SOMI/SCL - SD) P4.2 |14  23| P7.1 (CB9, A13)
       (UCB1SIMO/SDA - LCD/SD) P4.1 |15  22| P7.2 (CB10, A14)
    (UCB1CLK/UCA1STE - LCD/SD) P4.3 |16  21| P7.3 (CB11, A15)
        (UCB1STE/UCA1CLK - RF) P4.0 |17   *| P4.1 (UCB1SIM0/UCB1SDA - LCD/SD)
        (TB0OUTH, SVMOUT - SD) P3.7 |18   *| P4.2 (UCB1SOMI/UCB1SCL - SD)
                                GND |19  20| P7.7 (TB0CLK)
    								+------+
    */
    /*						
    								 J12
                                   +--\/--+
               (UCB0STE - RF) P2.6 |25  37| P3.0 (UCB0SIMO - RF)
              (UCB0SOMI - RF) P3.1 |26  36| P3.2 (UCB0CLK - RF)
            (TA2.0 - RF_GDO0) P2.3 |27  35| P2.1 (TA1.2 - RF_GDO2)
    		          (TB0.3) P7.5 |28  34| GND
                       (GPIO) P4.7 |*   33| P2.4 (TA2.1)
               (UCA1RXD/SOMI) P4.5 |*    *| P4.6 (GPIO)
       		   (UCA1TXD/SIMO) P4.4 |*    *| P4.0 (UC 1)
                (GPIO - LED2) P1.0 |29  32| P2.0 (TA1.1)
    						   GND |30  31| VCC
    							   +------+
    */
    /*
    					  ----+
    						38| P1.7 (PUSH1)
                            39| P2.2 (PUSH2)
    						
                           *29| P1.0 (LED1)
                           *11| P8.1 (LED2)
    					   *10| P8.2 (LED3)
    					    *9| P8.0 (POT_EN)
    						
    						40| P6.5 (POT_READ - A5)
    					
    					TOUCHPADS
    						41| P1.1 (TA0.0)
    						46| P6.0 (CB0)
    						42| P1.2 (TA0.1)
    						47| P6.1 (CB1)
    						43| 53| P1.3 (TA0.2)
    						48| P6.2 (CB2)
    						44| P1.4 (TA0.3)
    						49| P6.3 (CB3)
    						45| P1.5 (TA0.4)
    						50| P6.4 (CB4)
    */
    /*								   
    					ACCEL-UCA0
    						51| P3.6 (ACCEL_PWR)
    						52| P3.4 (ACCEL_SOMI)
    						53| P3.3 (ACCEL_SIMO)
    						54| P2.7 (ACCEL_SCLK)
    						55| P2.5 (ACCEL_INT)
    						56| P3.5 (ACCEL_CS)
    								   
    					ezFET-UCA1
                            *2| P4.5 (UCA1RXD -> ezFET -> Serial)
                            *3| P4.4 (UCA1TXD -> ezFET -> Serial)
    */
    /*								   
    					LCD-UCB1
    						57| P5.7 (LCD_RST)
    					   *15| P4.1 (LCD_SIMO)
    					   *16| P4.3 (LCD_SCLK)
    						58| P5.6 (LCD_D/C)
    						59| P7.4 (LCD_CS)
    						60| P7.6 (LCD_BL_EN)
    								   
    					SD-UCB1
    					   *14| P4.2 (SD_SOMI - DO)
    					   *15| P4.1 (SD_SIMO - DI)
    					   *16| P4.3 (SD_SCLK)
    					   *18| P3.7 (SD_CS)								   
                          ----+
    */
    
    /* Pin names based on the silkscreen */
    
    /* PIN1 = 3.3v */
    static const uint8_t P4_5 = 2;
    static const uint8_t P4_4 = 3;
    static const uint8_t P4_6 = 4;
    static const uint8_t P4_7 = 5;
    static const uint8_t P5_1 = 6;
    /* PIN7 is GND */
    static const uint8_t P6_7 = 8;
    static const uint8_t P8_0 = 9;
    static const uint8_t P8_2 = 10;
    static const uint8_t P8_1 = 11;
    static const uint8_t P6_6 = 12;
    /* PIN13 = 3.3v */
    static const uint8_t P4_2 = 14;
    static const uint8_t P4_1 = 15;
    static const uint8_t P4_3 = 16;
    static const uint8_t P4_0 = 17;
    static const uint8_t P3_7 = 18;
    /* PIN19 is GND */
    static const uint8_t P7_7 = 20;
    static const uint8_t P7_3 = 21;
    static const uint8_t P7_2 = 22;
    static const uint8_t P7_1 = 23;
    static const uint8_t P7_0 = 24;
    static const uint8_t P2_6 = 25;
    static const uint8_t P3_1 = 26;
    static const uint8_t P2_3 = 27;
    static const uint8_t P7_5 = 28;
    static const uint8_t P1_0 = 29;
    /* PIN30 is GND */
    /* PIN31 = 3.3v */
    static const uint8_t P2_0 = 32;
    static const uint8_t P2_4 = 33;
    /* PIN34 is GND */
    static const uint8_t P2_1 = 35;
    static const uint8_t P3_2 = 36;
    static const uint8_t P3_0 = 37;
    
    static const uint8_t P6_5 = 40;
    
    /* Extra pins not on the header + temp sensor */
    static const uint8_t PUSH1 = 38;
    static const uint8_t PUSH2 = 39;
    static const uint8_t RED_LED = 29;
    static const uint8_t GREEN_LED = 10;
    static const uint8_t ORANGE_LED = 11;
    static const uint8_t POT_ENABLE = 9;
    static const uint8_t POT_ANALOG = 40;
    static const uint8_t TEMPSENSOR = 10;
    
    #ifdef ARDUINO_MAIN
    
    const uint16_t port_to_input[] = {
    	NOT_A_PORT,
    	(uint16_t) &P1IN,
    	(uint16_t) &P2IN,
    #ifdef __MSP430_HAS_PORT3_R__
    	(uint16_t) &P3IN,
    #endif
    #ifdef __MSP430_HAS_PORT4_R__
    	(uint16_t) &P4IN,
    #endif
    #ifdef __MSP430_HAS_PORT5_R__
    	(uint16_t) &P5IN,
    #endif
    #ifdef __MSP430_HAS_PORT6_R__
    	(uint16_t) &P6IN,
    #endif
    #ifdef __MSP430_HAS_PORT7_R__
    	(uint16_t) &P7IN,
    #endif
    #ifdef __MSP430_HAS_PORT8_R__
    	(uint16_t) &P8IN,
    #endif
    };
    
    const uint16_t port_to_output[] = {
    	NOT_A_PORT,
    	(uint16_t) &P1OUT,
    	(uint16_t) &P2OUT,
    #ifdef __MSP430_HAS_PORT3_R__
    	(uint16_t) &P3OUT,
    #endif
    #ifdef __MSP430_HAS_PORT4_R__
    	(uint16_t) &P4OUT,
    #endif
    #ifdef __MSP430_HAS_PORT5_R__
    	(uint16_t) &P5OUT,
    #endif
    #ifdef __MSP430_HAS_PORT6_R__
    	(uint16_t) &P6OUT,
    #endif
    #ifdef __MSP430_HAS_PORT7_R__
    	(uint16_t) &P7OUT,
    #endif
    #ifdef __MSP430_HAS_PORT8_R__
    	(uint16_t) &P8OUT,
    #endif
    };
    
    const uint16_t port_to_dir[] = {
    	NOT_A_PORT,
    	(uint16_t) &P1DIR,
    	(uint16_t) &P2DIR,
    #ifdef __MSP430_HAS_PORT3_R__
    	(uint16_t) &P3DIR,
    #endif
    #ifdef __MSP430_HAS_PORT4_R__
    	(uint16_t) &P4DIR,
    #endif
    #ifdef __MSP430_HAS_PORT5_R__
    	(uint16_t) &P5DIR,
    #endif
    #ifdef __MSP430_HAS_PORT6_R__
    	(uint16_t) &P6DIR,
    #endif
    #ifdef __MSP430_HAS_PORT7_R__
    	(uint16_t) &P7DIR,
    #endif
    #ifdef __MSP430_HAS_PORT8_R__
    	(uint16_t) &P8DIR,
    #endif
    };
    
    const uint16_t port_to_ren[] = {
    	NOT_A_PORT,
    	(uint16_t) &P1REN,
    	(uint16_t) &P2REN,
    #ifdef __MSP430_HAS_PORT3_R__
    	(uint16_t) &P3REN,
    #endif
    #ifdef __MSP430_HAS_PORT4_R__
    	(uint16_t) &P4REN,
    #endif
    #ifdef __MSP430_HAS_PORT5_R__
    	(uint16_t) &P5REN,
    #endif
    #ifdef __MSP430_HAS_PORT6_R__
    	(uint16_t) &P6REN,
    #endif
    #ifdef __MSP430_HAS_PORT7_R__
    	(uint16_t) &P7REN,
    #endif
    #ifdef __MSP430_HAS_PORT8_R__
    	(uint16_t) &P8REN,
    #endif
    };
    
    const uint16_t port_to_sel0[] = {  /* put this PxSEL register under the group of PxSEL0 */
    	NOT_A_PORT,
    	(uint16_t) &P1SEL,
    	(uint16_t) &P2SEL,
    #ifdef __MSP430_HAS_PORT3_R__
    	(uint16_t) &P3SEL,
    #endif
    #ifdef __MSP430_HAS_PORT4_R__
    	(uint16_t) &P4SEL,
    #endif
    #ifdef __MSP430_HAS_PORT5_R__
    	(uint16_t) &P5SEL,
    #endif
    #ifdef __MSP430_HAS_PORT6_R__
    	(uint16_t) &P6SEL,
    #endif
    #ifdef __MSP430_HAS_PORT7_R__
    	(uint16_t) &P7SEL,
    #endif
    #ifdef __MSP430_HAS_PORT8_R__
    	(uint16_t) &P8SEL,
    #endif
    };
    
    const uint16_t port_to_pmap[] = {
    	NOT_A_PORT,	/* PMAP starts at port P1 */
    	NOT_A_PORT,
    	NOT_A_PORT,
    	NOT_A_PORT,
    	(uint16_t) &P4MAP0,
    	NOT_A_PORT,
    	NOT_A_PORT,
    	NOT_A_PORT,
    	NOT_A_PORT,
    };
    
    const uint8_t digital_pin_to_timer[] = {
    	NOT_ON_TIMER, /*  dummy */
    	NOT_ON_TIMER, /*  1 - 3.3v */
    	T0B0,         /*  2 - P5.6 */
    	NOT_ON_TIMER, /*  3 - P3.4 */
    	NOT_ON_TIMER, /*  4 - P3.3 */
    	NOT_ON_TIMER, /*  5 - P1.6 */
    	NOT_ON_TIMER, /*  6 - P6.6 */
    	NOT_ON_TIMER, /*  7 - P3.2 */
    	NOT_ON_TIMER, /*  8 - P2.7 */
    	NOT_ON_TIMER, /*  9 - P4.2 */
    	NOT_ON_TIMER, /* 10 - P4.1 */
    	NOT_ON_TIMER, /* 11 - P8.1 */
    	T2A0,         /* 12 - P2.3 */
    	NOT_ON_TIMER, /* 13 - P2.6 */
    	NOT_ON_TIMER, /* 14 - P3.2 */
    	NOT_ON_TIMER, /* 15 - P3.0 */
    	NOT_ON_TIMER, /* 16 - RST */
    	T0B2,         /* 17 - P7.4 */
    	NOT_ON_TIMER, /* 18 - P2.2 */
    	T1A1,         /* 19 - P2.0 */
    	NOT_ON_TIMER, /* 20 - GND  */
    	NOT_ON_TIMER, /* 21 - 5.0v */
    	NOT_ON_TIMER, /* 22 - GND */
    	NOT_ON_TIMER, /* 23 - P6.0 */
    	NOT_ON_TIMER, /* 24 - P6.1 */
    	NOT_ON_TIMER, /* 25 - P6.2 */
    	NOT_ON_TIMER, /* 26 - P6.3 */
    	NOT_ON_TIMER, /* 27 - P6.4 */
    	NOT_ON_TIMER, /* 28 - P7.0 */
    	T0B6,         /* 29 - P3.6 */
    	T0B5,         /* 30 - P3.5 */
    	NOT_ON_TIMER, /* 31 - P8.2 */
    	NOT_ON_TIMER, /* 32 - P3.7 */
    	NOT_ON_TIMER, /* 33 - P4.0 */
    	NOT_ON_TIMER, /* 34 - P4.3 */
    	T0A1,         /* 35 - P1.2 */
    	T0A2,         /* 36 - P1.3 */
    	T0A3,         /* 37 - P1.4 */
    	T0A4,         /* 38 - P1.5 */
    	T2A1        /* 39 - P2.4 */
    };
    
    const uint8_t digital_pin_to_port[] = {
    	NOT_A_PIN, /* dummy */
    	NOT_A_PIN, /* 1 */
    	P4,        /* 2 */
    	P4,        /* 3 */
    	P4,        /* 4 */
    	P4,        /* 5 */
    	P5,        /* 6 */
    	NOT_A_PIN,        /* 7 */
    	P6,        /* 8 */
    	P8,        /* 9 */
    	P8,        /* 10 */
    	P8,        /* 11 */
    	P6,        /* 12 */
    	NOT_A_PIN,        /* 13 */
    	P4,        /* 14 */
    	P4,        /* 15 */
    	P4,		   /* 16 */
    	P4,        /* 17 */
    	P3,        /* 18 */
    	NOT_A_PIN,        /* 19 */
    	P7, /* 20 */
    	P7, /* 21 */
    	P7, /* 22 */
    	P7,        /* 23 */
    	P7,        /* 24 */
    	P2,        /* 25 */
    	P3,        /* 26 */
    	P2,        /* 27 */
    	P7,        /* 28 */
    	P1,        /* 29 */
    	NOT_A_PIN,        /* 30 */
    	NOT_A_PIN,        /* 31 */
    	P2,        /* 32 */
    	P2,        /* 33 */
    	NOT_A_PIN,        /* 34 */
    	P2,        /* 35 */
    	P3,        /* 36 */
    	P3,        /* 37 */
    	P1,        /* 38 */
    	P2        /* 39 */
    };
    
    const uint8_t digital_pin_to_bit_mask[] = {
    	NOT_A_PIN, /* 0,  pin count starts at 1 */
    	NOT_A_PIN, /* 1 */
    	BV(5),     /* 2 */
    	BV(4),     /* 3 */
    	BV(6),     /* 4 */
    	BV(7),     /* 5 */
    	BV(1),     /* 6 */
    	NOT_A_PIN,     /* 7 */
    	BV(7),     /* 8 */
    	BV(0),     /* 9 */
    	BV(2),     /* 10 */
    	BV(1),     /* 11 */
    	BV(6),     /* 12 */
    	NOT_A_PIN,     /* 13 */
    	BV(2),     /* 14 */
    	BV(1),     /* 15 */
    	BV(3), /* 16 */
    	BV(0),     /* 17 */
    	BV(7),     /* 18 */
    	NOT_A_PIN,     /* 19 */
    	BV(7), /* 20 */
    	BV(1), /* 21 */
    	BV(2), /* 22 */
    	BV(1),     /* 23 */
    	BV(0),     /* 24 */
    	BV(6),     /* 25 */
    	BV(1),     /* 26 */
    	BV(3),     /* 27 */
    	BV(5),     /* 28 */
    	BV(0),     /* 29 */
    	NOT_A_PIN,     /* 30 */
    	NOT_A_PIN,     /* 31 */
    	BV(0),     /* 32 */
    	BV(4),     /* 33 */
    	NOT_A_PIN,     /* 34 */
    	BV(1),     /* 35 */
    	BV(2),     /* 36 */
    	BV(0),     /* 37 */
    	BV(7),     /* 38 */
    	BV(2)     /* 39 */
    };
    #endif // #ifdef ARDUINO_MAIN
    #endif // #ifndef Pins_Energia_h
    
    

    And a simple example to read the on-board potentiometer and output to serial monitor.

    /*
      AnalogReadSerial
      Enables on-board potentiometer on P8.0 and reads an
      analog input from on-board potentiometer on A5(P6.5); 
      prints the result to the serial monitor.
      
      Hardware Required:
      * MSP-EXP430F5529 (Not the F5529 LP)
    
      This example code is in the public domain.
    */
    
    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
      pinMode(POT_ENABLE, OUTPUT);    // set P8.0 to output
      digitalWrite(POT_ENABLE, HIGH); // set P8.0 high to enable Potentiometer
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
      // read the input on analog pin A5:
      int sensorValue = analogRead(A5);
      // print out the value you read:
      Serial.println(sensorValue);
      delay(100); // delay in between reads for stability
    }
    
  5. Make sure you have this part correct; take note of the &.

    
    int sendByte_getBytes( unsigned char reg_to_read, int bytes_to_rx )
    {
        //i = 0;
    
        i2c_tx_init();
    
        __delay_cycles(1000);
    
        PTxData = ( unsigned char *)&reg_to_read;                     //TX ARRAY START ADRESS
        TXByteCtr = sizeof reg_to_read;                                  //LOAD TX BYTE COUNTER
    ...
    
  6. I commented out all the code you added.  Seems to be working fine now.  It runs very slow as you have not set your clock speed, so I believe the default is 1Mhz.  Use CCS to watch data for bmp_temp and bmp_pres; you can also check ac1, ac2, ac3...

    #include <msp430.h>
    #include <stdlib.h>
    
    //BMP085 DEFINES
    #define BMP180_ADDR                    0x77
    #define BMP180_CTRL_REG             0xF4
    #define BMP180_TEMPERATURE_REG         0x2E
    #define BMP180_PRESSURE_REG         0x34                                    //oss = 0
    //#define BMP180_PRESSURE_REG_OSS1     0x74                                    //oss = 1, LONGER DELAY NEEDED 7.5ms
    //#define BMP180_PRESSURE_REG_OSS2     0xB4                                     //oss = 2, LONGER DELAY NEEDED 13.5ms
    //#define BMP180_PRESSURE_REG_OSS3     0xF4                                     //oss = 3, LONGER DELAY NEEDED 25.5ms
    #define BMP180_MSB_REG                0xF6
    #define BMP180_LSB_REG                0xF7
    #define BMP180_CONV_REG_XLSB         0xF8
    
    //BMP085 FUNCTIONS
    void bmp180_calibration(void);
    unsigned int bmp180_ut(void);
    unsigned long bmp180_up(void);
    void get_bmp180(void);
    
    //I2C FUNCTIONS
    void i2c_tx_init(void);
    void i2c_rx_init(void);
    void start_TX(void);
    void start_RX(void);
    int sendByte_getBytes(unsigned char reg_to_read, int bytes_to_rx);
    
    
    //VARIABLES
    //int i = 1;
    int ac1;
    int ac2;
    int ac3;
    unsigned int ac4;
    unsigned int ac5;
    unsigned int ac6;
    int b1;
    int b2;
    int mb;
    int mc;
    int md;
    
    
    //TRUE PRESSURE AND TEMPERATURE
    long ut;
    long x1;
    long x2;
    long b5;
    int bmp_temp = 0;
    long up;
    long x3;
    long b3;
    unsigned long b4;
    long b6;
    unsigned long b7;
    long p;
    volatile long bmp_pres = 0;
    
    
    //TIMER_B VARIABLES
    //long first_pres = 0;
    //int k = 1;
    
    //TX CONSTANTS
    const unsigned char utTxData[] = { BMP180_CTRL_REG, BMP180_TEMPERATURE_REG };   //UNCONPENSATED TEMPERATURE REGISTER
    const unsigned char upTxData[] = { BMP180_CTRL_REG, BMP180_PRESSURE_REG };        //UNCOMPENSATED PRESSURE REGISTER
    const unsigned char msbData[] = { BMP180_MSB_REG };
    
    //I2C VARIABLES
    unsigned char *PTxData;                                                             //POINTER TO TX DATA
    volatile unsigned int TXByteCtr = 0;
    
    unsigned char *PRxData;                                                         //POINTER TO RX DATA
    volatile unsigned int RXByteCtr = 0;
    volatile unsigned char RxBuffer[3];                                               //ALLOCATE 3 BYTES OF RAM
    
    
    void main(void)
    {
        WDTCTL = WDTPW + WDTHOLD;                                                     //STOP WDT
    
        P3SEL |= 0x03;                                                                //ASSIGN I2C PINS TO USCI_B0
        UCB0CTL1 |= UCSWRST;                                                          //ENABLE SW RESET
        UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;                                         //I2C MASTER, SYNCHRONOUS MODE
        UCB0CTL1 = UCSSEL_2 + UCSWRST;                                                //USE SMCLK, KEEP SW RESET
    
        UCB0BR0 = 0;                                                                //FSCL = SMCLK/12 =~ 100kHz
        UCB0BR1 = 0;
    
        UCB0CTL1 &= ~UCSWRST;                                                         //CLEAR SW RESET, RESUME OPERATION
    
        /*
        P1DIR |= 0x01;
        P1OUT &= ~0x01;
    
        P6DIR |= 0x04;
        P6OUT &= ~0x04;
    
        P4DIR |= 0x80;                                                                //P4.7 OUTPUT PRESSURE DELTA
        TBCCTL0 = CCIE;                                                               //CCR0 INTERRUPT ENABLED
        */
        __delay_cycles(100000);                                                        //AT LEAST 10ms (100ms) BEFORE FIRST COMUNICATION
    
        bmp180_calibration();                                                         //LOAD CALIBRATION DATA
    
        get_bmp180();                                                                //LOOP TO COLLECT TEMPERATURE AND PRESSURE
    }
    
    
    //STORE E2PROM DATA INTO USABLE VARIABLES
    
    void bmp180_calibration(void)
    {
        ac1 = sendByte_getBytes(0xAA, 2);                                            //MSB ADRESS=0xAA, LSB ADRESS=AB, "EACH WORLD READ IS 16 BITS" WIDE (2 BYTES)
        __delay_cycles(1000);
    
        ac2 = sendByte_getBytes(0xAC, 2);
        __delay_cycles(1000);
    
        ac3 = sendByte_getBytes(0xAE, 2);
        __delay_cycles(1000);
    
        ac4 = sendByte_getBytes(0xB0, 2);
        __delay_cycles(1000);
    
        ac5 = sendByte_getBytes(0xB2, 2);
        __delay_cycles(1000);
    
        ac6 = sendByte_getBytes(0xB4, 2);
        __delay_cycles(1000);
    
        b1 =  sendByte_getBytes(0xB6, 2);
        __delay_cycles(1000);
    
        b2 =  sendByte_getBytes(0xB8, 2);
        __delay_cycles(1000);
    
        mb =  sendByte_getBytes(0xBA, 2);
        __delay_cycles(1000);
    
        mc =  sendByte_getBytes(0xBC, 2);
        __delay_cycles(1000);
    
        md =  sendByte_getBytes(0xBE, 2);
        __delay_cycles(10000);
    }
    
    
    // READ UNCOMPENSATED TEMPERATURE AND RETURN MSB AND LSB
    unsigned int bmp180_ut(void)
    {
        //i = 1;
    
        i2c_tx_init();
    
        __delay_cycles(1000);
    
        PTxData = (unsigned char *)utTxData;                            //SEND CONTROL REGISTER AND TEMPERATURE REGISTER
        TXByteCtr = 2;                                                  //LOAD TX BYTE COUNTER
    
        start_TX();
    
        __delay_cycles(200000);                                           //LONG DELAY HERE WAITING FOR CONVERSION TO COMPLETE
    
        return (sendByte_getBytes(BMP180_MSB_REG, 2));
    
    }
    
    
    //READ UNCOMPENSATED PRESSURE AND RETURN MSB, LSB AND XLSB
    unsigned long bmp180_up(void)
    {
        //i = 1;
    
        i2c_tx_init();
    
        __delay_cycles(1000);
    
        PTxData = (unsigned char *)upTxData;                            //SEND CONTROL REGISTER ADRESS AND PRESSURE REGISTER VALUE
        TXByteCtr = 2;                                                      //LOAD TX BYTE COUNTER
    
        start_TX();
    
        __delay_cycles(200000);                                            //LONG DELAY HERE WAITING FOR CONVERSION TO COMPLETE
    
        PTxData = (unsigned char *)msbData;                                //SEND MSB READ REGISTER
        TXByteCtr = 1;
    
        //i = 0;
    
        start_TX();
    
        i2c_rx_init();
    
        __delay_cycles(1000);
    
        PRxData = (unsigned char *)RxBuffer;                            //RX BUFFER
        RXByteCtr = 3;                                                     //NUMBER OF BYTES TO RECIEVE
    
        start_RX();
    
        return ( (( (long)RxBuffer[0] << 16) | ( (long)RxBuffer[1] << 8) | (long)RxBuffer[2]) >> 8);
    }
    
    
    //COLLECT UNCOMPESATED TEMPERATURE AND PRESSURE, CALCULATE COMPENSATED TEMPERATURE AND PRESSURE
    
    void get_bmp180()
    {
    
        while (1){
    
        ut = bmp180_ut();
        up = bmp180_up();
    
        //CALCULATE TRUE TEMPERATURE
    
        x1 = ((long)ut - ac6) * ac5 >> 15;
        x2 = ((long)mc << 11) / (x1 + md);
        b5 = x1 + x2;
        bmp_temp = (b5 + 8) >> 4;                                    //FINAL TEMPERATURE
    
         //CALCULATE TRUE PRESSURE
    
        b6 = b5 - 4000;
        x1 = (b2 * (b6 * b6) >> 12) >> 11;
        x2 = (ac2 * b6) >> 11;
        x3 = x1 + x2;
    
        b3 = ((long)ac1 * 4 + x3 + 2) >> 2;                          //LOTS OF "CORRECTIONS" ON THE WEB
    
        x1 = ac3 * b6 >> 13;
        x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
        x3 = ((x1 + x2) + 2) >> 2;
        b4 = (ac4 * (unsigned long)(x3 + 32768)) >> 15;
        b7 = ((unsigned long)up - b3) * 50000;
    
        if (b7 < 0x80000000)
        { p = (b7 * 2) / b4;}
        else {p = (b7 / b4) *2;}
    
        x1 = (p >> 8) * (p >> 8);
        x1 = (x1 * 3038) >> 16;
        x2 = (-7357 * p) >> 16;
        bmp_pres = p + ((x1 + x2 + 3791) >> 4);                        //FINAL PRESSURE
    
    /*
        if ( k == 1 ){
            first_pres = bmp_pres;                                    //SAVE FIRST PRESSURE MEASUREMENT
            k = 0;}
    
        else {
    
            TBCTL = TBSSEL_2 + MC_1 + TBCLR;                         //COUNT MODE
    
            if ( bmp_pres > first_pres ){                            //BLINK FASTER IF CURRENT PRESSURE IS HIGHER THEN first_pres
                TBCCR0 = 20000;}
            if (bmp_pres < first_pres){                                //BLINK SLOWER IF CURRENT PRESSURE IS HIGHER THEN first_pres
                TBCCR0 = 65000;}
            else {
                P4OUT ^= 0x80;}                                        //TOGGLE IF CURRENT PRESSURE IS EQUAL TO first_pres
    
        __delay_cycles(500000);
        }
    
        */
        }
    
    }
    
    
    void i2c_tx_init()
    {
        UCB0I2CSA = BMP180_ADDR;
        UCB0IE |= UCTXIE;                                           //TX INTERRUPT ENABLED
    }
    
    
    void i2c_rx_init(void)
    {
        UCB0IE |= UCRXIE;                                            //RX INTERRUPT ENABLED
    }
    
    
    int sendByte_getBytes( unsigned char reg_to_read, int bytes_to_rx )
    {
        //i = 0;
    
        i2c_tx_init();
    
        __delay_cycles(1000);
    
        PTxData = ( unsigned char *)&reg_to_read;                     //TX ARRAY START ADRESS
        TXByteCtr = sizeof reg_to_read;                                  //LOAD TX BYTE COUNTER
    
        start_TX();
    
        i2c_rx_init();                                                //RECIEVE REQUESTED BYTES
    
        __delay_cycles(1000);
    
        PRxData = (unsigned char *)RxBuffer;                        //RX BUFFER
    
        RXByteCtr = bytes_to_rx;                                     //NUMBER OF BYTES TO RECIEVE
    
        start_RX();
    
        return (((int)RxBuffer[0] << 8) | (int)RxBuffer[1]);         //CURRENTLY ONLY RETURNING TWO BYTES
    }
    
    
    //I2C TRANSMISSION START
    
    void start_TX(void)
    {
        UCB0CTL1 |= UCTR + UCTXSTT;                                 //I2C TX, START CONDITION
    
        __bis_SR_register(LPM0_bits + GIE);                         //ENTER LPM0, GLOBAL INTERRUPT ENABLE, REMAIN IN LPM0 UNTIL ALL DATA IS TX'D
        __no_operation();
    
        while (UCB0CTL1 & UCTXSTP);                                 //ENSURE STOP CONDITION GOT SENT
    }
    
    
    //I2C RESTART AND RECIEVE
    
    void start_RX(void){
        while (UCB0CTL1 & UCTXSTP);                                 //WAIT FOR STOP CONDITION
    
        UCB0CTL1 &= ~UCTR;                                          //SET AS RECIEVER
        UCB0CTL1 |= UCTXSTT;                                        //RESTART, START CONDITION
    
        __bis_SR_register(LPM0_bits + GIE);
    
        while (UCB0CTL1 & UCTXSTP);
    }
    
    
    //I2C INTERRUPT SERVICE ROUTINE
    
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
      switch(__even_in_range(UCB0IV,12))
      {
      case  0: break;                                               //VECTOR  0: NO INTERRUPT FLAGS
      case  2: break;                                                   //VECTOR  2: ALIFG
      case  4: break;                                               //VECTOR  4: NACKIFG
    
      case  6:                                                            //VECTOR  6: STTIFG
    
                      UCB0IFG &= ~UCSTTIFG;                               //CLEAR START CONDITION FLAG
    
                   break;
    
      case  8:                                                            //VECTOR  8: STPIFG
    
                    UCB0IFG &= ~UCSTPIFG;                               //CLEAR STOP CONDITION FLAG
                    __bic_SR_register_on_exit(LPM0_bits);               //EXIT LPM0
    
                   break;
    
      case 10:                                                        //VECTOR 10: RXIFG
    
                    RXByteCtr--;                                        //DECREMENT RX BYTE COUNTER
    
                    //P1OUT ^= 0x01;                                        //TOGGLE P1.0
    
               if (RXByteCtr){
                    *PRxData++ = UCB0RXBUF;                           //MOVE RX DATA TO ADRESS PRxData
               if (RXByteCtr == 1)                                   //ONLY ONE BYTE LEFT?
                      UCB0CTL1 |= UCTXSTP;}                            //GENERATE I2C STOP CONDITION
    
               else{
                    *PRxData = UCB0RXBUF;                            //MOVE FINAL RX DATA TO PRxData
                    __bic_SR_register_on_exit(LPM0_bits);}             //EXIT LPM0
    
               break;
    
      case 12:                                                      //VECTOR 12: TXIFG
    
                if (TXByteCtr){                                          //CHECK TX BYTE COUNTER
    
                    //P6OUT ^= 0x04;                                    //TOGGLE P6.3
    
                    UCB0TXBUF = *PTxData++;                           //LOAD TX BUFFER
                    TXByteCtr--;}                                      //DECREMENT TX BYTE CUNTER
    
                else{
    
                    //if( i == 1 ){
    
                    UCB0CTL1 |= UCTXSTP; //}                              //I2C STOP CONDITION
                    UCB0IFG &= ~UCTXIFG;                                //CLEAR USCI_B0 TX INTERRUPT FLAG
                    __bic_SR_register_on_exit(LPM0_bits);             //EXIT LPM0
                    }
                  default: break;
    }}
    
    //TIMER 1 INTERRUPT SERVICE ROUTINE
    /*
    #pragma vector=TIMERB0_VECTOR
    __interrupt void TIMERB0_ISR (void)
    {
      P4OUT ^= 0x80;                                                //TOGGLE P4.7
    }
    */
    
    
  7. @@supamas Grace is just a simple GUI for setting up selected msp430 devices.  In the case of the ISR, it's just letting you type in a common function name for your interrupt function and then it adjusts the IV table.

     

    Essentially, it just does this:

    #pragma vector=USCIAB0TX_VECTOR
    __interrupt void USCI0TX_ISR_HOOK(void)
    {
    
        if (IFG2 & UCB0TXIFG) {
    		/* USCI_B0 Transmit Interrupt Handler */
    
    		iic_TX_isr();
    
    		/* Enter active mode on exit */
    		__bic_SR_register_on_exit(LPM4_bits);
        }
        else {
    		/* USCI_B0 Receive Interrupt Handler */
    
    		iic_RX_isr();
    
    		/* Enter active mode on exit */
    		__bic_SR_register_on_exit(LPM4_bits);
        }
    }
    
  8. @@atiom that actually sounds like the data is being clocked incorrectly. The bit rate is determined by your mcu's clock speed. I see that you have UCB0BR0 = 12. Check my original code and read the note. Setting the "proper" bit rate has never once worked for me on any msp430 using i2c. Leave those values to zero and data is clocked correctly. Might be something to try as I just tested my original code and it's running fine.

×
×
  • Create New...