curtis63 5 Posted January 30, 2017 Share Posted January 30, 2017 Good Morning, This may be the wrong place to ask this question. If so, please let me know where to ask it.. I've been a Windows programmer for 20 years. I've pretty much stuck to User Interface development the whole time. I have been using .net and C# for the past 10 years so I am VERY SPOILED when it comes to letting the language do the grunt work and I finesse the code. I now find myself working on a personal project which requires me to program the MSP430G2553 controller. I started out by using Energia (which if you don't know, is a fork off of Arduino) The advantage of it is you can do a lot with very little code and without needing to know all the guts of the MSP430G2553. The disadvantages are that sometimes it doesn't work right. Sometimes it doesn't give you the control you need, sometimes it's hard to figure out if Energia isn't working, or if your code isn't working... Anyway, I've spent hundreds of hours getting parts of my program to work. I have been trying to get away with not having to learn how to write firmware and have to deal directly with the processor. However, I'm starting to think that I need to bite the bullet and take the time to overcome my learning curve and dive in headfirst to firmware development and the paradigm shift that comes with it. The program I am using needs to have control over changing into and out of the various Low Power Modes on the MSP430. I need to listen for interrupts. I need to use I2C to communicate with various devices that are connected to the MSP430. I need to monitor Power Level/Consumption from time to time. So, basically, I have the following questions: 1. Can Energia robustly and without errors do the above things? 2. Am I wasting my time getting all of the above accomplished using Energia? 3. Should I be using Code Composer Studio? 4. Having NEVER developed ANY controller level code outside of Arduino and Energia, what kind of Learning Curve am I looking at to accomplish the above things? 5. Where is the best place to start learning this? 6. Where is the best place to look for answers to MSP430 development questions? Thank you all in advance for any assistance and advice you might have. Quote Link to post Share on other sites
energia 485 Posted January 30, 2017 Share Posted January 30, 2017 Looking at the high level requirements it looks like this should be possible with Energia. You will not have the level of control you will get with a bare metal CCS implementation but it will get you a long way. This has been tested quite extensively but I can not claim that you will not run into bugs. Same will be true for a CCS based application I guess. Your friends are: attachInterrupt(). For listening for GPIO interrupts. If you need to listen to / wake up from other sources then we will need to review those cases. sleep() and sleepSeconds(). This will put the MSP430 into LPM3. Most efficient is to have the 32kHz watch crystal installed. This will allow Energia to clock the watchdog from that crystal allowing longer sleep times. You can cancel this sleep in an ISR from e.g. attachInterrupt() by calling wakeup. (see this thread: http://forum.43oh.com/topic/4571-building-low-power-into-energia/page-2) suspend(). This will put the MSP430 into LPM4 and can only be woken up from an attacheInterrupt() isr. You MUST call wakup() in the isr to resume execution of the loop. delay(). This will put the MSP430 into LPM0. Delay can not be cancelled by calling wakup() from an isr. Wire for the I2C stuff. Measuring power levels on the MSP430 itself is going to be difficult because it will be sleeping and not executing anything when you care about those numbers the most. You can profile your application using EnergyTrace. I have seen users hooking up a launchpad that supports EnergyTrace to an MSP430G2553 and measure the power consumption that way. This of course is only helpful during the development phase. Hope this helps. Robert Quote Link to post Share on other sites
L.R.A 78 Posted January 31, 2017 Share Posted January 31, 2017 Hi @@curtis63I would advise to use Energia. Use Energia libraries when you can. If you need some feature not supported by any Energia libraries (user submitted or core) then use more low level programming (using MSP register headers and things like that). This way you get a mix of both and spend the least time developing software.If you would like some debug power, CCS supports Energia sketches.That said I think you can do everything you want with Energia libraries.Note that some problems you might face are not language wise. Yes many times in CCS you use C instead of C++. But you can use C++ just fine if you want, after all you use it with Energia.The thing is, what you will find different is hardware configuration. See it like making a driver for a piece of hardware. 1. Can Energia robustly and without errors do the above things? It can but you of course have to code the MSP correctly for your purpose. 2. Am I wasting my time getting all of the above accomplished using Energia? For what I understood of what you want to do, you will save time using Energia libraries instead of MSP430 register programming. 3. Should I be using Code Composer Studio? You can use it if you need to use debug tools. Otherwise don't bother. 4. Having NEVER developed ANY controller level code outside of Arduino and Energia, what kind of Learning Curve am I looking at to accomplish the above things? If you are talking about implementing in register programming fashion it's a bit hard to start. You will have to understand about registers in general and then learn the MSP430 register (just the ones that you need) and how to access them (by using the names on the headers). When using register programming a Wire.begin() becomes multiple lines of code configuring registers. Not that hard but when you start it can be discouraging to configure them.You also need to learn how interrupts work and how to use them.It may seem a lot but there are very good workshops and resources for the MSP430. Being a TM4C user it makes me envious! But as I (and @energia) said, you should not need any of that 5. Where is the best place to start learning this? There are a ton of MSP430 tutorials and resources from the TI team. I know most for other MSP430s. Not sure if you can consult the cloud. It has a ton of the software and documents:https://dev.ti.com/ But here is a good one for the MSP430G2553.http://processors.wiki.ti.com/index.php/Getting_Started_with_the_MSP430G2553_Value-Line_LaunchPad_Workshop 6. Where is the best place to look for answers to MSP430 development questions? If you are really interested you can make some questions in this forum or TI E2E. btw, if you came from Arduino, remember all launchpads work with 3.3v and most don't have 5v tolerant pins, including the MSP430G2553. So if you are using i2c with a 5V slave, be careful if you use 5V pull-ups.Hope it helps Quote Link to post Share on other sites
Fmilburn 446 Posted January 31, 2017 Share Posted January 31, 2017 I find Energia suitable for many most of my projects. Much of the time direct register access is not needed. But if you keep at it long enough and stretch the boundaries of what others have done and posted, then expect to encounter the limitations of Energia / Arduino or at least the need to understand what is happening at the register level. It may be in terms of the software, the libraries, slow execution, lack of access to features, or that your desired microcontroller does not have an Energia port. If you learn to directly access registers then all peripherals and capabilities are available. If you want to understand and port other libraries that use direct register access then clearly a deeper understanding is needed as well. As long as you don't introduce a conflict then direct register programming and Energia work together fine and it is not one or the other. I would start with CCS and the workshop that L.R.A suggests if using the G2553. There are also tutorials on using CCS. I find the debugger in CCS invaluable even when using Energia. Gaining familiarity with the datasheets, the family user guides, and header files was the most difficult part for me as I have no microcontroller or C/C++ background - but they are key. My approach was to become proficient in Energia and then add the more traditional approach as I went along. I even find that myself writing everything in CCS without Energia from time to time now MichelKohler and NurseBob 2 Quote Link to post Share on other sites
Fred 453 Posted January 31, 2017 Share Posted January 31, 2017 If you're a C# coder, I'd say you can consider Energia/Arduino to be the equivalent of VB.NET. Try CCS. If you have problems with peripheral setup (often the trickiest bit) you can use the grace tool to help generate code for you that you. Quote Link to post Share on other sites
NurseBob 111 Posted January 31, 2017 Share Posted January 31, 2017 Curtis, First, I'm not going to address your questions regarding Energia; I am not experienced enough, nor educated enough in that realm to make the judgements you're calling for. That said, and given your long experience in writing Windows UI code, I'll share some of my personal observations and opinions (definitely not free of prejudice...). FWIW, while no longer employed as a professional software engineer - I really am a nurse - I do have 15+ years analysing, designing, coding and testing enterprise applications in the corporate world. I worked for Del Monte Foods, and then EDS while developing and supporting various apps. I focused on UI development for enterprise database systems, and was literate in SQL, VB, C, C++ on both PC and midrange systems, with a smidge of mainframe stuff. Enough rambling.... As you are aware, there are numerous tools available at this point. Not so long ago the micro world was almost entirely in the assembler domain. Then came C, and most recently, C++ and the development of various class libraries along with traditional C-based libraries. My time with TI has focused on the F2013 for many projects, and now the F5529 (I need the USB functionality). My preferred environment is definitely IAR, but their price structure is out of my reach as a non-professional. Where I can, I do dabble (I won't claim to code) in IAR assembler with the 2013; there are numerous examples to help, and there is no code size limit with the IAR assembler. As my current project looked like it was going to exceed the CCS code size limits, I bit the bullet and paid the then $500 price tag to have a full implementation. As I've noted in other posts, I really dislike the UI for CCS, but I put up with it. So, where does Energia fit in? For what I've done in the past, and plan to do in the future, Energia does not lend itself well to my needs of absolutely minimal energy consumption. I use the Energia sketches to explore the connection and configuration of various sensors. Once I've established that I can successfully read/write data with the sensor of interest, I import the project into CCS. There I can use the debugger to see the low level calls to set up peripherals and read/write data. I use that information to write the functional code I need. (A similar path with MSPWare is beneficial as well) My goal with my apps is to be as economical as possible with energy consumption. Having been deep in Energia's code, I appreciate the very clever coding to achieve low power apps while still running in a continuous loop (the arduino roots) that typical '430 designs would avoid. Much of the interrupt-based code examples set up the peripherals and then go to LPM3 (allows a timer-based application) or LPM4 (requires an external input to interrupt). So, in short, my approach: 1) Energia to set up and confirm sensor communications 2) Import project to CCS to understand the underlying code used to access the sensor via single-stepping through the code with the debugger 3) Develop code in C, C++ for the final app I suspect you will be able to leverage your years with C# and debugging to move forward with your '430 code. FWIW, I only lurked on your bit-bang I2C thread, but the thoughts I had were to code it directly in C, or even more efficiently, assembler. I don't remember off hand if the G2553 implements USCI or USI, but there are numerous code examples in both C and assembler for both approaches, and the effort in porting from say a F2013 to a G2553 is not great, and serves as yet another learning opportunity. I have successfully implemented the USI assembler code examples for the F2013 to talk I2C to the F5529 (in C). HTH, Bob Quote Link to post Share on other sites
LIJsselstein 9 Posted February 1, 2017 Share Posted February 1, 2017 The program I am using needs to have control over changing into and out of the various Low Power Modes on the MSP430. I need to listen for interrupts. I need to use I2C to communicate with various devices that are connected to the MSP430. I need to monitor Power Level/Consumption from time to time. Yes, a collegue and I have been doing all of the above with a G2553 (and other chips like the 28 pin version and the FR2433) using sleep (LPM0), sleepSeconds (LPM3), interrupts, ADC and master/slave I2C. We found two bugs in the I2C implementations and made bugreports and pull-requests for them. At least one pull-request is over a year old and has not been pulled-in, not sure why. So, it depends a bit on your specific situation if you'll run into any problems or not. CCS we found especially useful to do register level debugging of our I2C problems after importing the Energia sketch (which does not work for our custom FR2433 board!) and using EnergyTrace++ (a very very cool tool when doing low power development). NurseBob 1 Quote Link to post Share on other sites
curtis63 5 Posted February 8, 2017 Author Share Posted February 8, 2017 Thanks to all who have offered advice and perspective to this discussion. I have attempted my implementation using energia, but I run into bizzare behavior that I cannot figure out. For example. When using i2c, everything seems to be working just fine. I'm talking to a sensor, reading out of its fifo, getting data perfectly, then, after right around 32 seconds (no matter how long I delay between reading out of the fifo) the data gets garbled. There are 5 byte values I need to read and combine to convert it into data and they seem to just get off by some random number of bytes. So the data turns to junk. It happens pretty much at precisely 32 seconds. I can use the very same code on Energia and Arduino. When I use the Arduino code with an arduino nano to talk to my sensor, it's all perfect without any 32 second bug. But, using Energia with an MSP430 launchpad and absolutely no change in my code, it bugs out at 32 seconds. I have no clue why.. Another oddity, is when using bit banging to generate a 25khz frequency on a speaker, I get a wierd hesitation at around 1khz. This causes the side effect of having a harmonic at 1khz which makes a hum noise when the 25khz frequency should be inaudible to human ears. I can see the pattern on my oscilliscope at 1khz and at 25khz.. My code doesn't have a delay, so it's somewhere in the guts of Energia, or the way it talks to the MSP430, or something in the looping or communication. The above two problems make my solution unusable. This is why I attempted to rewrite an i2c implementation. I have trouble with this because there's not an actual way to do a real open collector pin with Energia. You have to fake it by doing a digitalWrite(pin, LOW) and then changing the pinMode(pin,OUTPUT) if you want it low and pinMode(pin,INPUT) if you want it to pull high (with your pullup resisters). The problem is that when you're doing that with both SCL and SDA one after the other, there is about a 2microsecond delay between the two mode changes, which appears to confuse the sensor I'm trying to talk to. Using the Wire library, it appears to change both pinModes simultaniously which is good, but when I use the Wire library, I have that weird 32 second bug. Anyway, looks like I'm going to go directly to CCS and use it to code directly and perhaps remove some of the oddities that I'm seeing. Plus, it will give me a bit more control over the extreme low power mode stuff that I need to use. Quote Link to post Share on other sites
Rickta59 589 Posted February 8, 2017 Share Posted February 8, 2017 Thanks to all who have offered advice and perspective to this discussion. I have attempted my implementation using energia, but I run into bizzare behavior that I cannot figure out. For example. When using i2c, everything seems to be working just fine. I'm talking to a sensor, reading out of its fifo, getting data perfectly, then, after right around 32 seconds (no matter how long I delay between reading out of the fifo) the data gets garbled. There are 5 byte values I need to read and combine to convert it into data and they seem to just get off by some random number of bytes. So the data turns to junk. It happens pretty much at precisely 32 seconds. I can use the very same code on Energia and Arduino. When I use the Arduino code with an arduino nano to talk to my sensor, it's all perfect without any 32 second bug. But, using Energia with an MSP430 launchpad and absolutely no change in my code, it bugs out at 32 seconds. I have no clue why.. How are you combining the data? Strings (that uses heap RAM and is subject to fragmentation)? A large static buffer (that will reduce total RAM)? You are using an msp430g2553 yes? It only has 512bytes of RAM. People don't often notice that an Arduino chip has 2k of RAM and assume anything that fits on an arduino will run on an msp430g2553. If I had only one shot at a wild guess, I'd say you are running out of ram in either the stack or heap. Blowing out RAM is very easy to do. Energia exacerbates memory and flash usage problems. -rick LiviuM and NurseBob 2 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.