Jump to content

gwdeveloper

Members
  • Content Count

    618
  • Joined

  • Last visited

  • Days Won

    22

Everything posted by gwdeveloper

  1. gwdeveloper

    Another BMP085 Project

    Hey guys, I managed to get the BMP085 running on the new MSP-EXP430F5529 dev board. Still putting the final touches on the application but it will initially be a basic weather station. Getting the BMP085 was one of the tougher parts of the programming. The display is showing temperature, pressure and time. Eventually, it will look like a weather station plot like http://www.srh.noaa.gov/jetstream/synoptic/wxmaps.htm Since the USCI was used, I'm pretty sure that all of this code, with minor modifications, would run on a MSP430G2553. I may attempt that later on today but the RC truck is screaming for attention (and it's in a thousand pieces on the dining table). Begin BMP085.c /****************************************************************/ /* Greg Whitmore */ /* greg@gwdeveloper.net */ /* gwdevprojects.blogspot.com */ /****************************************************************/ /* released under the "Use at your own risk" license */ /* use it how you want, where you want and have fun */ /* debugging the code. */ /* MSP-EXP430F5529 */ /****************************************************************/ // currently this is only configured for OSS = 0 // future changes will allow for extended oversampling // standard includes #include #include #include "itoa.h" // driver includes #include "HAL_Board.h" #include "HAL_Buttons.h" #include "HAL_Dogs102x6.h" #include "HAL_Menu.h" #include "HAL_MACROS.h" #include "clock.h" #include "bmp085.h" #include "iic.h" extern char time[9]; extern char date[9]; extern unsigned char *PTxData; // Pointer to TX data extern unsigned char TXByteCtr; extern unsigned char *PRxData; // Pointer to RX data extern unsigned char RXByteCtr; extern volatile unsigned char RxBuffer[3]; // Allocate 3 bytes of RAM, it's all we need here // types based from API // if initialize more than 1 var per line, the calculations are off // cal data 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 temp long ut; long x1; long x2; long b5; int bmp_temp = 0; //true pressure long up; long x3; long b3; unsigned long b4; long b6; unsigned long b7; long p; long bmp_pres = 0; // tx constants const unsigned char utTxData[] = { BMP085_CTRL_REG, BMP085_TEMP_REG }; // uncomp temp reg const unsigned char upTxData[] = { BMP085_CTRL_REG, BMP085_PRESSURE_REG }; // oss =0 see bmp085.h const unsigned char msbData[] = { BMP085_MSB_REG }; // read calibration data from prom - optimize? load all 22 bytes 1 shot? void bmp085_cal(void){ Dogs102x6_clearScreen(); Dogs102x6_stringDrawXY(4, 0, "Loading", DOGS102x6_DRAW_NORMAL); Dogs102x6_stringDrawXY(8, 10, "Calibration", DOGS102x6_DRAW_NORMAL); // store PROM data into usable variables ac1 = sendByte_getBytes(BMP085_ADDR, 0xAA, 2); __delay_cycles(1000); ac2 = sendByte_getBytes(BMP085_ADDR, 0xAC, 2); __delay_cycles(1000); ac3 = sendByte_getBytes(BMP085_ADDR, 0xAE, 2); __delay_cycles(1000); ac4 = sendByte_getBytes(BMP085_ADDR, 0xB0, 2); __delay_cycles(1000); ac5 = sendByte_getBytes(BMP085_ADDR, 0xB2, 2); __delay_cycles(1000); ac6 = sendByte_getBytes(BMP085_ADDR, 0xB4, 2); __delay_cycles(1000); b1 = sendByte_getBytes(BMP085_ADDR, 0xB6, 2); __delay_cycles(1000); b2 = sendByte_getBytes(BMP085_ADDR, 0xB8, 2); __delay_cycles(1000); mb = sendByte_getBytes(BMP085_ADDR, 0xBA, 2); __delay_cycles(1000); mc = sendByte_getBytes(BMP085_ADDR, 0xBC, 2); __delay_cycles(1000); md = sendByte_getBytes(BMP085_ADDR, 0xBE, 2); __delay_cycles(1000); // write to flash here and only run on intitial puc - not implemented yet Dogs102x6_clearScreen(); } // read uncompensated temperature and return msb & lsb unsigned int bmp085_ut(void){ iic_tx_init(BMP085_ADDR); __delay_cycles(1000); PTxData = (unsigned char *)utTxData; // send control reg and temp reg TXByteCtr = 2; // Load TX byte counter start_TX(); __delay_cycles(112505); // ? ~4.5ms at 25mhz ? 25001 * 4.5 // function returns ints return (sendByte_getBytes(BMP085_ADDR, BMP085_MSB_REG, 2)); } // read uncompensated pressure and return msb, lsb & xlsb unsigned long bmp085_up(void){ iic_tx_init(BMP085_ADDR); __delay_cycles(1000); PTxData = (unsigned char *)upTxData; // send control reg and temp reg TXByteCtr = 2; // Load TX byte counter start_TX(); __delay_cycles(112505); // ? ~4.5ms at 25mhz ? 25001 * 4.5 PTxData = (unsigned char *)msbData; // send msb read register TXByteCtr = 1; start_TX(); iic_rx_init(); // set RX interrupt __delay_cycles(1000); PRxData = (unsigned char *)RxBuffer; // rx buffer RXByteCtr = 3; // number of bytes to receive start_RX(); // returning longs instead of ints to allow 2^16 shifts return ( (( (long)RxBuffer[0] << 16) | ( (long)RxBuffer[1] << 8) | (long)RxBuffer[2]) >> 8); } void get_bmp085(){ unsigned char temp_buffer[8]; unsigned char pres_buffer[8]; bmp085_cal(); Dogs102x6_clearScreen(); Dogs102x6_stringDraw(0, 1, "GWDev BMP085", NORMAL); // header Dogs102x6_circleDraw(50, 34, 8, NORMAL); // circle for weather symbol while (!(buttonsPressed & BUTTON_S2)){ DigitalClockUpdate(); Dogs102x6_stringDraw(7, 0, &time[HOUR10], NORMAL); // clock here for demo ut = bmp085_ut(); up = bmp085_up(); // calc true temp x1 = ((long)ut - ac6) * ac5 >> 15; x2 = ((long)mc << 11) / (x1 + md); b5 = x1 + x2; bmp_temp = (b5 + 8) >> 4; // itoa function added itoa(bmp_temp, (char*)temp_buffer); // move integer into char buffer Dogs102x6_stringDraw(2, 24, (char*)temp_buffer, NORMAL); // display temperature on weather symbol // // calc 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; // ???? so many 'corrections' on the web this one works though 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; //p = b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2; // ???? noobness - unsure of the formatting, below works // or 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); // ltoa, part of stdlib.h ltoa(bmp_pres, (char*)pres_buffer); // move long integer into char buffer Dogs102x6_stringDraw(2, 60, (char*)pres_buffer, NORMAL); // display pressure on weather symbol // __delay_cycles(500000); } } Begin BMP085.h /****************************************************************/ /* Greg Whitmore */ /* greg@gwdeveloper.net */ /* gwdevprojects.blogspot.com */ /****************************************************************/ /* released under the "Use at your own risk" license */ /* use it how you want, where you want and have fun */ /* debugging the code. */ /* MSP-EXP430F5529 */ /****************************************************************/ #ifndef BMP085_H_ #define BMP085_H_ /* BMP085 Register Definitions */ #define BMP085_ADDR 0x77 #define BMP085_CTRL_REG 0xF4 #define BMP085_TEMP_REG 0x2E #define BMP085_PRESSURE_REG 0x34 // oss =0 #define BMP085_PRESSURE_REG_OSS1 0x74 // oss =1, longer delays needed 7.5ms #define BMP085_PRESSURE_REG_OSS2 0xB4 // oss =2, 13.5ms #define BMP085_PRESSURE_REG_OSS3 0xF4 // oss =3, 25.5ms #define BMP085_MSB_REG 0xF6 #define BMP085_LSB_REG 0xF7 #define BMP085_CONV_REG_XLSB 0xF8 // prototypes void bmp085_cal(void); unsigned int bmp085_ut(void); unsigned long bmp085_up(void); void get_bmp085(void); #endif /*BMP085_H_*/ Begin iic.c /****************************************************************/ /* Greg Whitmore */ /* greg@gwdeveloper.net */ /* gwdevprojects.blogspot.com */ /****************************************************************/ /* released under the "Use at your own risk" license */ /* use it how you want, where you want and have fun */ /* debugging the code. */ /* MSP-EXP430F5529 */ /****************************************************************/ #include #include "HAL_Board.h" #include "HAL_Buttons.h" #include "HAL_Dogs102x6.h" #include "bmp085.h" #include "iic.h" unsigned char *PTxData; // Pointer to TX data unsigned char TXByteCtr; unsigned char *PRxData; // Pointer to RX data unsigned char RXByteCtr; volatile unsigned char RxBuffer[3]; // Allocate 3 byte of RAM /* ignore remapping for now, iic needs to be moved from UCB0 to UCB1 const uint8_t iic_remap[] = { PM_UCB1SDA, PM_UCB1SCL, }; */ /* ignore this remap for now * * void remap_iic() { PMAPPWD = 0x02D52; PMAPCTL |= PMAPRECFG; P4MAP6 = PM_UCB1SDA; P4MAP7 = PM_UCB1SCL; P4SEL = BIT6+BIT7; UCB1CTL1 |= UCSWRST; // Enable SW reset UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode UCB1CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset UCB1BR0 = 12; // fSCL = SMCLK/12 = ~100kHz UCB1BR1 = 0; UCB1I2COA = 0x01; UCB1I2CSA = 0x48; // Slave Address is 048h UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation UCB1IE |= UCTXIE; // Enable TX interrupt } * */ // initialize iic void iic_init(void){ 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" ----supposedly, UCB0BR1 = 0; // but any values for UCB0BR cause system to run funny UCB0I2COA = 0x43; // set own address UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation } void iic_tx_init(unsigned char slave_reg){ UCB0I2CSA = slave_reg; UCB0IE |= UCTXIE; // Enable TX interrupt } void iic_rx_init(void){ UCB0IE |= UCRXIE; // enable RX interrupt } // send 1 byte, return 2 bytes - needs the return expanded for X bytes int sendByte_getBytes(unsigned char slave_addr, unsigned char reg_2_read, int bytes_to_rx){ // transmit slave address and register to read iic_tx_init(slave_addr); __delay_cycles(1000); PTxData = (unsigned char *)&reg_2_read; // TX array start address TXByteCtr = sizeof reg_2_read; // Load TX byte counter start_TX(); // // receive requested bytes iic_rx_init(); // set RX interrupt __delay_cycles(1000); PRxData = (unsigned char *)RxBuffer; // rx buffer RXByteCtr = bytes_to_rx; // number of bytes to receive start_RX(); // return ((int)RxBuffer[0] << 8) | (int)RxBuffer[1]; // currently only returning 2 bytes } // start transmitting void start_TX(void){ UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts __no_operation(); // Remain in LPM0 until all data // is TX'd while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent } // restart and receive void start_RX(void){ while (UCB0CTL1 & UCTXSTP); // wait for stop UCB0CTL1 &= ~UCTR; // restart, set as receiver UCB0CTL1 |= UCTXSTT; // start condition __bis_SR_register(LPM0_bits + GIE); while (UCB0CTL1 & UCTXSTP); } // initial isr code combined from TI I2C examples for MSP430F5529 // ucsi BO isr states #pragma vector = USCI_B0_VECTOR __interrupt void USCI_B0_ISR(void) { switch(__even_in_range(UCB0IV,12)) { case 0: break; // Vector 0: No interrupts case 2: break; // Vector 2: ALIFG case 4: // Vector 4: NACKIFG break; case 6: // Vector 6: STTIFG UCB0IFG &= ~UCSTTIFG; // Clear start condition int flag break; case 8: // Vector 8: STPIFG UCB0IFG &= ~UCSTPIFG; // Clear stop condition int flag __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 if data was transmitted break; case 10: // Vector 10: RXIFG RXByteCtr--; // Decrement RX byte counter if (RXByteCtr) { *PRxData++ = UCB0RXBUF; // Move RX data to address 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 active CPU } break; case 12: // Vector 12: TXIFG if (TXByteCtr) // Check TX byte counter { UCB0TXBUF = *PTxData++; // Load TX buffer TXByteCtr--; // Decrement TX byte counter } else { UCB0CTL1 |= UCTXSTP; // I2C stop condition UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 } default: break; } } Begin iic.h /****************************************************************/ /* Greg Whitmore */ /* greg@gwdeveloper.net */ /* gwdevprojects.blogspot.com */ /****************************************************************/ /* released under the "Use at your own risk" license */ /* use it how you want, where you want and have fun */ /* debugging the code. */ /* MSP-EXP430F5529 */ /****************************************************************/ #ifndef IIC_H_ #define IIC_H_ void remap_iic(void); void iic_init(void); void iic_tx_init(unsigned char slave_reg); void start_TX(void); void iic_rx_init(void); void start_RX(void); int sendByte_getBytes(unsigned char slave_addr, unsigned char reg_2_read, int bytes_to_rx); #endif /*IIC_H_*/
  2. Electronics and certification aside, make sure you protect yourself legally too. Lawyer, indemnification... start an LLC or something.
  3. gwdeveloper

    ADC problems or code problems? Please help !

    You might consider switching to the HIH-5030 as it operates at 3.3v. I never had any luck with accurate readings using a HIH-4000 on the Launchpad.
  4. gwdeveloper

    SimpiciTI Tutorial for CC2500

    This tutorial is meant to provide simple instruction to prepare a SimpliciTI wireless project using the TI Launchpad and CC2500 radio. Currently, CCSv5.1 will compile this program but have a few syntax errors. They can be ignored for now. CCSv4 will compile with no issues. Please feel free to critique and ask questions. It helps to make us all better. Part 1 of 2 Hardware Needed: Launchpad with MSP430G2553 CC2500 Radio (several variants available; MDFLY CC2500 breakout or ez430-RF2500t) (will insert an image of various hardware versions from TI to DIY) Software Needed: TI's CCS v5.1 http://processors.wi...hp/Download_CCS SimpliciTI 1.1.1 for CCS http://www.ti.com/tool/simpliciti LP_G2553.zip (launchpad BSP for simpliciTI) 2274_SimpliciTI_Toggle.zip (only needed for RF2500T used as slave; it will disable the cpu and set up peripherals to toggle leds) 2274_SimpliciTI_Toggle.zip Step 1: Install Softwares. - Install CCS v5 OR V6 for the MSP430 (if you don't already use CCS) - Install SimpliciTI 1.1.1 (make note of the install directory; we'll use C:\Texas Instruments\SimpliciTI-CCS-1.1.1) - unzip LP_G2553.zip bsp files to C:\Texas Instruments\SimpliciTI-CCS-1.1.1\Components\bsp\boards - modified vlo_rand library for easy address assignment will be unzipped later - for RF2500T, unzip 2274_SimpliciTI_Toggle.zip to your current CCS workspace --- this project will need to be imported to CCS via Project -> Import Existing CCS Project Step 2: Create CCS Project -File -> New CCS Project -Give project name. Select MSP430 Family and MSP430G2553 as variant. Connection should be left to default and Empty Project selected for template. 5_2folder_structure.JPG[/attachment] Step 4: Create project file structure -Now you will need to open the SimpliciTI\components folder. --- for eg; C:\Texas Instruments\SimpliciTI-CCS-1.1.1\Components (after the following actions, select "Link To" for the copy action) -- drag 3 files from ..\bsp to the bsp project folder -- drag 3 files from ..\mrfi to the mrfi project folder -- drag all files from ..\Simpliciti\nwk to nwk project folder -- drag all files from ..\Simpliciti\nwk_applications folder to nwk applications project folder -We'll borrow the nwk .dat files from the EZ430RF project --drag smpl_nwk_config.dat from \SimpliciTI-CCS-1.1.1\Projects\Examples\eZ430RF\Simple_Peer_to_Peer\CCS\Configuration to the configuration project folder. --drag smpl_config.dat from \SimpliciTI-CCS-1.1.1\Projects\Examples\eZ430RF\Simple_Peer_to_Peer\CCS\Configuration\End_Device to the end device project folder. [attachment=1]5_3linked_files.JPG[/attachment] end of part 1. (limited due to 5 attachments per entry)
  5. gwdeveloper

    Code Composer Studio v6 now officially released

    v6 is working pretty well for me. The beta was a bit clunky and the App Center never worked. After tracking down a proper libudev0 for Ubuntu 13.10 64bit, the release version is functioning quite well. A few years ago, TI gave me a full platinum license and it transferred over to v6 with no issues.
  6. gwdeveloper

    I2C acting weird MSP430G2553

    The MPR121 generates two interrupts, one for press and the 2nd for release. You'll need your code setup to handle both or it gets screwy. EDIT: Since you are using Energia. Maybe try the Arduino library for the MPR121? http://bildr.org/2011/05/mpr121_arduino/ Other links: http://forum.43oh.com/topic/1254-mpr121-interrupt-question/ http://forum.43oh.com/topic/3587-mpr121-touch-sensor-and-i2c-wire-library/
  7. gwdeveloper

    Tooth brushing minder.

    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...
  8. gwdeveloper

    Your last beer

    @@wasson65 Super jealous. Worst part of moving from Austin to Indy = no good bbq. I miss Rudy's brisket.
  9. gwdeveloper

    Your last beer

    3 Floyds' Alpha King Best part of moving from Austin to Indianapolis = the beer in Indy rules.
  10. gwdeveloper

    SimpiciTI Tutorial for CC2500

    @@MarkusR 1a) Yes, SPI activation is done by the Simpliciti BSP. 1b) You have no connection for GDO0 or GDO2. Check: ./LP_2553/bsp_external/mrfi_board_defs.h There you will find the SPI init macro as well as the pin definitions.
  11. gwdeveloper

    Help me port energia to msp430f2274

    @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.
  12. gwdeveloper

    Help me port energia to msp430f2274

    Is it code you can post here? I'm interested in trying it out.
  13. gwdeveloper

    Help me port energia to msp430f2274

    @chicken No, I surely did not. That's where I was at with the RF2500 when I started having pc issues. From your last post, it seems that you have it working(?) I'll check it out over the weekend.
  14. gwdeveloper

    System76 Notebooks?

    Any of you guys have one of their computers? Or know somebody with one? After yesterday's smoky event, I'm in need of a new pc ASAP. Looking at the Galago Ultrapro.
  15. gwdeveloper

    System76 Notebooks?

    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.
  16. gwdeveloper

    The Terminal - 43oh OLED Booster Pack

    @t0mpr1c3 Have you made progress on this?
  17. gwdeveloper

    System76 Notebooks?

    Thanks, that's what I was hoping to hear. Didn't want the trouble removing windows and install linux anyhow. They seemed to offer the best package.
  18. gwdeveloper

    The Terminal - 43oh OLED Booster Pack

    I'd help out here but my PC let all the magic smoke out on Sunday morning. You guys will probably sort it out before I'm up and running.
  19. gwdeveloper

    Mailbag

    Today, I received an order from RobG's Tindie Store; the Ethernet Booster Pack. Thanks @@RobG
  20. gwdeveloper

    Help in interfacing cc2541 BLE sensortag with msp430

    Red Bear Lab's BLE Mini? http://redbearlab.com/blemini/ I ordered one the other day to use with a F5529.
  21. gwdeveloper

    120 LED Ring Clock

    Bad-a** Post the Gerbers for us?
  22. gwdeveloper

    MSP430 Application UART

    I've never had any luck with any of my computers (or msp <-> msp) using the UART on MSP430 devices until I found this https://github.com/glitovsky38412/msp430uartdriver
  23. 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 }
  24. gwdeveloper

    Another BMP085 Project

    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 ...
  25. gwdeveloper

    Another BMP085 Project

    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 } */
×