Jump to content

turd

Members
  • Content Count

    116
  • Joined

  • Last visited

  • Days Won

    2

Reputation Activity

  1. Like
    turd got a reaction from cekin in MSP430G2553/LaunchPad UART RX example   
    Just a simple UART RX example
    Don't forget this.
     

    #include #include //#include void main(void) { WDTCTL = WDTPW + WDTHOLD; //Stop WDT P1DIR |= (BIT0 | BIT6); //Set P1.0 and P1.6 to outputs BCSCTL1 = CALBC1_1MHZ; //Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; P1SEL = BIT1 + BIT2; //Set P1.1 and P1.2 to RX to TX P1SEL2 = BIT1 + BIT2; UCA0CTL1 |= UCSSEL_2; //SMCLK UCA0BR0 = 104; //9600 UCA0BR1 = 0; //9600 UCA0MCTL = UCBRS_1; //Modulation UCA0CTL1 &= ~UCSWRST; //Start USCI IE2 |= UCA0RXIE; //Enable RX interrupt __bis_SR_register(CPUOFF + GIE); //Enter LPM0 with interrupts } //#pragma vector=USCIAB0RX_VECTOR //__interrupt void USCI0RX_ISR(void) interrupt(USCIAB0RX_VECTOR) USCI0RX_ISR(void) { if(UCA0RXBUF == 65) //Toggle red LED if "A" RXed { P1OUT ^= BIT0; } if(UCA0RXBUF == 66) //Toggle green LED if "B" RXed { P1OUT ^= BIT6; } }

  2. Like
    turd got a reaction from SouLSLayeR in MSP430G2553/LaunchPad UART RX example   
    Just a simple UART RX example
    Don't forget this.
     

    #include #include //#include void main(void) { WDTCTL = WDTPW + WDTHOLD; //Stop WDT P1DIR |= (BIT0 | BIT6); //Set P1.0 and P1.6 to outputs BCSCTL1 = CALBC1_1MHZ; //Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; P1SEL = BIT1 + BIT2; //Set P1.1 and P1.2 to RX to TX P1SEL2 = BIT1 + BIT2; UCA0CTL1 |= UCSSEL_2; //SMCLK UCA0BR0 = 104; //9600 UCA0BR1 = 0; //9600 UCA0MCTL = UCBRS_1; //Modulation UCA0CTL1 &= ~UCSWRST; //Start USCI IE2 |= UCA0RXIE; //Enable RX interrupt __bis_SR_register(CPUOFF + GIE); //Enter LPM0 with interrupts } //#pragma vector=USCIAB0RX_VECTOR //__interrupt void USCI0RX_ISR(void) interrupt(USCIAB0RX_VECTOR) USCI0RX_ISR(void) { if(UCA0RXBUF == 65) //Toggle red LED if "A" RXed { P1OUT ^= BIT0; } if(UCA0RXBUF == 66) //Toggle green LED if "B" RXed { P1OUT ^= BIT6; } }

  3. Like
    turd reacted to jazz in Uart configurator   
    I was playing last days with MSP5xx UART, and every time after changing baud rate, need to calculate configuration again, and again, and again...
     
    I write small program for making configuration depending on clock and baud rate. After generation, just press mouse button on first/second listing (nothing will happen) and use [CTRL]+[C] for copy listing to clipboard.
     

    MSP430UartCalc.rar
  4. Like
    turd got a reaction from cubeberg in fram for dummies book   
    Anyone see this yet?
    http://www.mouser.com/framfordummies/
  5. Like
    turd reacted to bluehash in Arduino Quadcopter   
    Since Marko is interested.. Here is my first LOS(Line of Sight) flight.
     


  6. Like
    turd reacted to larsie in Motor/Boosterpack for L298 and servos   
    I must admit I
    RobotBooster_mini_v1.zip
  7. Like
    turd got a reaction from aalani in MSP430G2553 I2C   
    This might help:
    viewtopic.php?f=8&t=2266&p=16737#p16801
     
    Also look at the example code from TI:
    http://www.ti.com/lit/zip/slac485
    http://www.ti.com/lsds/ti/microcontroll ... /code.page
     
    It took me a couple weeks to get it working for me and now its been awhile since I worked with it so I probably won't be much help beyond this.
  8. Like
    turd reacted to Alan in MSP430G2553 I2C   
    I've modified TIs code and split it into functions. Its been a while since I have looked at it admittedly but hopefully the following files might be useful to you. I wrote it for mspgcc there might be some issues with using it with CSS / IAR mainly the interrupts will need changed. The register setups will be the same though.
     
    I2C:
    https://github.com/alanbarr/msp430-launchpad/blob/master/common/src/i2c.c
    https://github.com/alanbarr/msp430-launchpad/blob/master/common/inc/i2c.h
     
    Example:
    https://github.com/alanbarr/msp430-launchpad/blob/master/examples/i2cBitExp4Leds/main.c
  9. Like
    turd reacted to pabigot in first look: BSP430   
    Having wrestled mspgcc mostly to a state of stability and feature-completeness, I've been moving back towards using the MSP430 for real application code. The next tool I needed was a board support environment that met my needs. I've got the first public release up at https://github.com/pabigot/bsp430 and thought people here might want to take a look. In the next month or two I'll be extending this with examples of much more complex features including full ChipCon radio support, the CC3000 WiFi module, and integration into FreeRTOS.
     
    Here's the blurb:
     
    BSP430 is a set of C language adaptation layers simplifying cross-MCU library and application development on Texas Instruments MSP430 microcontrollers. The target audience is experienced embedded systems developers who need full control over the microcontroller but are willing to trade a small amount of performance for improved component re-usability and rapid prototyping.
     
    For more details, the documentation is at http://pabigot.github.com/bsp430
  10. Like
    turd reacted to boseji in Updated compile of mspgcc and mspdebug on Linux   
    Hello,
     
    I have started a project in github to create the scripted compile and download of mspgcc components.
    https://github.com/AdharLabs/mspgcc-build-linux
    This project would provide with examples for makefile based projects for Launch Pad and also for advance MSP430 processors.
    There is also a plan to provide an easy to use makefile generator script to help speed up the project development.
     
    For the easy of the users, I did the complete build and packaging of the MSPGCC + MSP430libc + MCU files and mspdebug.
    The same has been tested for Ubuntu Linux 12.04. Hope that this release should be compatible to most of the updated Debian Linux flavours.
    Here is the Download link: https://github.com/AdharLabs/mspgcc-build-linux/downloads
    You can directly download the first release:
    https://github.com/downloads/AdharLabs/mspgcc-build-linux/mspgcc-build-linux-20120710-Ubuntu12.04.tar.bz2
     
    I would like to know feedback and suggestions.
     
    Kindly help me out to make this innitiatve successful.
     
    Thanking you,
  11. Like
    turd reacted to boseji in Updated compile of mspgcc and mspdebug on Linux   
    Hello,
     
    I was able to successfully compile the complete mspgcc and mspdebug.
    This compile has been perfomed with the most updated gcc compiler GCC4.7
    http://m8051.blogspot.in/2012/07/compiling-msp430-gcc-in-linux-upto-date.html
     
    However this has a special provistion that C++ language is enabled and the installation is in a custom location at user space.
     
    I wish if any one could verify the compile steps and let me know the feeback.
    As this was the first time I compiled with C++ enabled.
     
    Thanks,
  12. Like
    turd reacted to kff2 in Generating image bitmaps for Nokia 7110 LCD   
    In oPossum's Time and Temperature project, there is an embedded TI logo that rolls across the screen when the program starts. Here is how you can generate bitmaps from your own images. You will need ImageMagick and python.
     
    1) Resize your image to fit on the LCD. The maximum height is 96 pixels. The height should be a multiple of 8. Also, you will want to stretch your image horizontally a little bit, as pixels on 7110 aren't square.
     
    I did something along the lines of
     
    convert -resize 43x48! logo.jpg logo2.png
     
    The exclamation point here tells ImageMagick to go ahead and change the aspect ratio of the image; otherwise it will set width (or height) automatically to maintain the original aspect ratio.
     
    2) Convert the image to 1-bit black and white and save it in RGB format
     
    convert -monochrome -depth 1 -type Bilevel +dither logo2.png logo3.rgb
     
    The resulting file contains 3 bits for each pixel (red, green, and blue channels). The 3 bits are the same. 0 corresponds to black and 1 to white.
     
    I wrote a short python script to convert RGB files to the format expected by nokia7110tl.h's bitmap() function:
     

    import sys import string x = int(sys.argv[2]) y = int(sys.argv[3]) img = open(sys.argv[1]).read() b = string.join([str(int(ord(img[i*3/8]) & (1<<(7-(i*3%8))) == 0)) for i in xrange(x*y)], '') # b is a string that contains a 0 or 1 for each pixel of the image. If you now set # the screen size to 'width' and print b, you should see your image in ascii. # The next step is to rearrange the bits in b to match the # addressing expected by 7110's controller. b2 = '' for i in reversed(xrange(y/8)): for j in xrange(x): b2 += string.join([b[(y-1-i*8-k)*x+j] for k in xrange(8)], '') print string.join(['0x%02x' % eval('0b'+b2[i*8:i*8+8]) for i in xrange(x*y/8)], ',')
     
    You run it like this:
     
    python convert_7110.py logo3.rgb 43 48
     
    where 43 is the width and 48 is the height of the image. The script spits out an array of ascii bytes that you can copy and paste directly into your C program and pass to the bitmap() function.
  13. Like
    turd reacted to kylej1050 in Lightning detector/counter   
    I'm fascinated by weather. New Mexico doesn't have much to offer in this particular area but I try to capture the moments whenever I can.
     
    This is one of two lightning projects I'm currently working on. The second is an IR detector for triggering my Kodak Retina 2 with B&W film.
     

     
    The detector captures pulses from an external lightning detector circuit, counts how many strikes there have been since the last reset(powered off) and takes the average Strikes Per Minute based on the last 10 seconds worth of data. I'll get around to a better averaging scheme later but I wanted this thing up and running faster because we are getting into storm season here in NM. Pin 1.6 is for accessories but can be used for an LED to indicate when a strike is occurring for minimal parts. I'm using an LED and a speaker from the detector add-on circuits so I can hear and see the strikes outside the MSP.
     
    I sample Vcc so I know when the lithium battery is in need of recharging(runs 1MHz so without audio should last a long time with the 1200mAH capacity). The code is based on the 4.2-3.6V working range of a lithium-ion battery being dropped through a diode to not exceed the MSP max. I intended to incorporate a charger circuit so there is an input for the indicator but thermal limitations of a plastic chassis has made this a no go for now.
     
    The code for the LCD is based off the 5110 code that is on here, the lightning detector circuit is from http://www.techlib.com/electronics/lightning.html#Egor but I used the newer antenna tank circuit , and the lithium charger circuit is from here http://www.shdesigns.org/lionchg.html modified for a single cell.
     
    I had a little mishap making the chassis yesterday so I now have to go get another cover but I should have a finished product to show soon.
     

    // main.c #include "msp430g2553.h" #include "PCD8544.h" #define LCD5110_SCLK_PIN BIT5 #define LCD5110_DN_PIN BIT7 #define LCD5110_SCE_PIN BIT0 #define LCD5110_DC_PIN BIT1 #define LCD5110_SELECT P1OUT &= ~LCD5110_SCE_PIN #define LCD5110_DESELECT P1OUT |= LCD5110_SCE_PIN #define LCD5110_SET_COMMAND P1OUT &= ~LCD5110_DC_PIN #define LCD5110_SET_DATA P1OUT |= LCD5110_DC_PIN #define LCD5110_COMMAND 0 #define LCD5110_DATA 1 // Pin 1.4 for lightning trigger (hi->low) // Pin 1.3 for charge indicator (high == charging) // Pin 1.6 for pulsed output (high pulse) #define SPI_MSB_FIRST UCB0CTL0 |= UCMSB #define SPI_LSB_FIRST UCB0CTL0 &= ~UCMSB void writeStringToLCD(const char *string); void writeCharToLCD(char c); void writeIntToLCD(int input); void writeBlockToLCD(char *byte, unsigned char length); void writeGraphicToLCD(char *byte, unsigned char transform); void writeToLCD(unsigned char dataCommand, unsigned char data); void clearLCD(); void clearBank(unsigned char bank); void setAddr(unsigned char xAddr, unsigned char yAddr); void initLCD(); // Variables for lightning counter volatile unsigned int SPMTime = 0, displayUpdate = '4', totalStrikes = 0, SPMCount = 0; volatile long unsigned int timeSinceReset = 0; long unsigned int TSRCalc; unsigned int totalStrikesDisp, TSDCheck, SPMCheck; short int TSD5, TSD4, TSD3, TSD2, TSD1, SPM3, SPM2, SPM1, TSRHour, TSRMinute, TSRSecond; int SPMAverage = 0; // Variables for battery circuit short int batteryTime = 0, batteryLevel = 0, batteryStatus = '0'; int main() { WDTCTL = WDTPW + WDTHOLD; // disable WDT BCSCTL1 = CALBC1_1MHZ; // 1MHz clock DCOCTL = CALDCO_1MHZ; BCSCTL3 = XCAP_3; // 12.5pF capacitance for 32KHz crystal. P1IE |= 0x10; // P1.4 interrupt enabled P1IES |= 0x10; // P1.4 Hi/lo edge P1IFG &= ~0x10; // P1.4 IFG cleared P1OUT |= LCD5110_SCE_PIN + LCD5110_DC_PIN + BIT3; P1OUT &= ~BIT6; P1DIR |= LCD5110_SCE_PIN + LCD5110_DC_PIN + BIT6; P1REN |= BIT3; // setup USIB P1SEL |= LCD5110_SCLK_PIN + LCD5110_DN_PIN; P1SEL2 |= LCD5110_SCLK_PIN + LCD5110_DN_PIN; UCB0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 |= 0x01; // 1:1 UCB0BR1 = 0; UCB0CTL1 &= ~UCSWRST; // clear SW ADC10CTL1 = INCH_11; // AVcc/2 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REF2_5V + REFON + ADC10ON; // Begin active code WDTCTL = WDT_ADLY_1000; IE1 |= WDTIE; initLCD(); clearLCD(); setAddr(0,0); writeStringToLCD("Lightning"); setAddr(0,1); writeStringToLCD(" Detector"); clearBank(3); writeStringToLCD("Avg SPM: 0"); // setAddr spacing 54 clearBank(4); writeStringToLCD("Total: 0"); // setAddr spacing 42 clearBank(5); writeStringToLCD("TSR: 00:00:00"); // setAddr spacing 30 while(1) { switch(displayUpdate) { case '1': // Calculate time TSRCalc = timeSinceReset; TSRHour = TSRCalc / 3600; TSRCalc %= 3600; TSRMinute = TSRCalc / 60; TSRSecond = TSRCalc % 60; // Display time setAddr(30,5); writeIntToLCD(TSRHour/10); writeIntToLCD(TSRHour%10); writeCharToLCD(0x3a); writeIntToLCD(TSRMinute/10); writeIntToLCD(TSRMinute%10); writeCharToLCD(0x3a); writeIntToLCD(TSRSecond/10); writeIntToLCD(TSRSecond%10); break; case '2': P1OUT ^= BIT6; // Update total strikes from interrupt TSDCheck = totalStrikesDisp = totalStrikes; TSD5 = totalStrikesDisp / 100000; totalStrikesDisp%=100000; TSD4 = totalStrikesDisp / 10000; totalStrikesDisp%=10000; TSD3 = totalStrikesDisp / 1000; totalStrikesDisp%=1000; TSD2 = totalStrikesDisp / 100; totalStrikesDisp%=100; TSD1 = totalStrikesDisp / 10; // Display total strikes setAddr(42,4); if (TSD5 == 0 && TSDCheck < 100000) writeCharToLCD(0x20); else writeIntToLCD(TSD5); if (TSD4 == 0 && TSDCheck < 10000) writeCharToLCD(0x20); else writeIntToLCD(TSD4); if (TSD3 == 0 && TSDCheck < 1000) writeCharToLCD(0x20); else writeIntToLCD(TSD3); if (TSD2 == 0 && TSDCheck < 100) writeCharToLCD(0x20); else writeIntToLCD(TSD2); if (TSD1 == 0 && TSDCheck < 10) writeCharToLCD(0x20); else writeIntToLCD(TSD1); writeIntToLCD(totalStrikesDisp%10); P1OUT ^= BIT6; break; case '3': // Update average strikes per minute SPMCheck = SPMAverage = SPMCount * 6; SPM3 = SPMAverage / 1000; SPMAverage %= 1000; SPM2 = SPMAverage / 100; SPMAverage %= 100; SPM1 = SPMAverage / 10; // Display SPM setAddr(54, 3); if (SPM3 == 0 && SPMCheck < 1000) writeCharToLCD(0x20); else writeIntToLCD(SPM3); if (SPM2 == 0 && SPMCheck < 100) writeCharToLCD(0x20); else writeIntToLCD(SPM2); if (SPM1 == 0 && SPMCheck < 10) writeCharToLCD(0x20); else writeIntToLCD(SPM1); writeIntToLCD(SPMAverage%10); SPMTime = 0; SPMCount = 0; batteryTime++; break; case '4': // Measure battery voltage and update battery icon ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start while (ADC10CTL1 & ADC10BUSY); // ADC10BUSY? batteryLevel = ADC10MEM; if (batteryLevel > 0x28F) batteryStatus = '4'; // > 3.2v after .7 diode drop else if (batteryLevel > 0x27A) batteryStatus = '3'; // > 3.1v after .7 diode drop else if (batteryLevel > 0x266) batteryStatus = '2'; // > 3.0v after .7 diode drop else if (batteryLevel > 0x251) batteryStatus = '1'; // > 2.9v after .7 diode drop else batteryStatus = '0'; //Update battery and charge indicator (high on pin 1.3 indicates charge) if(0x08 & P1IN) { setAddr(73,0); writeCharToLCD(0x20); } else { setAddr(73,0); writeCharToLCD(0x85); } switch(batteryStatus) { case '4': writeCharToLCD(0x80); break; case '3': writeCharToLCD(0x81); break; case '2': writeCharToLCD(0x82); break; case '1': writeCharToLCD(0x83); break; case '0': writeCharToLCD(0x84); break; } batteryTime = 0; break; } if(SPMTime > 9) displayUpdate = '3'; else if (batteryTime > 5) displayUpdate = '4'; else { displayUpdate = '0'; _BIS_SR(LPM3_bits + GIE); } } } // Interrupt vectors #pragma vector=WDT_VECTOR __interrupt void watchdog_timer (void) { timeSinceReset++; SPMTime++; displayUpdate = '1'; _BIC_SR_IRQ(LPM3_bits); } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { SPMCount++; totalStrikes++; displayUpdate = '2'; _BIC_SR_IRQ(LPM3_bits); P1IFG &= ~0x10; } // LCD Code void writeStringToLCD(const char *string) { while(*string) { writeCharToLCD(*string++); } } void writeCharToLCD(char c) { unsigned char i; for(i = 0; i < 5; i++) { writeToLCD(LCD5110_DATA, font[c - 0x20][i]); } writeToLCD(LCD5110_DATA, 0); } void writeIntToLCD(int input) { unsigned char i; for(i = 0; i < 5; i++) { writeToLCD(LCD5110_DATA, font[16 + input][i]); } writeToLCD(LCD5110_DATA, 0); } void writeBlockToLCD(char *byte, unsigned char length) { unsigned char c = 0; while(c < length) { writeToLCD(LCD5110_DATA, *byte++); c++; } } void writeGraphicToLCD(char *byte, unsigned char transform) { int c = 0; char block[8]; if(transform & FLIP_V) { SPI_LSB_FIRST; } if(transform & ROTATE) { c = 1; while(c != 0) { (*byte & 0x01) ? (block[7] |= c) : (block[7] &= ~c); (*byte & 0x02) ? (block[6] |= c) : (block[6] &= ~c); (*byte & 0x04) ? (block[5] |= c) : (block[5] &= ~c); (*byte & 0x08) ? (block[4] |= c) : (block[4] &= ~c); (*byte & 0x10) ? (block[3] |= c) : (block[3] &= ~c); (*byte & 0x20) ? (block[2] |= c) : (block[2] &= ~c); (*byte & 0x40) ? (block[1] |= c) : (block[1] &= ~c); (*byte & 0x80) ? (block[0] |= c) : (block[0] &= ~c); *byte++; c <<= 1; } } else { while(c < 8) { block[c++] = *byte++; } } if(transform & FLIP_H) { c = 7; while(c > -1) { writeToLCD(LCD5110_DATA, block[c--]); } } else { c = 0; while(c < 8) { writeToLCD(LCD5110_DATA, block[c++]); } } SPI_MSB_FIRST; } void writeToLCD(unsigned char dataCommand, unsigned char data) { LCD5110_SELECT; if(dataCommand) { LCD5110_SET_DATA; } else { LCD5110_SET_COMMAND; } UCB0TXBUF = data; while(!(IFG2 & UCB0TXIFG)) ; LCD5110_DESELECT; } void clearLCD() { setAddr(0, 0); int c = 0; while(c < PCD8544_MAXBYTES) { writeToLCD(LCD5110_DATA, 0); c++; } setAddr(0, 0); } void clearBank(unsigned char bank) { setAddr(0, bank); int c = 0; while(c < PCD8544_HPIXELS) { writeToLCD(LCD5110_DATA, 0); c++; } setAddr(0, bank); } void setAddr(unsigned char xAddr, unsigned char yAddr) { writeToLCD(LCD5110_COMMAND, PCD8544_SETXADDR | xAddr); writeToLCD(LCD5110_COMMAND, PCD8544_SETYADDR | yAddr); } void initLCD() { writeToLCD(LCD5110_COMMAND, PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION); writeToLCD(LCD5110_COMMAND, PCD8544_SETVOP | 0x3F); writeToLCD(LCD5110_COMMAND, PCD8544_SETTEMP | 0x02); writeToLCD(LCD5110_COMMAND, PCD8544_SETBIAS | 0x03); writeToLCD(LCD5110_COMMAND, PCD8544_FUNCTIONSET); writeToLCD(LCD5110_COMMAND, PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); }
     
    // PCD8544.h (modified for extra characters)
     
    #ifndef PCD8544_H_
    #define PCD8544_H_
     
    #define PCD8544_POWERDOWN 0x04
    #define PCD8544_ENTRYMODE 0x02
    #define PCD8544_EXTENDEDINSTRUCTION 0x01
     
    #define PCD8544_DISPLAYBLANK 0x0
    #define PCD8544_DISPLAYNORMAL 0x4
    #define PCD8544_DISPLAYALLON 0x1
    #define PCD8544_DISPLAYINVERTED 0x5
     
    // H = 0
    #define PCD8544_FUNCTIONSET 0x20
    #define PCD8544_DISPLAYCONTROL 0x08
    #define PCD8544_SETYADDR 0x40
    #define PCD8544_SETXADDR 0x80
    #define PCD8544_HPIXELS 84
    #define PCD8544_VBANKS 6
    #define PCD8544_MAXBYTES 504 // PCD8544_HPIXELS * PCD8544_VBANKS
     
    // H = 1
    #define PCD8544_SETTEMP 0x04
    #define PCD8544_SETBIAS 0x10
    #define PCD8544_SETVOP 0x80
     
    //transform
    #define NONE 0x00
    #define FLIP_H 0x01
    #define FLIP_V 0x02
    #define ROTATE 0x04 // 90 deg CW
    #define ROTATE_90_CW ROTATE
    #define ROTATE_90_CCW (FLIP_H | FLIP_V | ROTATE)
    #define ROTATE_180 (FLIP_H | FLIP_V)
     
    static const char font[][5] = { // basic font
    {0x00, 0x00, 0x00, 0x00, 0x00} // 20
    ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
    ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
    ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
    ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
    ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
    ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
    ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
    ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
    ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
    ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
    ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
    ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
    ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
    ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
    ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
    ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
    ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
    ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
    ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
    ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
    ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
    ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
    ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
    ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
    ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
    ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
    ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
    ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
    ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
    ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
    ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
    ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
    ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
    ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
    ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
    ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
    ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
    ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
    ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
    ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
    ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
    ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
    ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
    ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
    ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
    ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
    ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
    ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
    ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
    ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
    ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
    ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
    ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
    ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
    ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
    ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
    ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
    ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
    ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
    ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c
  14. Like
    turd reacted to Rickta59 in Energia (Arduino for msp430)   
    I came across the port of the Arduino IDE for the msp430 (it is called Energia) reading another post.
    Robert Wessels has made a great first stab at supporting the Arduino API for the launchpad boards. It already
    works on the MacOSX and Windows platforms. Edit: [i checked in the changes to git for the linux version
    [Linux isn't up to snuff yet, but I'll be helping him getting that working properly.] . It should be good to go.
    If you are running linux and have a working java, msp430-gcc and mspdebug. For a limited time you can try
    out an early snapshot by downloading this linux32 distribution.
     
    http://xxxxxxx It is large (~15MB) and will be changing so it will only
    available at that URL for a limited time.
     
    Download the tar file and unpack it. To launch, just run the energia shell script. In the Energia IDE, select the Tools menu
    pick one of the Launchpad boards. Set the Programmer to rf2500 and then pick your serial port. The picture below
    is a snapshot of the ASCIITable example found in the Communications section. The example uses the Hardware serial
    port of the msp430g2553 so make sure your TX/RX jumpers are set correctly. You can also find some msp430
    specific examples. I haven't tested all the examples so don't expect everything to work. This is a very early
    version of Energia.
     
    If you are a java weenie and want to checkout the source code, you can find it up on github:
     
    https://github.com/energia/Energia
     
    -rick

  15. Like
    turd reacted to Rickta59 in Is the MSPhere project work stopped completely ?   
    The Energia project seems to have a lot of potential for those who want an Arduino environment. I got it sort of
    working on Ubuntu 11.04. It still seems to need some work. I did get it to compile some of the sample programs
    and then run with the Serial Monitor. * I have my Launchpad connected to an FTDI serial usb device hence the ttyUSB0 *
     
    -rick
     
    Here it is with the 'TimerSerialExample':

  16. Like
    turd reacted to RobG in 3V LaunchPad   
    Here is one way to temporarily lower LaunchPad's 3.6V supply down to 3V (or 3.3V)
    Attach 220k (240k) resistor in parallel to R8.
    The values are for LaunchPad v1.5.
    LP v1.4 divider's values are 10 times smaller, so adjust as necessary.
    Also, LP will not work below 3V.
     

  17. Like
    turd reacted to nexusone1984 in Best Path for Using Linux with MSP   
    Which linux distro are you moving to?
     
    I personally use Mint, but the packages come from the Ubuntu repository. There are easy to download pre-package compiler and support files.
     
    Link for package files for ubuntu/Mint download and install all the packages:
    https://launchpad.net/ubuntu/oneiric/+s ... ext=msp430
     
    other distros here at this link:
     
    http://sourceforge.net/apps/mediawiki/m ... SPGCC_Wiki
  18. Like
    turd reacted to zeke in Anyone notice the 8-pin MSP430 yet?   
    Presenting the MSP430G2230.
     
    Only 8 pins!
  19. Like
    turd reacted to oPossum in Using the internal temperature sensor   
    TI has some sample code for the internal temperature sensor, but it does not explain how to scale the ADC reading to useful units of degrees. Here is a step-by-step explanation of how to do the scaling with integer math for degrees C, K and F. There is also sample code to display the temperature on a Nokia 5110 LCD.

     
    The data sheet (SLAU144) has this formula for converting temperature in degrees Celsius to voltage.
    V = 0.00355 * C + 0.986

    What we need is a formula for converting voltage to temperature.
     
    Rewrite the data sheet fomula with temperature on the left
    0.00355 * C + 0.986 = V
     
    Divide both sides by 0.00355
    C + 277.75 = V / 0.00355
     
    Subtract 277.75 from both sides
    C = V / 0.00355 - 277.75
     
    Now we have a formula for converting voltage to temperature.
     
    The data sheet has this formula for converting voltage to ADC value, once again the opposite of what we neeed.

    For Vref- == 0
    A = 1023 * V / Vref
     
    Swap sides
    1023 * V / Vref = A
     
    Multiply by Vref
    1023 * V = A * Vref
     
    Divide by 1023
    V = A * Vref / 1023
     
    For a 1.5V reference
    V = A * 1.5 / 1023
     
    Simplify
    V = A * 0.0014663
     
    Substitute ADC conversion forumula for voltage in the temperature conversion formula.
    C = A * 0.0014663 / 0.00355 - 277.75
     
    Simplify
    C = A * 0.413 - 277.75
     
    Now we have a formula to convert ADC reading to temperature.
    It uses real numbers, so floating point math is required for good precision.
    Floating point is slow and requires more flash, so let's use integer math instead.
    Multiply by 65536 (2^16) and then divide by the same.
    C = (A * 27069 - 18202393) / 65536
     
    Use a right shift instead of divide. This will become a move of high word to low word.
    C = (A * 27069 - 18202393) >> 16
     
    Add 0.5 * 65536 to impove rounding.
    C = (A * 27069 - 18202393 + 32768) >> 16
     
    Simplify.
    C = (A * 27069 - 18169625) >> 16
     
    So that is how to go from ADC to degrees Celsius.
     
     
    To convert degrees C to degees K.
    K = C + 273.15
     
    Applied to ADC to degrees C conversion formula.
    K = (A * 27069 - 18169625) >> 16 - 273.15
     
    Implement with integer math by multiplying by 65536
    K = (A * 27069 - 18169625 - 17,901,158) >> 16
     
    Simplify.
    K = (A * 27069 - 268467) >> 16
     
    To convert degrees C to degrees F.
    F = C * 9 / 5 + 32
     
    Applied to voltage to degrees C conversion forumula
    F = (V / 0.00355 - 277.75) * 9 / 5 + 32
     
    Multiply by 9
    F = (V / 0.0003944 - 2499.75) / 5 + 32
     
    Divide by 5
    F = (V / 0.0019722 - 499.95) + 32
     
    Add 32
    F = V / 0.0019722 - 467.95
     
    Substitute ADC to voltage forumula
    F = A * 0.0014663 / 0.0019722 - 467.95
     
    Simplifiy
    F = A * 0.7435 - 467.95
     
    Convert to integer
    F = (A * 48724 - 30667156) >> 16
     
    Improve rounding
    F = (A * 48724 - 30667156 + 32768) >> 16
     
    Simplify
    F = (A * 48724 - 30634388) >> 16
     
    So now we have three formulas to convert ADC reading to degrees C, K and F using fast and compact integer math.
    C = (A * 27069 - 18169625) >> 16
    K = (A * 27069 - 268467) >> 16
    F = (A * 48724 - 30634388) >> 16
     
    Using the ADC value, rather than a different temperature scale, will ensure greatest precision for each temperature scale.
     
    main.c

    #include #include #include "lcd.h" #define ADC_SLEEP // Sleep during ADC conversion //#define SHOW_ADC // Show ADC raw and ADC millivolts // Print integer from -999 to 9999 using 12 x 16 font void print_int(int i, const unsigned y) { if(i < -999 || i > 9999) return; const unsigned neg = i < 0; if(neg) i = -i; div_t d; d.quot = i; unsigned x = 48; do { d = div(d.quot, 10); pd12(d.rem, x -= 12, y); } while(d.quot); if(neg) pd12(14, x -= 12, y); while(x) pd12(10, x -= 12, y); } // Print integer from 0 to 9999 vertically using 6 x 8 font void print_v(int i, unsigned x) { unsigned y = 4; unsigned c; if(i < 0 || i > 9999) return; div_t d; d.quot = i; do { d = div(d.quot, 10); c = d.rem + '0'; lcd_print((char *)&c, x, --y); } while(d.quot); c = ' '; while(y) lcd_print((char *)&c, x, --y); } void main(void) { unsigned adc; // ADC value int c, k, f; // Temperature in degrees C, K, and F unsigned mv; // ADC reading in millivolts // WDTCTL = WDTPW | WDTHOLD; // Disable watchdog reset // lcd_init(); // Initialize LCD lcd_clear(0); // pd12(15, 48, 0); // Degrees pd12(17, 59, 0); // F pd12(15, 48, 2); // Degrees pd12(16, 58, 2); // C pd12(15, 48, 4); // Degrees pd12(18, 59, 4); // K #ifdef SHOW_ADC // lcd_print("Am", 72, 4); // AD / mV lcd_print("DV", 72, 5); // #endif // // ADC10CTL0 = 0; // Configure ADC ADC10CTL1 = INCH_10 | ADC10DIV_3; // ADC10CTL0 = SREF_1 | ADC10SHT_3 | REFON | ADC10ON | ADC10IE; //ADC10CTL0 = SREF_1 | ADC10SHT_3 | REFON | ADC10ON | ADC10IE | REF2_5V; #ifdef ADC_SLEEP // ADC10CTL0 |= ADC10IE; // Enable ADC conversion complete interrupt #endif // // for(; { // for-ever #ifdef ADC_SLEEP // ADC10CTL0 |= (ENC | ADC10SC); // Begin ADC conversion __bis_SR_register(LPM0_bits + GIE); // Sleep until conversion complete #else // ADC10CTL0 &= ~ADC10IFG; // Clear conversion complete flag ADC10CTL0 |= (ENC | ADC10SC); // Begin ADC conversion while(!(ADC10CTL0 & ADC10IFG)); // Wait for conversion to complete #endif // // adc = ADC10MEM; // Read ADC // // Convert to temperature c = ((27069L * adc) - 18169625L) >> 16; // Vref = 1.5V //c = ((45115L * adc) - 18169625L) >> 16; // Vref = 2.5V // k = ((27069L * adc) - 268467L) >> 16; // Vref = 1.5V //k = ((45115L * adc) - 268467L) >> 16; // Vref = 2.5V // f = ((48724L * adc) - 30634388L) >> 16; // Vref = 1.5V //f = ((81206L * adc) - 30634388L) >> 16; // Vref = 2.5V // // Convert to millivolts mv = (96094L * adc + 32768) >> 16; // Vref = 1.5V //mv = (160156L * adc + 32768) >> 16; // Vref = 2.5V // // Display on LCD print_int(f, 0); // Degrees F print_int(c, 2); // Degrees C print_int(k, 4); // Degrees K // #ifdef SHOW_ADC // print_v(adc, 72); // ADC print_v(mv, 78); // ADC millivolts #endif // // //__delay_cycles(100000); // } // } #pragma vector = ADC10_VECTOR // ADC conversion complete interrupt __interrupt void ADC10_ISR(void) // { // __bic_SR_register_on_exit(LPM0_bits); // Wakeup main code } //
     
    lcd.h

    typedef enum { lcd_command = 0, // Array of one or more commands lcd_data = 1, // Array of one or more bytes of data lcd_data_repeat = 2 // One byte of data repeated } lcd_cmd_type; void lcd_send(const unsigned char *cmd, unsigned len, const lcd_cmd_type type); void lcd_home(void); void lcd_pos(unsigned char x, unsigned char y); void lcd_clear(unsigned char x); void lcd_init(void); void lcd_print(char *s, unsigned x, unsigned y); void pd12(unsigned n, unsigned x, unsigned y);
     
    lcd.c

    #include #include "lcd.h" //static const unsigned TXD = BIT1; static const unsigned RXD = BIT2; static const unsigned SWITCH = BIT3; static const unsigned LCD_CLK = BIT5; static const unsigned LCD_BACKLIGHT = BIT6; static const unsigned LCD_DATA = BIT7; static const unsigned LCD_DC = BIT0; // PORT2 static const unsigned LCD_CE = BIT1; // PORT2 void lcd_send(const unsigned char *cmd, unsigned len, const lcd_cmd_type type) { register unsigned mask; P2OUT &= ~LCD_CE; do { mask = 0x0080; do { if(*cmd & mask) { P1OUT &= ~LCD_CLK; P1OUT |= LCD_DATA; } else { P1OUT &= ~(LCD_CLK | LCD_DATA); } P1OUT |= LCD_CLK; mask >>= 1; } while(!(mask & 1)); if(!type) P2OUT &= ~LCD_DC; if(*cmd & mask) { P1OUT &= ~LCD_CLK; P1OUT |= LCD_DATA; } else { P1OUT &= ~(LCD_CLK | LCD_DATA); } P1OUT |= LCD_CLK; P2OUT |= LCD_DC; if(!(type & 2)) ++cmd; } while(--len); P2OUT |= LCD_CE; } static const unsigned char home[] = { 0x40, 0x80 }; void lcd_home(void) { lcd_send(home, sizeof(home), lcd_command); } void lcd_pos(unsigned char x, unsigned char y) { unsigned char c[2]; c[0] = 0x80 | x; c[1] = 0x40 | y; lcd_send(c, sizeof(c), lcd_command); } void lcd_clear(unsigned char x) { lcd_home(); lcd_send(&x, 504, lcd_data_repeat); lcd_home(); } void lcd_init(void) { static const unsigned char init[] = { 0x20 + 0x01, // function set - extended instructions enabled //0x80 + 64, // set vop (contrast) 0 - 127 0x80 + 66, // set vop (contrast) 0 - 127 0x04 + 0x02, // temperature control 0x10 + 0x03, // set bias system 0x20 + 0x00, // function set - chip active, horizontal addressing, basic instructions 0x08 + 0x04 // display control - normal mode }; P1REN = RXD | SWITCH; P1DIR = LCD_CLK | LCD_BACKLIGHT | LCD_DATA; P1OUT = LCD_CLK | RXD | SWITCH | LCD_BACKLIGHT; P2REN = 0; P2DIR = LCD_DC | LCD_CE; P2OUT = LCD_CE; __delay_cycles(20000); P2OUT |= LCD_DC; __delay_cycles(20000); lcd_send(init, sizeof(init), lcd_command); } static const unsigned char font6x8[96][5] = { 0x00, 0x00, 0x00, 0x00, 0x00, // 20 32 0x00, 0x00, 0x5F, 0x00, 0x00, // 21 33 ! 0x00, 0x07, 0x00, 0x07, 0x00, // 22 34 " 0x14, 0x7F, 0x14, 0x7F, 0x14, // 23 35 # 0x24, 0x2A, 0x7F, 0x2A, 0x12, // 24 36 $ 0x23, 0x13, 0x08, 0x64, 0x62, // 25 37 % 0x36, 0x49, 0x56, 0x20, 0x50, // 26 38 & 0x00, 0x08, 0x07, 0x03, 0x00, // 27 39 ' 0x00, 0x1C, 0x22, 0x41, 0x00, // 28 40 ( 0x00, 0x41, 0x22, 0x1C, 0x00, // 29 41 ) 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // 2A 42 * 0x08, 0x08, 0x3E, 0x08, 0x08, // 2B 43 + 0x00, 0x40, 0x38, 0x18, 0x00, // 2C 44 , 0x08, 0x08, 0x08, 0x08, 0x08, // 2D 45 - 0x00, 0x00, 0x60, 0x60, 0x00, // 2E 46 . 0x20, 0x10, 0x08, 0x04, 0x02, // 2F 47 / 0x3E, 0x51, 0x49, 0x45, 0x3E, // 30 48 0 0x00, 0x42, 0x7F, 0x40, 0x00, // 31 49 1 0x42, 0x61, 0x51, 0x49, 0x46, // 32 50 2 0x21, 0x41, 0x49, 0x4D, 0x33, // 33 51 3 0x18, 0x14, 0x12, 0x7F, 0x10, // 34 52 4 0x27, 0x45, 0x45, 0x45, 0x39, // 35 53 5 0x3C, 0x4A, 0x49, 0x49, 0x30, // 36 54 6 0x41, 0x21, 0x11, 0x09, 0x07, // 37 55 7 0x36, 0x49, 0x49, 0x49, 0x36, // 38 56 8 0x06, 0x49, 0x49, 0x29, 0x1E, // 39 57 9 0x00, 0x00, 0x14, 0x00, 0x00, // 3A 58 : 0x00, 0x00, 0x40, 0x34, 0x00, // 3B 59 ; 0x00, 0x08, 0x14, 0x22, 0x41, // 3C 60 < 0x14, 0x14, 0x14, 0x14, 0x14, // 3D 61 = 0x00, 0x41, 0x22, 0x14, 0x08, // 3E 62 > 0x02, 0x01, 0x51, 0x09, 0x06, // 3F 63 ? 0x3E, 0x41, 0x5D, 0x59, 0x4E, // 40 64 @ 0x7C, 0x12, 0x11, 0x12, 0x7C, // 41 65 A 0x7F, 0x49, 0x49, 0x49, 0x36, // 42 66 B 0x3E, 0x41, 0x41, 0x41, 0x22, // 43 67 C 0x7F, 0x41, 0x41, 0x41, 0x3E, // 44 68 D 0x7F, 0x49, 0x49, 0x49, 0x41, // 45 69 E 0x7F, 0x09, 0x09, 0x09, 0x01, // 46 70 F 0x3E, 0x41, 0x49, 0x49, 0x7A, // 47 71 G 0x7F, 0x08, 0x08, 0x08, 0x7F, // 48 72 H 0x00, 0x41, 0x7F, 0x41, 0x00, // 49 73 I 0x20, 0x40, 0x41, 0x3F, 0x01, // 4A 74 J 0x7F, 0x08, 0x14, 0x22, 0x41, // 4B 75 K 0x7F, 0x40, 0x40, 0x40, 0x40, // 4C 76 L 0x7F, 0x02, 0x1C, 0x02, 0x7F, // 4D 77 M 0x7F, 0x04, 0x08, 0x10, 0x7F, // 4E 78 N 0x3E, 0x41, 0x41, 0x41, 0x3E, // 4F 79 O 0x7F, 0x09, 0x09, 0x09, 0x06, // 50 80 P 0x3E, 0x41, 0x51, 0x21, 0x5E, // 51 81 Q 0x7F, 0x09, 0x19, 0x29, 0x46, // 52 82 R 0x26, 0x49, 0x49, 0x49, 0x32, // 53 83 S 0x01, 0x01, 0x7F, 0x01, 0x01, // 54 84 T 0x3F, 0x40, 0x40, 0x40, 0x3F, // 55 85 U 0x1F, 0x20, 0x40, 0x20, 0x1F, // 56 86 V 0x3F, 0x40, 0x38, 0x40, 0x3F, // 57 87 W 0x63, 0x14, 0x08, 0x14, 0x63, // 58 88 X 0x03, 0x04, 0x78, 0x04, 0x03, // 59 89 Y 0x61, 0x51, 0x49, 0x45, 0x43, // 5A 90 Z 0x00, 0x7F, 0x41, 0x41, 0x41, // 5B 91 [ 0x02, 0x04, 0x08, 0x10, 0x20, // 5C 92 '\' 0x00, 0x41, 0x41, 0x41, 0x7F, // 5D 93 ] 0x04, 0x02, 0x01, 0x02, 0x04, // 5E 94 ^ 0x80, 0x80, 0x80, 0x80, 0x80, // 5F 95 _ 0x00, 0x03, 0x07, 0x08, 0x00, // 60 96 ' 0x20, 0x54, 0x54, 0x54, 0x78, // 61 97 a 0x7F, 0x28, 0x44, 0x44, 0x38, // 62 98 b 0x38, 0x44, 0x44, 0x44, 0x28, // 63 99 c 0x38, 0x44, 0x44, 0x28, 0x7F, // 64 100 d 0x38, 0x54, 0x54, 0x54, 0x18, // 65 101 e 0x00, 0x08, 0x7E, 0x09, 0x02, // 66 102 f 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // 67 103 g 0x7F, 0x08, 0x04, 0x04, 0x78, // 68 104 h 0x00, 0x44, 0x7D, 0x40, 0x00, // 69 105 i 0x00, 0x20, 0x40, 0x40, 0x3D, // 6A 106 j 0x00, 0x7F, 0x10, 0x28, 0x44, // 6B 107 k 0x00, 0x41, 0x7F, 0x40, 0x00, // 6C 108 l 0x7C, 0x04, 0x78, 0x04, 0x78, // 6D 109 m 0x7C, 0x08, 0x04, 0x04, 0x78, // 6E 110 n 0x38, 0x44, 0x44, 0x44, 0x38, // 6F 111 o 0xFC, 0x18, 0x24, 0x24, 0x18, // 70 112 p 0x18, 0x24, 0x24, 0x18, 0xFC, // 71 113 q 0x7C, 0x08, 0x04, 0x04, 0x08, // 72 114 r 0x48, 0x54, 0x54, 0x54, 0x24, // 73 115 s 0x04, 0x04, 0x3F, 0x44, 0x24, // 74 116 t 0x3C, 0x40, 0x40, 0x20, 0x7C, // 75 117 u 0x1C, 0x20, 0x40, 0x20, 0x1C, // 76 118 v 0x3C, 0x40, 0x30, 0x40, 0x3C, // 77 119 w 0x44, 0x28, 0x10, 0x28, 0x44, // 78 120 x 0x4C, 0x90, 0x90, 0x90, 0x7C, // 79 121 y 0x44, 0x64, 0x54, 0x4C, 0x44, // 7A 122 z 0x00, 0x08, 0x36, 0x41, 0x00, // 7B 123 { 0x00, 0x00, 0x77, 0x00, 0x00, // 7C 124 | 0x00, 0x41, 0x36, 0x08, 0x00, // 7D 125 } 0x02, 0x01, 0x02, 0x04, 0x02, // 7E 126 ~ 0x00, 0x06, 0x09, 0x09, 0x06, // 7F 127 degrees }; void lcd_print(char *s, unsigned x, unsigned y) { unsigned char c[2]; c[0] = 0x80 | x; c[1] = 0x40 | y; lcd_send(c, sizeof(c), lcd_command); while(*s) { lcd_send(&font6x8[*s - 32][0], 5, lcd_data); lcd_send(&font6x8[0][0], 1, lcd_data); ++s; } } static const unsigned char num11x16[19][11 * 2] = { 0x00,0xF0,0xFC,0xFE,0x06,0x02,0x06,0xFE,0xFC,0xF0,0x00, // 0 0x00,0x07,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x07,0x00, 0x00,0x00,0x08,0x0C,0xFC,0xFE,0xFE,0x00,0x00,0x00,0x00, // 1 0x00,0x20,0x20,0x20,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x00, 0x00,0x0C,0x0E,0x06,0x02,0x02,0x86,0xFE,0x7C,0x38,0x00, // 2 0x00,0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x38,0x00, 0x00,0x0C,0x0E,0x86,0x82,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 3 0x00,0x18,0x38,0x30,0x20,0x20,0x31,0x3F,0x1F,0x0E,0x00, 0x00,0x00,0xC0,0x20,0x18,0x04,0xFE,0xFE,0xFE,0x00,0x00, // 4 0x00,0x03,0x02,0x02,0x02,0x22,0x3F,0x3F,0x3F,0x22,0x02, 0x00,0x00,0x7E,0x7E,0x46,0x46,0xC6,0xC6,0x86,0x00,0x00, // 5 0x00,0x18,0x38,0x30,0x20,0x20,0x30,0x3F,0x1F,0x0F,0x00, 0x00,0xC0,0xF0,0xF8,0xFC,0x4C,0xC6,0xC2,0x82,0x00,0x00, // 6 0x00,0x0F,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x0F,0x00, 0x00,0x06,0x06,0x06,0x06,0x06,0xC6,0xF6,0x3E,0x0E,0x00, // 7 0x00,0x00,0x00,0x30,0x3C,0x0F,0x03,0x00,0x00,0x00,0x00, 0x00,0x38,0x7C,0xFE,0xC6,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 8 0x00,0x0E,0x1F,0x3F,0x31,0x20,0x31,0x3F,0x1F,0x0E,0x00, 0x00,0x78,0xFC,0xFE,0x86,0x02,0x86,0xFE,0xFC,0xF8,0x00, // 9 0x00,0x00,0x00,0x21,0x21,0x31,0x1D,0x1F,0x0F,0x03,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x70,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // : 0x00,0x0E,0x0E,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // . 0x00,0x38,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC0,0x30,0x0C,0x00,0x00,0x00,0x00, // / 0x00,0x30,0x0C,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, // - 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x00,0x18,0x3C,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00, // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xF0,0xF8,0x0C,0x06,0x02,0x02,0x02,0x02,0x0E,0x0C,0x00, // C 0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x1C,0x0C,0x00, 0xFE,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x00,0x00,0x00, // F 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFE,0xFE,0x40,0xE0,0xB0,0x18,0x0C,0x06,0x02,0x00,0x00, // K 0x1F,0x1F,0x00,0x00,0x01,0x03,0x06,0x0C,0x18,0x10,0x00 }; void pd12(unsigned n, unsigned x, unsigned y) { unsigned char c[2]; c[0] = 0x80 | x; c[1] = 0x40 + y; lcd_send(c, 2, lcd_command); lcd_send(num11x16[n], 11, lcd_data); c[1] = 0x41 + y; lcd_send(c, 2, lcd_command); lcd_send(num11x16[n] + 11, 11, lcd_data); }
  20. Like
    turd reacted to chibiace in LP screw terminal power connector   
    I needed something to test my lm2576 3.3v switch mode power supply that i had built the other day, so i desoldered the male headers at the bottom of the launchpad and slotted in a cheap 2 way screw terminal.
     

     
    there is a tiny bit of over hang and only G G V are visible on the silkscreen but that is alright for me.
    im sure to use this for battery hookup in the future.
     
    if those 0.1" screw terminals weren't so damned expensive i would replace all of the other female headers with them. :twisted:
  21. Like
    turd reacted to V0JT4 in Universal Ripple Control Receiver   
    I'm using I2C in my project with USCI. Here is code for write and read with repeated start, 8 or 16 bit EEPROM data address is possible. It was inspired by Anderson's code. May be useful for someone else.
     
    i2c.h

    #ifndef I2C_H_ #define I2C_H_ typedef unsigned char u8; typedef signed char s8; typedef unsigned int u16; typedef signed int s16; typedef struct { u8 count; u8 state; u16 address; u8 *buffer; } i2c_data_t; #define size_tr(size, addr16) ((size-1)<<1)|(addr16 & 0x01) // number of bytes to transfer(1 to 128, 2+ for RX), device ID, buffer pointer, is 16bit addressing, memory address #define i2c_tx(size, id, buffer, addr16, address) i2c_trans(size_tr(size,addr16), id, buffer, address) #define i2c_rx(size, id, buffer, addr16, address) i2c_trans(size_tr(size,addr16), id|0x01, buffer, address) // number of bytes to transfer|16 bit addressing, device ID|dirrection, buffer pointer, memory address void i2c_trans(u8 size, u8 id, u8 buffer[], u16 address); void i2c_init(void); // setup u8 i2c_int(void); // data transfer interrupt u8 i2c_eint(void); // NACK interrupt #endif /*I2C_H_*/
     
    i2c.c

    #include "msp430g2553.h" #include "i2c.h" // i2c states #define WRITE 0x00 #define READ 0x01 #define ADDR16 0x02 #define ADDRTR 0x04 #define REPSTT 0x08 i2c_data_t i2c_data = {0, 0, 0, 0}; void i2c_init(void) { P1SEL |= BIT6 + BIT7; //Set I2C pins P1SEL2 |= BIT6 + BIT7; UCB0CTL1 |= UCSWRST; //Enable SW reset UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; //I2C Master, synchronous mode UCB0CTL1 = UCSSEL_2 + UCSWRST; //Use SMCLK, keep SW reset UCB0BR0 = 12; //fSCL = SMCLK/12 = ~100kHz UCB0BR1 = 0; UCB0CTL1 &= ~UCSWRST; //Clear SW reset, resume operation IE2 |= UCB0TXIE | UCB0RXIE; //Enable TX, RX interrupt UCB0I2CIE = UCNACKIE; // NACK interrups } void i2c_trans(u8 size, u8 id, u8 *buffer, u16 address) { i2c_data.state = (id & READ) | ADDRTR; // byte counter if (size & 0x01) i2c_data.state |= ADDR16; i2c_data.count = (size >> 1) + 1; // byte counter i2c_data.address = address; // byte counter i2c_data.buffer = buffer; // byte counter UCB0I2CSA = id >> 1; // Slave Address 01101000 0x68 RTC //Slave Address 01010000 0x50 EEPROM UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts // Remain in LPM0 until all data is transferred } u8 i2c_int(void) { if (i2c_data.state == WRITE) { if (i2c_data.count > 0) { //Check TX byte counter UCB0TXBUF = *i2c_data.buffer++; // Load TX buffer i2c_data.count--; //Decrement TX byte counter } else if (i2c_data.count == 0) { //last byte transferred UCB0CTL1 |= UCTXSTP; //I2C stop condition while (UCB0CTL1 & UCTXSTP); //Ensure stop condition got sent IFG2 &= ~UCB0TXIFG; //Clear USCI_B0 TX int flag return 1; //Exit LPM0 } } else if (i2c_data.state == READ) { *i2c_data.buffer++ = UCB0RXBUF; i2c_data.count--; //Decrement RX byte counter if (i2c_data.count == 1) { //Check RX byte counter, 1 byte remaining UCB0CTL1 |= UCTXSTP; // I2C stop condition } if (i2c_data.count == 0) { //Check RX byte counter, last byte received while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent return 1; // Exit LPM0 } } else if (i2c_data.state & ADDR16) { // high byte address transmit UCB0TXBUF = _swap_bytes(i2c_data.address); i2c_data.state &= ~ADDR16; } else if (i2c_data.state & ADDRTR) { // low byte address transmit UCB0TXBUF = i2c_data.address; i2c_data.state &= ~ADDRTR; if (i2c_data.state) { // repeated Start for RX i2c_data.state |= REPSTT; } } else if (i2c_data.state & REPSTT) { // repeated start required i2c_data.state &= ~REPSTT; UCB0CTL1 &= ~UCTR; // I2C RX UCB0CTL1 |= UCTXSTT; // I2C repeated Start condition for RX IFG2 &= ~UCB0TXIFG; //Clear USCI_B0 TX int flag } return 0; } u8 i2c_eint(void) { if (UCB0STAT & UCNACKIFG) { // send STOP if slave sends NACK UCB0CTL1 |= UCTXSTP; UCB0STAT &= ~UCNACKIFG; return 1; } return 0; }
     
    example main.c

    #include "msp430g2553.h" #include "i2c.h" u8 txdata[] = {'H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D'}; u8 rxdata[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; void main(void) { WDTCTL = WDTPW + WDTHOLD; //Stop WDT BCSCTL1 = CALBC1_1MHZ; //Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; // UART setup P1SEL = BIT1 + BIT2; //Set RXD and TXD P1SEL2 = BIT1 + BIT2; UCA0CTL1 |= UCSSEL_2 | UCSWRST; //Have USCI use SMCLK AKA 1MHz main CLK UCA0BR0 = 104; //Baud = 9600 UCA0BR1 = 0; UCA0MCTL = UCBRS_1; //Modulation UCA0CTL1 &= ~UCSWRST; //Start USCI i2c_init(); // init I2C __delay_cycles(20000); //Just a start up delay i2c_rx(11, 0xA0, rxdata, 0, 0); //i2c RX data u8 i = 0; while (i < 11) { while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = rxdata[i]; //UART TX data i++; } i2c_tx(11, 0xA0, txdata, 0, 0); //i2c TX 11 bytes("HELLO WORLD") __delay_cycles(20000); //Allow EEPROM to write data i2c_rx(11, 0xA0, rxdata, 0, 0); //i2c RX data i = 0; while (i < 11) { while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = rxdata[i]; //UART TX data i++; } __bis_SR_register(CPUOFF + GIE); //Wait for a reset } // I2C data transfer vector #pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) { if (i2c_int()) __bic_SR_register_on_exit(CPUOFF); //Exit LPM0; } // I2C status vector #pragma vector = USCIAB0RX_VECTOR __interrupt void USCIAB0RX_ISR(void) { if (i2c_eint()) { while (!(IFG2 & UCA0TXIFG)); // send error via UART UCA0TXBUF = '#'; } }
  22. Like
    turd got a reaction from oPossum in MSP430FG4618 and 24LC512   
    Here's an example using an MSP430G2553 and a 24LC256.
    It's not perfect but it works.
     
    It first writes "HELLO WORLD" too 0x0000 then reads it back and sends it out the UART at 9600.
    I hope it helps
     

    //#include //For mspgcc //#include //For mspgcc #include "msp430g2553.h" //Address word + "HELLO WORLD" unsigned char txdata[14] = {0x00, 0x00, 0x00, 0x48, 0x45, 0x4C, 0x4C, 0x4F, 0x20, 0x57, 0x4F, 0x52, 0x4C, 0x44}; unsigned char rxdata[12]; unsigned char tx_byte_count; unsigned char rx_byte_count; unsigned char tx_byte_counter; unsigned char rx_byte_counter; unsigned char i; unsigned char tx_rx; void i2c_tx(unsigned char tx_count); void i2c_rx(unsigned char rx_count); void main(void) { WDTCTL = WDTPW + WDTHOLD; //Stop WDT BCSCTL1 = CALBC1_1MHZ; //Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; P1SEL = BIT1 + BIT2; //Set RXD and TXD P1SEL2 = BIT1 + BIT2; UCA0CTL1 |= UCSSEL_2; //Have USCI use SMCLK AKA 1MHz main CLK UCA0BR0 = 104; //Baud = 9600 UCA0BR1 = 0; UCA0MCTL = UCBRS_1; //Modulation UCA0CTL1 &= ~UCSWRST; //Start USCI P1SEL |= BIT6 + BIT7; //Set I2C pins P1SEL2|= BIT6 + BIT7; UCB0CTL1 |= UCSWRST; //Enable SW reset UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; //I2C Master, synchronous mode UCB0CTL1 = UCSSEL_2 + UCSWRST; //Use SMCLK, keep SW reset UCB0BR0 = 12; //fSCL = SMCLK/12 = ~100kHz UCB0BR1 = 0; UCB0I2CSA = 0b1010000; //Slave Address UCB0CTL1 &= ~UCSWRST; //Clear SW reset, resume operation IE2 |= UCB0TXIE; //Enable TX interrupt IE2 |= UCB0RXIE; //Enable RX interrupt __delay_cycles(20000); //Just a start up delay i2c_tx(13); //i2c TX 13 bytes(Address word + "HELLO WORLD" __delay_cycles(20000); //Allow 24LC256 to write data i2c_tx(2); //i2c TX address i2c_rx(12); //i2c RX data for(i = 1; i < 12; i++) { while(!(IFG2 & UCA0TXIFG)); UCA0TXBUF = rxdata[i]; //UART TX data } __bis_SR_register(CPUOFF + GIE); //Wait for a reset } void i2c_tx(unsigned char tx_count) { tx_rx = 0; tx_byte_count = tx_count + 1; tx_byte_counter = tx_count; // Load TX byte counter UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts // Remain in LPM0 until all data is TX'd } void i2c_rx(unsigned char rx_count) { tx_rx = 1; rx_byte_count = rx_count + 1; rx_byte_counter = rx_count; // Load RX byte counter UCB0CTL1 &= ~UCTR; // I2C RX UCB0CTL1 |= UCTXSTT; // I2C start condition __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts // Remain in LPM0 until all data is RX'd } //interrupt(USCIAB0TX_VECTOR) USCIAB0TX_ISR(void) #pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) //For mspgcc { if(tx_rx == 0) { if (tx_byte_counter > 0) //Check TX byte counter { UCB0TXBUF = txdata[tx_byte_count - tx_byte_counter]; // Load TX buffer tx_byte_counter--; //Decrement TX byte counter } else if(tx_byte_counter == 0) { UCB0CTL1 |= UCTXSTP; //I2C stop condition while (UCB0CTL1 & UCTXSTP); //Ensure stop condition got sent IFG2 &= ~UCB0TXIFG; //Clear USCI_B0 TX int flag __bic_SR_register_on_exit(CPUOFF); //Exit LPM0 } } else if(tx_rx == 1) { if (rx_byte_counter > 0) //Check RX byte counter { rxdata[rx_byte_count - rx_byte_counter] = UCB0RXBUF; rx_byte_counter--; //Decrement RX byte counter } else if(rx_byte_counter == 0) { UCB0CTL1 |= UCTXSTP; // I2C stop condition while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent rxdata[rx_byte_count - (rx_byte_counter + 1)] = UCB0RXBUF; rxdata[rx_byte_count - (rx_byte_counter + 1)] = UCB0RXBUF; IFG2 &= ~UCB0RXIFG; // Clear USCI_B0 RX int flag __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } } }
    It hasn't been tested with CCS or IAR just mspgcc.
     



  23. Like
    turd reacted to jotux in LaunchLib - a new library for the launchpad and fraunchpad   
    Long-time lurker here to share a library I've been working on.
     
    LaunchLib is an easy-to-use (you still need to know C) library to help quickly develop projects on the launchpad (MSP430G2553) and fraunchpad (MSP430FR5739). The code is all open source and hosted on github. Most of it is well documented (doxygen style) and whenever I make changes I update the docs -- so they're always up-to-date.
     
    http://jotux.github.com/LaunchLib/
    https://github.com/jotux/LaunchLib
     
    Some unique features:
    - Selectable blocking or non-blocking UART
    - State machine framework
    - Scheduling mechanisms (callbacks and callouts)
    - GPIO interrupt handler (attach functions to interrupts)
    - Hardware PWM generation
    - Lots of examples
    - Cute logo
     
    I've licensed all the code with the open source MIT license and would love to see some forks and pull requests on github.
     
    (Admin: please whitelist so I can add links)
  24. Like
    turd reacted to ozymandias in Makerbot redone with '430s   
    I've had a Makerbot Cupcake CNC for a while now and have been wanting to convert it from the current arduino-bobino-fee-fi-sanguino controller to lightweight and modular MSP430 subsystems that would be useful in other control and robotics projects.
     
    currently i have beta software that takes in UART data from a computer (i'm using GTKterm in linux) to the launchpad, where a G2231 controls chip select bits and resends the byte to (currently 3) other 2231's.
     
    What i'm planning to do soon is modify the Makerbot to "close the loop" as far as control. Currently, you only theorectically know what state (where each bit is) by knowing what you've told it to do already; the "open loop" control (usually bad).
     
    I've put up beta code in the code vault and i should :!: have proof of concept up and running by the end of the week.
  25. Like
    turd reacted to ozymandias in BETA G2231 UART RX/SPI TX and SPI RX/ stepper signals   
    Project: control 3 MSP430G2231's using a single G2231 as a bridge/converter/demultiplexer that recieves data through the USB
     
    the bridge takes bytes and puts alternately sends them to recievers 1-3.
     
    the recievers' P1.0 and P1.6 go to stepper motor controllers to step on rising edge and control direction, respectively.
     
    "bridge" part:
    -recieves bytes from 2400 8N1 input to P1.1 (requires launchpad 'RXD' jumper to be removed and the pin on the FTDI side connected to P1.1)
     
    -after reception, transmits each byte out of P1.6 as MOSI and P1.5 as SCLK.
     
    -cycles through bringing one of three output pins low as a chip select
     

    #include #include // Conditions for 2400 Baud SW UART, ACLK = 32768 #define Bitime_5 0x06 // ~ 0.5 bit length + small adjustment #define Bitime 0x0E // 427us bit length ~ 2341 baud #define RXD 0x02 #define TXD 0x20 #define LED1 0x01 #define LED2 0x40 unsigned char RXTXData; unsigned char BitCnt; unsigned char temp; static void __inline__ delay(register unsigned int n); int main (void){ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer CCTL0 = OUT; // TXD Idle as Mark TACTL = TASSEL_1 + MC_2; // ACLK, continuous mode P1SEL = TXD + RXD; // P1DIR = TXD + LED1 + BIT4 + BIT3; P1OUT = LED1 + BIT4 + BIT3; USICTL0 = USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE | USISWRST; // Port, SPI Master USICTL1 = USICKPH | USIIE; USICKCTL = 0xE4;// /128 aclk? temp = 0; while(1){ P1OUT |= LED1 + BIT4 + BIT3; BitCnt = 0x8; // Load Bit counter CCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Cap _BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interr until char RXed if(temp == 2){ temp = 0; }else{ temp = temp +1; } } } // #pragma vector=TIMERA0_VECTOR interrupt(TIMERA0_VECTOR) Timer_A (void){ CCR0 += Bitime; // Add Offset to CCR0 if( CCTL0 & CAP ){ // Capture mode = start bit edge CCTL0 &= ~ CAP; // Switch from capture to compare mode CCR0 += Bitime_5; }else{ RXTXData = RXTXData >> 1; if (CCTL0 & SCCI) // Get bit waiting in receive latch RXTXData |= 0x80; BitCnt --; // All bits RXed? if ( BitCnt == 0){ USISRL = RXTXData; if(temp == 0){ P1OUT &= ~LED1; P1OUT |= BIT4 + BIT3; }else if(temp == 1){ P1OUT &= ~BIT4; P1OUT |= LED1 + BIT3; }else if(temp == 2){ P1OUT &= ~BIT3; P1OUT |= LED1 + BIT4; } USICNT |= 0x08; USICTL0 &= ~USISWRST; while (!(USIIFG & USICTL1)); USICTL0 |= USISWRST; delay(0); P1OUT |= LED1 + BIT4 + BIT3; CCTL0 &= ~ CCIE; // All bits RXed, disable interrupt _BIC_SR_IRQ(LPM3_bits + GIE); // Clear LPM3 bits from 0(SR) } } } static void __inline__ delay(register unsigned int n) { __asm__ __volatile__ ( "1: \n" " dec %[n] \n" " jne 1b \n" : [n] "+r"(n)); }
     
    The reciever recieves the byte from the bridge and in state machine fashion puts the byte in:
    -a counter for number of steps to take
    -determines to set or clear a direction bit
    -sets TACCR0 to control toggle rate
     

    #include #include unsigned int bufff; unsigned char count; int main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1OUT = 0x00; // P1.4 set, else reset P1DIR = 0x01 + BIT6; // P1.0 output, else input USICTL0 |= USIPE7 + USIPE5; // Port, SPI slave USICTL1 |= USIIE; // Counter interrupt, flag remains set USICTL0 &= ~USISWRST; // USI released for operation USICNT = 8; // init-load counter bufff = 0; count = 0; TACTL = TASSEL_1 | MC_1; //Set TimerA to use auxiliary clock in UP mode TACCTL0 = CCIE; //Enable the interrupt for TACCR0 match TACCR0 = 2; _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt while(1){ } } // USI interrupt service routine interrupt(USI_VECTOR) universal_serial_interface(void){ if(count == 0){//bufff if(USISRL > 0x7A){ bufff = bufff + 0xFF00; }else{ bufff = bufff + USISRL; } }else if(count == 1){//dir if(USISRL > 0x3F){ P1OUT |= BIT6; }else{ P1OUT &= ~BIT6; } }else if(count == 2){//speed TACCR0 = USISRL; }else{ count = 0; } count = count + 1; if(count == 3){ count = 0; } USICNT = 8; // re-load counter } interrupt(TIMERA0_VECTOR) TIMERA0_ISR(void) { if( bufff > 0){ P1OUT ^= BIT0; bufff = bufff - 1; } }
     
    PROBLEMS:
    -the bridge can't pass data through it too fast. one must wait about ~200ms until the next byte is sent to prevent data loss. (the code isn't optimized and kinda "fatty" in all likelihood).
    -since the TimerA assignments from USI data occur in the USI-ISR (and i haven't found a reliable way to do it otherwise), the data isn't 'pushed' into TimerA until the next byte is recieved.
    -it would be cool to not have to modify the jumpers on the launchpad to do the UART, but its based on TI code that worked so i went with it.
×
×
  • Create New...