Jump to content
43oh

calinp

Members
  • Content Count

    46
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Like
    calinp got a reaction from Rei Vilo in [SOLVED] Software / Bit-bang I2C library for Energia   
    Hi Rei,
    I found a I2C software lib for Arduino and after making the necessary changes it seems to work. At least it detects the address range of a small eeprom using the included example.
    The original with more examples is at http://forums.adafruit.com/viewtopic.php?f=25&t=13722
     
    Calin
    I2cMaster.zip
  2. Like
    calinp got a reaction from muhammet in [Energia Library] Petit FatFS SD Card Library   
    A small update:
    - all config settings in one file - pffconf.h
    - a soft SPI driver ( shuftIn/shiftOut ) that can be enabled in pffconf.h. It defaults on HW SPI pins, but these can be changed using FatFs.begin(cs_pin, sclk_pin, mosi_pin, miso_pin); . The speed is very low, but it frees 3 pins that can be used as analog inputs or I2C.
    - added a small benchmarking example
     
    Tested on MSP430G2553 and Stellaris Launchpads. A minimal program should work also on MSP430G2452. 
    On fraunchpad the examples compile without errors but I don't have the board to test it.
     
    Calin
     
     
    PFatFs10.zip
    PFatFs_SpeedTest.txt
    PFatFs_SpeedTest430.txt
  3. Like
    calinp got a reaction from energia in [SOLVED] Software / Bit-bang I2C library for Energia   
    Hi Rei,
    I found a I2C software lib for Arduino and after making the necessary changes it seems to work. At least it detects the address range of a small eeprom using the included example.
    The original with more examples is at http://forums.adafruit.com/viewtopic.php?f=25&t=13722
     
    Calin
    I2cMaster.zip
  4. Like
    calinp got a reaction from sirri in Real-Time Clock (RTC) Library for the MSP430/LaunchPad   
    Hi Sirri,
     
    Check this Energia library to see how you can get timer interrupts without disturbing PWM (and tone) generation: http://forum.43oh.com/topic/2861-energia-library-mstimer2/
     
    Or try using a different pin. According to pins_energia.h "On the 20pin devices, upto 3 analog outputs are available
    T0A1, T1A1 and T1A2 "  
        T1A0, /* 8 - P2.0 note: A0 output cannot be used with analogWrite */     T1A1, /* 9 - P2.1 */     T1A1, /* 10 - P2.2 */     T1A0, /* 11 - P2.3 note: A0 output cannot be used with analogWrite */     T1A2, /* 12 - P2.4 */     T1A2, /* 13 - P2.5 */   Regards, Calin
  5. Like
    calinp got a reaction from Erni in Beginner Library question   
    Hi Erni,
    Try the one posted in Energia libraries.
     
    Calin
  6. Like
    calinp reacted to energia in SPI pin map for Stellaris Launchpad (LM4F120)   
    Not a stupid question at all. The pin mapping for the Stellaris Launchpad can be found here: https://github.com/energia/Energia/wiki/Hardware
    The default SPI pins are PB_6 (MISO), PB_7 (MOSI) and, PB_4 (SCK). Note that in the example code there the Chip Select pin is mapped to pin 10 (int CS=10;). If you leave this as default then on the Stellaris Launchpad this would be PA_7 (See pin mapping).
  7. Like
    calinp reacted to jeshuah in Real-Time Clock (RTC) Library for the MSP430/LaunchPad   
    Hi all,
     
    I'm working on a simple alarm clock with an RGB 16x2 LCD display as a learning vehicle for the MSP430/LaunchPad and Energia.  This thread has been awesome -- many thanks to xv4y and grahamf72 for posting their code!
     
    I needed a more full-functioned calendar than what Graham had posted in RTCplus.zip on 1/29 (I haven't checked out his latest update in the "Libraries" section yet), so I took a slightly different tack and used Yan's timer code to create a simple RTC library that can be used to synchronize with the Time.h (and TimeAlarm.h) Arduino libraries here:
    http://playground.arduino.cc/Code/time
     
    The library is attached, along with an example sketch, in case any one else finds it useful...
     
    - Jesh
     
    MSP430RTC.zip
    LCD_light_clock_example.zip
  8. Like
    calinp reacted to grahamf72 in [Energia Library] MSP430 Real Time Clock   
    Attached is my latest version of the Real Time Clock library, adapted from xv4y's original library.  Some significant changes in this version are:
    Now works with both the MSP430G2553 and the MSP430G2452 processors (with some limitations on the 2452). The library may work on other processors, but I don't have any to test with. Rewrite of the logic used to detect the number of days in a month and leap year detection so that it uses considerably less RAM. Option to use the built-in VLO clock. The VLO is much less accurate than the crystal - about the best that can be achieved is accuracy to within a few minutes per day. The advantage of the VLO is that it frees up 2 IO pins, and can be used if you can't solder the tiny crystal to the launchpad. If you don't need a very accurate clock, or have a means of external synchronisation, the VLO may be sufficient for your needs. The #define's that configure the settings of the timer have been moved to a separate RTCconfig.h file, so they are easier to edit without having to edit the main header file. Documentation has been moved from the header file into a separate .txt file. Some example files have been included in the library. Known Limitations:
    Because the MSP430G2452 only has one timer, the RTC library cannot be used in conjunction with other functions that also require the timer. This includes Serial, AnalogWrite, Tone, and possibly some others. Because the MSP430G2452 doesn't have hardware serial, this means that the RTC library and Serial are completely incompatible.
    RTCplus.zip
  9. Like
    calinp reacted to Rickta59 in [Energia Library] sw_serial_t template based UART code   
    Yet another software only serial class implementation? What makes this one different? C++ template based with asm routines to implement read and write. Works with any pin and port combination. You can mix and match, put read on P2.0 and write on P1.2. Small size even with Energia. Multiple instances allowed. Each instance uses about 12 bytes so you are only limited by the number of pins and memory on your chip. Big plus, doesn't use the timer. Read on if this piques your interest.

    This code implements a C++ template based software only blocking serial UART class. It doesn't use the timer peripheral so it can be used with other code that might want to monopolize the timer(s). The read/write routines are based on oPossum's CCS msp430 asm based cycle counting serial routines. They have been generalized for use with Energia, C++ templates, msp430-gas abi asm, modified to support any port and pin combination, and will allow for multiple serial instances.

    The code does use some instance data (~12 bytes) but you can have multiple sw_serial_t class instances. You might find this useful if you have have to interact with more than one serial device. This isn't a library so much as a header file you include in your project. The code weighs in at about 1200 bytes for a typical ASCII table print. A serial.print("Hello World\n") is only about 560 bytes. Useful things can even be done on the MSP430G2231 chip using this code.

    I've successfully tested output to 230400 baud running the DCO clock at 16MHz. You won't be able to achieve that baud rate running at 1MHz. Note: I did calibrate my DCO clock to be to 16.00MHz before trying to run that fast.

    I've not stressed the input side so I can't say what the limits are for input. Needless to say, it will all depend on the input and how you attempt to process the input data.

    You might want to snag a couple of those $3 pl2303x usb modules from ebay. That is what I used to test at high speed.

    The sw_serial_t template class inherits from the Stream base class. That means that all the normal print() methods are available for use as you would do with any other Serial class implementation. In addition, I've included the Streaming class from http://arduiniana.org/libraries/streaming/ This allows C++-style output with the "<<" operator.

    See the example '.ino' files for information on how to actually instance the sw_serial_t template.

    Some caveats:

    1.) This code uses cycle counting. That means when you use the write() or read() methods, they disable the watchdog timer. Disabling the watchdog in Energia means the millis() count is going to be wrong. I guess an improvement would be to update the millis counter based on the baud rate but I haven't done that. You have been warned!

    2.) This code implements blocking routines. If you do a read() it will block until a character arrives. If you do a write() it will block until the bits have been shifted out. I take care of disabling the watchdog timer. However, if you have timer interrupt routines they will break this code. You will have to make sure you disable the timer interrupts while doing serial IO or pick a time when the timer code isn't running.

    3.) This code doesn't use a ring buffer. So, expect it to to drop characters if you receive a long stream of characters and you try to do too much in between the read() calls. If you need to do something with a stream of characters, receive each byte and put it in your own buffer then process the buffer when you detect a new line. Some simple solutions to dealing with blocking reads: a.) use a slower host BAUD rate. b.) add extra stop bits from the host side to give yourself more time between received bytes. c.) preface the stream of bytes with a length so your firmware will know how many bytes to receive before it tries to process them.

    4.) The more features of the Print class you use the larger your code will grow. If you really only want multiple serial instances then just use the read() and write() methods for the smallest code. Avoid the print() methods and you will acheive the smallest implementation.

    This code is implemented as templates and doesn't use the Arduino style pin number table runtime lookups. Pin information must be available at compile time so the asm routines can do the right thing. However, using templates reduces the size of this code and makes it more flexible. Look at the ssgpio.h for more information about the pin configuration. It is only setup for P1 and P2. I'm assuming people who want to use this are probably going to use it on the G series DIP chips. You will have to add entries for anything other than that.

    -rick

    hosted on github https://gist.github.com/RickKimball/4758580


  10. Like
    calinp reacted to energia in How to using attachInterrupt()?   
    While looking at this I discovered a serious bug in the interrupt code. Basically RISING would never work. Patch for this fix is pretty simple:
     
    diff --git a/hardware/msp430/cores/msp430/Energia.h b/hardware/msp430/cores/msp430/Energia.h index facfd06..7ce8034 100644 --- a/hardware/msp430/cores/msp430/Energia.h +++ b/hardware/msp430/cores/msp430/Energia.h @@ -22,9 +22,8 @@ extern "C"{ #define LSBFIRST 0 #define MSBFIRST 1 -#define CHANGE 1 -#define FALLING 2 -#define RISING 3 +#define RISING 0 +#define FALLING 1 #define INPUT 0x0 #define OUTPUT 0x1  
     
    And this is the Sketch that I used to test it. This Sketch also demonstrates how to get an interrupt on CHANGE just like in Arduino. It's only a couple more lines of code and a volatile var.
     
    uint8_t volatile edge; void setup() { pinMode(RED_LED, OUTPUT); digitalWrite(RED_LED, LOW); attachInterrupt(PUSH2, func, FALLING); edge = FALLING; } void loop() { } void func() { if(edge == FALLING) { attachInterrupt(PUSH2, func, RISING); edge = RISING; } else { attachInterrupt(PUSH2, func, FALLING); edge = FALLING; } P1OUT ^= 0x01; }  
     
  11. Like
    calinp got a reaction from qwertyu in [Energia Library] Petit FatFS SD Card Library   
    Hello,
     
    This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.org/fsw/ff/00index_p.html
     
    A lot of credits goes to the main contributors to this topic http://forum.43oh.com/topic/1427-petitefs-fatfs-sdcard-usci-code/
     
     
    Because this library makes use of the SPI library included in Energia it  works for both MSP430 and Stellaris launchpads.
     
    With MSP430 I noticed some interference with Serial.print so before every call to the fat library I had to add a small delay. On Stellaris board these are not necessary. 
     
     
    Unzip and copy in Energia\hardware\msp430\libraries or Energia\hardware\lm4f\libraries .
     
    [uPDATE] See post #15 http://forum.43oh.com/topic/3209-energia-library-petit-fatfs-sd-card-library/#entry30031
     
    [DOWNLOAD LINK] http://forum.43oh.com/index.php?app=core&module=attach&section=attach&attach_id=3019
  12. Like
    calinp got a reaction from bluehash in [Energia Library] Petit FatFS SD Card Library   
    Hi Grant,
     
    Try to format the cards that are not working with HP USB Disk Storage Format Tool : http://www.softpedia.com/get/System/Hard-Disk-Utils/HP-USB-Disk-Storage-Format-Tool.shtml
     
    The write function has some limitations :
    Cannot create file. Only existing file can be written. Cannot expand file size. Cannot update time stamp of the file. Write operation can start/stop on the sector boundary. Read-only attribute of the file cannot block write operation. See more here: http://elm-chan.org/fsw/ff/pf/write.html
     
    The FatFS lib does not have these limitations and provides more functions, but will not work with only 512bytes of RAM.
    With Petit FatFS you should create one or more empty large files and write until they are full.
     
    In case you want to append records to a non empty file you must find the last sector written and start writing on the next one.
     
    Below is an update to the library:
    - SPI clock divider can be specified in the begin function like FatFs.begin(cs_pin,2); -> 16MHZ / 2 = 8MHz SPI Clock
    - added string functions from FatFS:
    FatFs.gets - Read a string
    FatFs.fputc - Write a character
    FatFs.puts - Write a string
    FatFs.printf - Write a formatted string
    - Inherits from print class so you can use :
    FatFS.print()
    FatFS.println()
    [EDIT] Forgot  about FatFs.close(). It only does pf_write(0, 0, &bw) but is easier to use.
     
    Important! Apply these patches:
    http://forum.43oh.com/topic/3272-msp430g2553-issue-hardwareserial-io-corrupts-spi-io/
    http://forum.43oh.com/topic/3163-fixed-%E2%80%94-msp430g2553-spi-issue-first-byte-not-read/''>http://forum.43oh.com/topic/3163-fixed-%E2%80%94-msp430g2553-spi-issue-first-byte-not-read/'>http://forum.43oh.com/topic/3163-fixed-
    PFatFs07.zip
  13. Like
    calinp reacted to spirilis in MSP430G2553 Issue: HardwareSerial I/O corrupts SPI I/O   
    See post here: http://forum.43oh.com/topic/3237-energia-library-nordic-nrf24l01-library/?p=28498
     
    Energia version: 0101E0009 on MacOS X Snow Leopard.
     
     
    Description:
     
    When mixing SPI I/O and Serial I/O (e.g. queueing serial debugging messages while doing periodic SPI I/O to a peripheral), extraneous SPI transfers occur concurrently with execution of the IRQ ISRs related to USCI_A0 TX.
     
    Offending code found in /Applications/Energia.app/Contents/Resources/Java/hardware/msp430/cores/msp430/usci_isr_handler.c:
    __attribute__((interrupt(USCIAB0TX_VECTOR))) void USCIAB0TX_ISR(void) { /* USCI_A0 UART interrupt? */ if (UC0IFG & UCA0TXIFG) uart_tx_isr(); /* USCI_B0 I2C TX RX interrupt. */ if ((UC0IFG & (UCB0TXIFG | UCB0RXIFG)) != 0) i2c_txrx_isr(); }  
     
    The i2c_txrx_isr code will run whenever UCB0TXIFG or UCB0RXIFG is set, which may occur before or after an SPI transfer and in the middle of a multi-byte sequence of SPI I/O.  This is likely to show up as corruption in a race condition pattern.
     
    Modification, ensures i2c_txrx_isr is only run if UCB0CTL0's UCMODE is set to 0b11 (I2C mode), ignoring it entirely in SPI mode:
    __attribute__((interrupt(USCIAB0TX_VECTOR))) void USCIAB0TX_ISR(void) { /* USCI_A0 UART interrupt? */ if (UC0IFG & UCA0TXIFG) uart_tx_isr(); /* USCI_B0 I2C TX RX interrupt. */ if ((UCB0CTL0 & UCMODE_3) == UCMODE_3 && (UC0IFG & (UCB0TXIFG | UCB0RXIFG)) != 0) i2c_txrx_isr(); }  
    This fixed my bug, and I was able to perform Serial I/O concurrently with SPI I/O to my peripheral (Nordic nRF24L01+)
  14. Like
    calinp reacted to grahamf72 in Low Power Mode   
    I had a bit of spare time on my hands today, so had a bit of a play with activating low power modes.  I had a basic clock sketch that I had been using to test the RTC library that I posted on the RTC thread, and modified it a bit to see if I could get it to still work in low power mode.
     
    I discovered a few things about Energia in the process, so it was quite a productive day of play. Here are a few of my notes which hopefully will be of benefit to some others.
     
    1. I was originally relying the Energia function millis() to do software switch debouncing.  The function millis() derives its count from the WDT timer triggering an interrupt at 31.25khz (on 16MHz devices such as MSP430G2553).  The timing is derived from SMCLK which is in turn derived from the DCO clock. In LPM3 the DCO is disabled, so the interrupt is not called, meaning millis() no longer works. I did consider changing the WDT to get its signal from ACLK but because the smallest divider is 64, the WDT would only be called 512 times/second instead of 31250 times/second, making millis() and delay() inaccurate by a factor of ~60. Instead I changed my logic so that once a switch was pressed it stayed out of low power mode until the user had finished. Alternatively, because the 430 has Schmitt inputs, I could do hardware debouncing quite easily with just a capacitor & resistor.
     
    2. Inside an ISR, further interrupts are disabled, so although the DCO & SMCLK are running inside the ISR, millis() still won't work, because the interrupt will not be called. In theory delay() should work as it re-enables interrupts, however I found it to be unreliable, possibly because I was getting re-entrant problems. delayMicroseconds() works for short delays, as it is a simple loop that relies on the time instructions take to execute.
     
    3. According to the mspgcc documentation, when an interrupt is called during low power mode, it should return to low power mode when the ISR finishes. My experiments seem to indicate that this behaviour isn't reliable.  My interrupt running off the A0 timer seemed to return to the LPM about 3 times in 4.  The pin interrupts seemed to never return to LPM. I have looked over the code in wiring.c & winterrupts.c and cannot see why this should be the case. In any case, it is a positive, because after a pin interrupt triggers, the loop() continues to run, allowing it to do other useful functions.
     
    4. According to the mspgcc documentation you can override the Low Power Mode when an ISR exits by using the pseudo-function _BIC_SR_IRQ().  This function can only be called from an ISR. This works from within the ISR that I created for the RTC library, however it does not work if you use AttachInterrupt() to attach an interrupt to one of the 430's input pins. The reason being that the ISR is buried in WInterrupts.c, which then calls the user function. Although I cannot see any code to cause it, the ISR that handles input pin interrupts leaves the system at full power when it exits. This is fortunate, as otherwise there would be no way to resume the system to full power after a pin interrupt.
     
    So putting it together, the basic guidelines that I have worked out for using low power mode are:
    In your setup() function, configure the interrupts that you need - eg Attach interrupts to your pushbuttons
    If you want a timed interrupt, configure it to run off ACLK & configure ACLK.
    Set your Low-Power-Mode in loop() as per the below - this way after an interrupt runs, your loop() will continue.
    void loop() { //put code here that will run on the first pass of loop, and every subsequent loop //... _BIS_SR(LPMx_bits | GIE); //Turn on low power mode // Execution will stop at the _BIS_SR line above. // Any code here will not run until AFTER an Interrupt has triggered and // the ISR has finished running. // If an Interrupt is never triggered, this code will never run. // ... }  
    The low power modes are as follows:
    LPM0_bits - Low power mode 0 - the CPU & MCLK are disabled, SMCLK & ACLK still run. This means the WDT will still run and generate interrupts at 31.25kHz
    LPM1_bits - Low power mode 1 - the CPU & MCLK are disabled. The DCO will also be turned off if SMCLK isn't derived from it. Because Energia derives the SMCLK from DCO, DCO will still run, as will the WDT interrupts. With the standard Energia clock setup, this becomes identical to LPM0
    LPM2_bits - Low power mode 2 - CPU, MCLK, SMCLK & DCO disabled, DC generator still runs (The DC generator is used for the DCO). ACLK still runs.
    LPM3_bits - Low power mode 3 - CPU, MCLK, SMCLK, DCO & DC Generator disabled. ACLK still runs. The difference between this and LPM2 is that with the DC generator disabled, the DCO takes a little longer to start back up.
    LPM4_bits - Low Power mode 4 - all clocks (including ACLK) are disabled. In this mode no timing functions will operate - the CPU can only be woken up by a pin interrupt.
     
    Attached is my clock example that uses my RTCplus library (attached to one of my posts in the RTC thread) to display date and time on a 16x2 LCD and allow date and time to be set with a pair of buttons. My earlier version of this that didn't switch to low power mode was using 5mA as measured with a DMM across the VCC jumper on the launchpad (not including the LCD display current). By converting this to low power mode, consumption dropped to 2uA measured on my DMM. Each second as it ticks, my DMM spikes up to about 300uA. The actual consumption during the tick is probably closer to 5mA but for such a short time my DMM couldn't catch it. If you want to test this example, you will need to amend the RTCplus header so that the line "#define RTCSUBSECONDS" is commented out.
     
    Using LPM requires a bit of thought about what functions will run when, but for a task that only needs to do something infrequently or responding to user input, it can make a huge difference to the power consumption.
     
    sketch_Low_Power_LCD_Clock.zip
  15. Like
    calinp reacted to spirilis in [Energia Library] Nordic nRF24L01+ library   
    Okie doke - https://github.com/spirilis/Enrf24
     
    The examples are the same as the ones I posted... I'll write up the API in a wiki page soon.  Alternately, I put documentation in the Enrf24.h file for the various functions.
     
    edit: Zip file of the v1.0 release- Enrf24_v1_0.zip
  16. Like
    calinp got a reaction from energia in [Energia Library] Petit FatFS SD Card Library   
    Hello,
     
    This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.org/fsw/ff/00index_p.html
     
    A lot of credits goes to the main contributors to this topic http://forum.43oh.com/topic/1427-petitefs-fatfs-sdcard-usci-code/
     
     
    Because this library makes use of the SPI library included in Energia it works for both MSP430 and Stellaris launchpads.
     
    With MSP430 I noticed some interference with Serial.print so before every call to the fat library I had to add a small delay. On Stellaris board these are not necessary.
     
     
    Unzip and copy in Energia\hardware\msp430\libraries or Energia\hardware\lm4f\libraries .
     
    The file attached to this post is the first version. Please use the variant from 43oh forum: http://forum.43oh.com/topic/3209-energia-library-petit-fatfs-sd-card-library/#entry27705
    PFatFs06.zip
  17. Like
    calinp got a reaction from PTB in [Energia Library] Petit FatFS SD Card Library   
    Hello,
     
    This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.org/fsw/ff/00index_p.html
     
    A lot of credits goes to the main contributors to this topic http://forum.43oh.com/topic/1427-petitefs-fatfs-sdcard-usci-code/
     
     
    Because this library makes use of the SPI library included in Energia it  works for both MSP430 and Stellaris launchpads.
     
    With MSP430 I noticed some interference with Serial.print so before every call to the fat library I had to add a small delay. On Stellaris board these are not necessary. 
     
     
    Unzip and copy in Energia\hardware\msp430\libraries or Energia\hardware\lm4f\libraries .
     
    [uPDATE] See post #15 http://forum.43oh.com/topic/3209-energia-library-petit-fatfs-sd-card-library/#entry30031
     
    [DOWNLOAD LINK] http://forum.43oh.com/index.php?app=core&module=attach&section=attach&attach_id=3019
  18. Like
    calinp reacted to Rickta59 in New CCS vs Energia discussion.   
    The title of this conversation was "CCS vs Energia" so I was trying to focus my responses towards that topic.  However comparing CCS and Energia is like comparing apples and oranges. Energia is an IDE + examples + a peripheral Framework + a compiler + a libc/libm.  CCS is an IDE + a compiler + a libc/libm.  Most of the questions and posts have been really about the Energia Framework, specifically the Serial class for the msp430g2553.  So maybe the topic should be Energia classes vs low level peripheral register level coding.  The Energia Framework just packages up general purpose classes for ease of use that happen to conform to the existing Arduino API. This allows you to defer learning about the low level details of the msp430 peripherals and concentrate on making something.
     
    In Energia using an msp430g2553, Serial is implemented using HardwareSerial. The HardwareSerial class handles the generic case of reading and writing to the USCI peripheral. It is a general class not that isn't optimized for read or write. It doesn't know if you are going to do blocking reads or blocking writes so it automatically provides you will a TX and RX ring buffer.  You can insert or extract serial data with the ring buffers without worrying about dealing with interrupts or the USCI peripheral.  HardwareSerial inherits the Print class. The Print class provides generalized routines that can print any data type with many different base numbers. It doesn't optimize for a specific base implementation.
     
    If all you want to do is output characters on the USCI peripheral you can implement that in either CCS or msp430-gcc with about the same efficiency.  Energia really doesn't come into play.  If you did want to stick with Energia, you don't have to use the HardwareSerial class. You can use printf and putc.  Although if you use the msp430-gcc printf(), it will suck up an extra ~2k of code. But back to the comparison part of this topic, that 2k is still much less than the CCS printf version which also uses an insane amount of data space. You could use oPossum's or robg's printf() code. Although I think both of those require some minor changes to work with msp430-gcc.
     
    A third option is to write your own MinimalSerial output only class.  This one I sketched below only outputs const char strings or hex digits. However it adds less than 300 bytes to the size of your code. I implemented an insertion operator << overload so you can get the feeling that you are using an iostream class. However, it is just an illusion. There is no iostream on msp430-gcc.
     
    This example below weighs in at 470 bytes. The bare minumum sketch is 233 so I'm not adding too much to get debug output.  I'm sure you could write straight C code using either CCS or msp430-gcc that would be slightly smaller but I'm guessing it will still be around 350-400 bytes.
     
    /* * MinimalSerial.ino - output only Serial template class example for msp430g2553 */ #if !defined(__MSP430_HAS_USCI__) #error "This code only works on the msp430g2553 chip" #endif namespace { const char ascii_digits[] = "0123456789ABCDEF"; } template<uint32_t BPS=9600> struct USCISerial { void begin(uint32_t dummy /* be consistent with Serial class begin() */) { const uint32_t baud_rate_20_bits = (F_CPU + (BPS >> 1)) / BPS; // Bit rate divisor UCA0CTL1 = UCSWRST; // Hold USCI in reset to allow configuration UCA0CTL0 = 0; // No parity, LSB first, 8 bits, one stop bit, UART (async) UCA0BR1 = (baud_rate_20_bits >> 12) & 0xFF; // High byte of whole divisor UCA0BR0 = (baud_rate_20_bits >> 4) & 0xFF; // Low byte of whole divisor UCA0MCTL = ((baud_rate_20_bits << 4) & 0xF0) | UCOS16; // Fractional divisor, over sampling mode UCA0CTL1 = UCSSEL_2; // Use SMCLK for bit rate generator, then release reset // Configure P1.2 as UART controlled pin P1SEL = BIT2; // P1.2=TXD P1SEL2 = BIT2; // P1.2=TXD } void printHex(uint32_t n, uint16_t bits=32) { uint16_t mask = 0x0F; do { bits -= 4; write(ascii_digits[(n >> bits) & mask]); } while( bits ); } void print(const char *s) { while(*s) { write(*s); s++; } } void print(int8_t n) { printHex(n,8); } void print(uint8_t n) { printHex(n,8); } void print(int16_t n) { printHex(n,16); } void print(uint16_t n) { printHex(n,16); } void print(int32_t n) { printHex(n,32); } void print(uint32_t n) { printHex(n,32); } void print(float f) { printHex((uint32_t)f,32); } void write(uint8_t c) { while(!(IFG2 & UCA0TXIFG)); // wait for TX buffer to empty UCA0TXBUF = c; } }; typedef USCISerial<9600> USCISerial9600; USCISerial9600 DebugSerial; template<class T> inline USCISerial9600 &operator <<(USCISerial9600 &obj, T arg) { obj.print(arg); return obj; } void setup() { DebugSerial.begin(9600); DebugSerial << "\nMinimalSerial @ 9600 Baud\n"; } void loop() { uint16_t count=1; while ( 1 ) { DebugSerial << "count=0x" << count << "\n"; count++; if ( count == 0x200 ) { while(1); } } } #if 0 // you could implement printf with something like this #include <stdio.h> int putchar(int c) { DebugSerial.write(c); return 1; } /* ... then later printf("count=%d\n", count); */ #endif  
     
    -rick
  19. Like
    calinp got a reaction from larsie in [Energia Library] Petit FatFS SD Card Library   
    Hello,
     
    This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.org/fsw/ff/00index_p.html
     
    A lot of credits goes to the main contributors to this topic http://forum.43oh.com/topic/1427-petitefs-fatfs-sdcard-usci-code/
     
     
    Because this library makes use of the SPI library included in Energia it  works for both MSP430 and Stellaris launchpads.
     
    With MSP430 I noticed some interference with Serial.print so before every call to the fat library I had to add a small delay. On Stellaris board these are not necessary. 
     
     
    Unzip and copy in Energia\hardware\msp430\libraries or Energia\hardware\lm4f\libraries .
     
    [uPDATE] See post #15 http://forum.43oh.com/topic/3209-energia-library-petit-fatfs-sd-card-library/#entry30031
     
    [DOWNLOAD LINK] http://forum.43oh.com/index.php?app=core&module=attach&section=attach&attach_id=3019
  20. Like
    calinp got a reaction from energia in [Energia Library] Petit FatFS SD Card Library   
    Hello,
     
    This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.org/fsw/ff/00index_p.html
     
    A lot of credits goes to the main contributors to this topic http://forum.43oh.com/topic/1427-petitefs-fatfs-sdcard-usci-code/
     
     
    Because this library makes use of the SPI library included in Energia it  works for both MSP430 and Stellaris launchpads.
     
    With MSP430 I noticed some interference with Serial.print so before every call to the fat library I had to add a small delay. On Stellaris board these are not necessary. 
     
     
    Unzip and copy in Energia\hardware\msp430\libraries or Energia\hardware\lm4f\libraries .
     
    [uPDATE] See post #15 http://forum.43oh.com/topic/3209-energia-library-petit-fatfs-sd-card-library/#entry30031
     
    [DOWNLOAD LINK] http://forum.43oh.com/index.php?app=core&module=attach&section=attach&attach_id=3019
  21. Like
    calinp got a reaction from energia in [Energia Library] Stellaris Launchpad FatFs Energia library   
    This is a port to Energia of the Arduino library from this page: http://pressplay.pbworks.com/w/page/25687375/FatFs
     
    The diskio.c driver is from Stellarisware example for lm4f232 with some changes:
    - use digitalWrite for CS control
    - use delays instead of timers for timeouts
     
    The card must be connected to SSI0 (hardcoded in driver) but CS signal is defined in sketch and can be any pin.
     
    I checked the FileWriteToSerial example and it is working with uSD and uSDHC cards (2GB and 8GB). I connected the uSD cards with and adapter to SD using the first method presented here: http://www.43oh.com/2011/02/five-cheap-breadboard-prototyping-tips-and-tricks-list-2/
     
    Also, I'm not a good programmer (I had first hands-on experience with C when I discovered Energia) so some parts of the code might be optimised further for Stellaris.
     
    Extract the archive in Energia\hardware\lm4f\libraries\ and enjoy!
     
    [uPDATE] See post #7 http://forum.stellarisiti.com/topic/442-energia-library-stellaris-launchpad-fatfs-energia-library/#entry2553
    [DOWNLOAD LINK] http://forum.stellarisiti.com/index.php?app=core&module=attach&section=attach&attach_id=335
     
    The file attached to this post is the first version. For the updated library please use the link above.
    FatFs_03.zip
  22. Like
    calinp got a reaction from Rickta59 in [Energia Library] Stellaris Launchpad FatFs Energia library   
    This is a port to Energia of the Arduino library from this page: http://pressplay.pbworks.com/w/page/25687375/FatFs
     
    The diskio.c driver is from Stellarisware example for lm4f232 with some changes:
    - use digitalWrite for CS control
    - use delays instead of timers for timeouts
     
    The card must be connected to SSI0 (hardcoded in driver) but CS signal is defined in sketch and can be any pin.
     
    I checked the FileWriteToSerial example and it is working with uSD and uSDHC cards (2GB and 8GB). I connected the uSD cards with and adapter to SD using the first method presented here: http://www.43oh.com/2011/02/five-cheap-breadboard-prototyping-tips-and-tricks-list-2/
     
    Also, I'm not a good programmer (I had first hands-on experience with C when I discovered Energia) so some parts of the code might be optimised further for Stellaris.
     
    Extract the archive in Energia\hardware\lm4f\libraries\ and enjoy!
     
    [uPDATE] See post #7 http://forum.stellarisiti.com/topic/442-energia-library-stellaris-launchpad-fatfs-energia-library/#entry2553
    [DOWNLOAD LINK] http://forum.stellarisiti.com/index.php?app=core&module=attach&section=attach&attach_id=335
     
    The file attached to this post is the first version. For the updated library please use the link above.
    FatFs_03.zip
  23. Like
    calinp got a reaction from Rei Vilo in [Energia Library] Stellaris Launchpad FatFs Energia library   
    This is a port to Energia of the Arduino library from this page: http://pressplay.pbworks.com/w/page/25687375/FatFs
     
    The diskio.c driver is from Stellarisware example for lm4f232 with some changes:
    - use digitalWrite for CS control
    - use delays instead of timers for timeouts
     
    The card must be connected to SSI0 (hardcoded in driver) but CS signal is defined in sketch and can be any pin.
     
    I checked the FileWriteToSerial example and it is working with uSD and uSDHC cards (2GB and 8GB). I connected the uSD cards with and adapter to SD using the first method presented here: http://www.43oh.com/2011/02/five-cheap-breadboard-prototyping-tips-and-tricks-list-2/
     
    Also, I'm not a good programmer (I had first hands-on experience with C when I discovered Energia) so some parts of the code might be optimised further for Stellaris.
     
    Extract the archive in Energia\hardware\lm4f\libraries\ and enjoy!
     
    [uPDATE] See post #7 http://forum.stellarisiti.com/topic/442-energia-library-stellaris-launchpad-fatfs-energia-library/#entry2553
    [DOWNLOAD LINK] http://forum.stellarisiti.com/index.php?app=core&module=attach&section=attach&attach_id=335
     
    The file attached to this post is the first version. For the updated library please use the link above.
    FatFs_03.zip
  24. Like
    calinp got a reaction from bluehash in [Energia Library] Stellaris Launchpad FatFs Energia library   
    This is a port to Energia of the Arduino library from this page: http://pressplay.pbworks.com/w/page/25687375/FatFs
     
    The diskio.c driver is from Stellarisware example for lm4f232 with some changes:
    - use digitalWrite for CS control
    - use delays instead of timers for timeouts
     
    The card must be connected to SSI0 (hardcoded in driver) but CS signal is defined in sketch and can be any pin.
     
    I checked the FileWriteToSerial example and it is working with uSD and uSDHC cards (2GB and 8GB). I connected the uSD cards with and adapter to SD using the first method presented here: http://www.43oh.com/2011/02/five-cheap-breadboard-prototyping-tips-and-tricks-list-2/
     
    Also, I'm not a good programmer (I had first hands-on experience with C when I discovered Energia) so some parts of the code might be optimised further for Stellaris.
     
    Extract the archive in Energia\hardware\lm4f\libraries\ and enjoy!
     
    [uPDATE] See post #7 http://forum.stellarisiti.com/topic/442-energia-library-stellaris-launchpad-fatfs-energia-library/#entry2553
    [DOWNLOAD LINK] http://forum.stellarisiti.com/index.php?app=core&module=attach&section=attach&attach_id=335
     
    The file attached to this post is the first version. For the updated library please use the link above.
    FatFs_03.zip
  25. Like
    calinp got a reaction from energia in CMD library ported from Arduino   
    Hello,
     
    I ported the CMD library from Freaklabs so it compiles and runs on MSP430g2553 using Energia.
     
    Documentation and original code are available at:
    http://freaklabs.org...CmdArduino.html
     
    Unzip in \energia-0101E0008\hardware\msp430\libraries and restart Energia IDE. There is also an example available.
     
     
    Reuploaded CmdEnergia.zip
    CmdEnergia.zip
×
×
  • Create New...