Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Reputation Activity

  1. Like
    LiviuM reacted to chicken in Basic MSP430 GPIO Macros   
    In my project, I use a few basic macros for GPIO. The goal is, that I can easily redefine pin assignment in a central location without compromising performance or code size.
    The macros (gpiomacros.h):
    // MSP430 gpio macros #define GPIO_SEL(port) P ## port ## SEL #define GPIO_DIR(port) P ## port ## DIR #define GPIO_OUT(port) P ## port ## OUT #define GPIO_IN(port) P ## port ## IN #define GPIO_IS_INPUT(port,pin) { GPIO_SEL(port) &= ~(pin); GPIO_DIR(port) &= ~(pin); } #define GPIO_IS_OUTPUT(port,pin) { GPIO_SEL(port) &= ~(pin); GPIO_DIR(port) |= (pin); } #define GPIO_IS_PERIPHERAL_IN(port,pin) { GPIO_SEL(port) |= (pin); GPIO_DIR(port) &= ~(pin); } #define GPIO_IS_PERIPHERAL_OUT(port,pin) { GPIO_SEL(port) |= (pin); GPIO_DIR(port) |= (pin); } #define GPIO_SET(port,pin) { GPIO_OUT(port) |= (pin); } #define GPIO_CLEAR(port,pin) { GPIO_OUT(port) &= ~(pin); } #define GPIO_READ(port,pin)  ( GPIO_IN(port) & (pin) ) In a central configuration file (e.g. hardware.h) I assign pins like this:
    // Pin assignment #define LED1_PIN BIT1 #define LED1_PORT 6 #define LED2_PIN BIT0 #define LED2_PORT 1 And then in the code I interact with GPIO like this:
    // Setup LEDs GPIO_IS_OUTPUT(LED1_PORT, LED1_PIN); GPIO_IS_OUTPUT(LED2_PORT, LED2_PIN); // Turn off LEDs GPIO_CLEAR(LED1_PORT, LED1_PIN); GPIO_CLEAR(LED2_PORT, LED2_PIN); The macros are resolved in two steps:
    1. Higher level "functions" define the commands. E.g. GPIO_SET(), GPIO_IS_OUTPUT(), ..
    2. Lower level macros used within those functions translate port, pin to a register. E.g. GPIO_IN(), GPIO_SEL(), ..
    The end result is code like you would write when directly working with the GPIO registers. E.g. P2OUT &= ~BIT0; Note that this translation is done by the C pre-processor before the code is compiled.
    This all works fine and dandy, with the exception of port J. Port J doesn't have a SEL register, which breaks the 1st half of the GPIO_IS_OUTPUT and GPIO_IS_INPUT macros. I currently work around this by adding special GPIO_IS_OUTPUT/INPUT_J macros, but then the main code needs to include some logic to invoke the proper macro.
    #if (LED2_PORT == J) GPIO_IS_OUTPUT_J(LED2_PORT, LED2_PIN); #else GPIO_IS_OUTPUT(LED2_PORT, LED2_PIN); #endif Any ideas, how I could include a condition inside macros, that checks whether the port is J, and if so excludes the GPIO_SEL command?
    And yes, I could probably use C++ templates with identical results and an easy workaround for port J, but I'd like to avoid migrating my plain old C project.
    Edit: Added a few missing parentheses, thanks to Rickta59 for spotting that
  2. Like
    LiviuM reacted to roadrunner84 in Basic MSP430 GPIO Macros   
    You could consider using C++ template programming instead of C style defines.
    I haven't tested this, but it would go something like this:
    template <int port> void GPIO_IS_INPUT(int pin) { GPIO_SEL(port) &= ~(pin); GPIO_DIR(port) &= ~(pin); } template <> void GPIO_IS_INPUT<J>(int pin) { GPIO_DIR(J) &= ~(pin); } Now instead of passing port as a macro like function parameter, pass it as a template parameter
    GPIO_IS_INPUT<LED1_PORT>(LED1_PIN); I'm not entirely sure this will work though; the double-hash preprocessor operator is very tricky.
    You could go all the way with these templates and get gone with the macros entirely.
    If you really want no function call overhead, just make them inline.
  3. Like
    LiviuM got a reaction from yyrkoon in UART - Sending 3 bytes per start/stop bit sets.   
    Strange, I was thinking the English is my week point...
    What I tried to say is, if you look the diagram at page 4 in the Microchips AN, you'll see that every time the bit value changes (0->1 or 1->0) you don't have a transition at the end of bit, but if the bit repeats, you have a transition in the middle of the bit (the active one) and one transition at the end of bit.
    But looking now to the same diagram, I see now that if you can detect the start edge (first H->L transition), there are maybe better criteria to decode the bits.
  4. Like
    LiviuM got a reaction from yyrkoon in UART - Sending 3 bytes per start/stop bit sets.   
    For Manchester decoding (not on micro controllers, on other equipment), I've measured the time distance between consecutive edges. If the distance is half of the bit length, the last bit is repeated, if the distance is the bit length, the last bit is inverted.
    If you use in interrupt to detect the falling edge and to start a timer, and as you know the first (start) bit is a zero, detecting the next bits shouldn't be to difficult.
  5. Like
    LiviuM got a reaction from OzGrant in Determining Board Selection   
    you can use the for sure the uC name:
    #if defined(__TM4C1294NCPDT__) /*tivac LM4C1294 writes 4 locations at once;*/ In older Arduino IDE's I've used the board name as well, but not sure how the newer IDEs work:
    #if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) Regards,
    LE Because of the "command line defines" (-D compiling option), I think in the last Energia (1.6.10E18) you can use "ENERGIA_board-name", with the "board-name" found in the boards.txt file. For my TivaC TM41294XL, the boards.txt shows:
    EK-TM4C1294XL.build.board=EK-TM4C1294XL and the compile option is
  6. Like
    LiviuM got a reaction from yyrkoon in UART - Sending 3 bytes per start/stop bit sets.   
    in the data sheets of some PIC uC (PIC18F13K50, for example), in the description of the EUSART synchronous mode, there is specified:
    Maybe it is what you are looking for?
  7. Like
    LiviuM reacted to Fmilburn in It's Halloween Again   
    Here are my finished projects for the season...
    This is a princess tiara made from the wearable G2553 I posted above.  It drives 3 WS2812 "neopixels" on a tiara that I bought at the dollar store.  The WS2812 were ordered from Aliexpress and I find them difficult to solder up in a chain by hand.  I need to put together a jig or something to hold things in place and make it easier.

    All princesses need a magic wand and this one came with the tiara.  I cut out a star shape from some 4x6 cm 0.1" pitch PCB and soldered a blinking RGB LED, coin cell holder, and a tilt ball type switch to it.  The wand turns off when pointed down and on when lifted up while blinking different colors.  Because of bounce in the switch it kind of randomly blinks itself when shaken which is interesting.  I took a number of pictures to capture the 3 colors shown.

    The big project was the ferry boat.  Here is a photo of one of the many ferry boats that run in the Seattle area:

    I start by choosing a main box to work from and shape it.

    Then lay out more pieces to get an idea of what it will look like.

    Then cut to shape, glue everything up, and paint.  The electronics are more WS2812 and another G2553 wearable.  I had planned to add more electronic gizmos to this but ran out of time.  I guess that leaves me with something to do next year though.

    My grandson has been helping a bit.  He is really into Lego.  He built this pumpkin and then we put an LED into that is just taped to a coin cell.

    Finally, some satisfied customers at the local fall festival parade...

  8. Like
    LiviuM reacted to Rickta59 in neo430 - msp430 compatible FPGA processor   
    For a long time, I have had an interest in FPGA development. You can find boards that come with a JTAG programmer on ebay for less than $20. The following ebay link shows a board similar to the one I had purchased http://www.ebay.com/itm/361568712810  I experimented with it a lot for a while and then I probably got distracted by some new TI toy  Occasionally, I would pick it up and try different things with it. However, the cost and form factor of the chips discourages me from doing anything real with it.  For me these things are more of an educational plaything.
    Yesterday, I noticed the neo430 project on opencores.org. It is an msp430 compatible processor implemented in VHDL. It didn't take me long to get it installed and it actually seems to work pretty well. There are some difference between the neo430 and the msp430. ( see list below for the details ) Using the Altera Cyclone II EP2C5 board I linked above I was able to use the example code to create an msp430 like device with 4K of ROM and 4K of RAM. It runs a serial bootloader over its UART peripheral and allows you to toggle the pins using its parallel port peripheral. It has a simple timer peripheral. It has its own custom peripherals and 'C' header files setup to access those. It comes all setup to use msp430-gcc as a development tool with the device you create.
    The instructions are pretty complete neo430 instructions  , I just followed them to get started.  For my Altera chip, I used the free web edition of quartus II 13.0.1 sp1 to convert the VHDL code into a loadable bitstream. Once you load that on to the FPGA chip using the USB-Blaster, a serial terminal is used to interact with the bootloader and upload msp430-gcc compiled files.  The provided makefiles automate the msp430 code creation process.  I'm using this on linux and I had to make a few changes to point at the directory where my msp430-gcc is installed. If you are windows user it will probably just work out of the box for you.

    I'll try and post more on my experiments.  In the meantime, I thought others might find it interesting.
    Functional Diagram:

    Memory Layout:

  9. Like
    LiviuM reacted to greeeg in GPS logger for a local Beagle club   
    Polyurethane parts have come up nicely.

    Main advantages of this method of rapid prototyping
    Part cost is low these use about $0.05 of polyurethane resin. Parts can easily be coloured using dyes. (as demonstrated) Very little time needed for each cast (about 5 minutes) 1-2 Hour cure time 1-1 replica to original part. Of course you need to invest the time and money to make the silicone molds to begin with. So for a single part 3d printing is often the preferred approach.

    The parts are a perfect fit over the button and LEDs.

  10. Like
    LiviuM got a reaction from stasundr in [Energia Library] Petit FatFS SD Card Library   
    There are some limitation in using the write function. Calin has listed them in the post 4.
    Impossibility to change the size of the file is one of them.
  11. Like
    LiviuM got a reaction from stasundr in [Energia Library] Petit FatFS SD Card Library   
    PFatFS uses the 8.3 naming convention.That means, a longer name will be "truncated" to 8 characters. In the case of a file with a name as you used ("SD card test.txt"), PFatFS shows me it as "SDCARD~1.TXT".
    Maybe an ideea will be to start keeping just the directory listing part from the test sketch, to see if you have communication and just the name is wrong, or you don't have communication at all.
    /*-----------------------------------------------------------------------*/ /* Program Main                                                          */ /*-----------------------------------------------------------------------*/ void loop() {     Serial.println();     Serial.println("Open root directory.");     delay(100);         rc = FatFs.opendir(&dir, "");     if (rc) die(rc);     Serial.println();         Serial.println("Directory listing...");         delay(100);     for (; {         rc = FatFs.readdir(&dir, &fno);    /* Read a directory item */         if (rc || !fno.fname[0]) break;    /* Error or end of dir */         if (fno.fattrib & AM_DIR) {Serial.print("<dir>\t"); Serial.println(fno.fname);delay(100);}         else {Serial.print(fno.fsize);Serial.print("\t"); Serial.println(fno.fname);delay(100);}     }     if (rc) die(rc);         Serial.println();     Serial.print("Test completed.");     //for (; ; } PS I'm using a tivac board.
  • Create New...