Jump to content
43oh

Taggsladder

Members
  • Content Count

    41
  • Joined

  • Last visited

Posts posted by Taggsladder

  1. Thanks for your reply.

     

    Sorry I forgot to mention that I am using Energia coding or maybe it doesn't matter?

     

    Please see

    http://energia.nu/String.html

     

    Here it states

     

     

    char Str2[8] = {'e', 'n', 'e', 'r', 'g', 'i', 'a'};

     

    Declare an array of chars (with one extra char) and the compiler will add the required null character, as in Str2

     

    Best regards

    Andreas
     

  2. Hello

     

    I am working on a MSP430G2553 project and a strange thing is happening when I am converting two chars to integer.

     

    If I only convert one value like this:

    char a[2] = {data[9], data[10]};  // Put in a array + terminating NULL byte.
    int i_a = (int) atoi(a); // Convert to a integer.
    

    It converts the "a" correctly to a integer, but when I do like this:

    char a[2] = {data[9], data[10]};  // Put in a array + terminating NULL byte.
    int i_a = (int) atoi(a); // Convert to a integer.
    
    char b[2] = {data[12], data[13]};  // Put in a array + terminating NULL byte.
    int i_b = (int) atoi(; // Convert to a integer.
    

    It converts both "a" and "b" to integer but it adds 1 at the end, for example if "a"="30" after the conversion the "i_a"=301?

     

    So this just happens when I convert both "a" and "b". If I remove one of the conversion code it converts the other value correctly...

     

    BUT...

     

    If I manually add a terminating NULL byte on both "a" and "b" like this:

    char a[2] = {data[9], data[10]};  // Put in a array + terminating NULL byte.
    a[2] = NULL;
    int i_a = (int) atoi(a); // Convert to a integer.
    
    char b[2] = {data[12], data[13]};  // Put in a array + terminating NULL byte.
    b[2] = NULL;
    int i_b = (int) atoi(; // Convert to a integer.
    

    it works as intended. Why is this? Shouldn't declaring like "char a[2] = {data[9], data[10]};" autoadd the terminating NULL byte at the end?

     

    As you might suspect I am a newbie to this so what is the correct way of doing this?

     

    Hope I am clear enough and you understand. Looking forward to a reply.

     

    Best regards

    Andreas

  3. It's not bad, either positive or negative requires pretty much the same treatment. I have designed many products used in autos and trucks. A resistor, a capacitor, and a Zener diode is ample protection for an input pin. If you are using the internal pullup or pulldown in the MSP430 then it might influence the choice of resistor value, use a higher value if you are sensing a 12V signal(4.7K or 10K is fine). But the basic three parts are all you need. Use a white or blue LED if you don't have a 3.3V Zener. Or two reds in series.

    Regards, Bob

    Really happy with this setup. Works great and fits my needs perfect. Thank you so much.

     

    And thanks everybody for your input [emoji16]

     

    Best regards,

    Andreas

  4.  

     

    One thing to realize is that a 12v automotive system is rarely at 12v. It can dip below 10v during starting, and to nearly 15v when charging the battery. Turning headlights on and off can cause the voltage to fluctuate until the charging system can compensate. Malfunctions in the charging system can also take the electrical system to over 50v.

     

    If you're averse to building your own solution, an option could be automotive / USB power adapters, but if you need more than 1/4-1/2 Ampere current, that's not viable.

     

    If this were something I was planning on selling, or otherwise make it available for others to build / install, I'd consider things like reverse polarity protection- someone, somewhere WILL hook it up backwards eventually, as well as noise filtering and overload protection.

    I have a base unit that has those features and is working great. This is for a addon to recognize when the ignition is turned over. So just a basic digital input to the msp430. First I thought I could go with a manual push button to GND and avoid all the problems with a positive input but as many said it is not a good manner to do so, so I just need a simple way of converting the automotive positive from the ignition to a simple digital input to the msp430.

     

    Best regards

  5. Thanks for the reply!

     

    I want the setup to be as of a good practice as possible of course. I was a little skeptical about doing it this way but I thought I could get away with it and avoid all problems connected with a positive input (spikes etc.).

     

    On the contrary what is the best/min. components, yet good pratice way to use a positive input instead?

     

    I am going to make a couple of these devices so I need to take number of components and the time it takes to solder them in to consideration. Best would be if there was a finished PCB to buy that would do the job. Maybe a step down of some sort, will it do?

     

    Like this http://www.ebay.com/itm/390855989060

     

    Or can it not handle the automotive systems?

     

    Or just a 12v relay?

     

    Kind regards,

    Andreas

  6. Hello

     

    I am working in a msp430 device that is going to be used in a car running of the cars battery. Everything is working fine but I need to know if it is safe to connect a digital input directly from the msp430 to the cars ground via a push button?

     

    Best regards

    Andreas

  7. Hello again

     

    Sorry for the delay :)

     

    I have used your examples and it is working, thanks!

     

    I have a question tho; what is the accuracy of the internal crystal (G2553) or where can I find it in the datasheet?

     

    Couse if I set the timer for 24 hours, it is roughly 5 min off (5 min to much at 2 times I tested it). Is this normal?

     

    Best regards

    Andreas

     

     

    Skickat fr

  8. What is the proper way of using counting variables in loops. Lets say I have 5 loops in a sketch and they all use a counting variable "i". Should this be a unique variable for all 5 loops say i1, i2, i3... or is it ok to use the same variable in all loops and just reset (i=0) it before the loop?

     

    Thanks

     

    Skickat fr

  9. Hello

     

    Please note that I am a beginner :)

     

    I am working on a project that needs a relay to be turned on for a preset time. I have written the following code and it works but obviously no other code can run at the same time. I have been trying to use millis() instead but with no success. Can someone give me a hint?

     

    The timer span will be 1 sec - 999 hours or 1 sec - 99 hours. I have not decided yet, will it be some problems with max to be 999 hours? The timer do not need to be very accurate.

     

    It says the millis() will overflow after about 50 days. If I use millis() somehow will this couse any problems if the timer is enabled while the millis overflows after 50 days?

     

    onTime is the time in milliseconds / 10 ( one hundred of a second) that the relay should be on

      if (relayState != lastRelayState && onTime > 0) {  // See if the state of the relay has changed and if the timer is enabled.
        
        if (relayState == LOW) {  // If relay is activated
          
            onTimeCounter = 10;  // Reset the counter, this is crucial. Reset to 10 to compensate for 1 second delay.
            while (relayState == LOW && onTimeCounter < onTime) {  // Loop until timer is reached or the relay is diactivated externally.
              onTimeCounter++;
              delay(10);  //10ms per cycle
              relayState = digitalRead(relayPin); // Read the state of the relay if it has been diactivated externally.
            }
            
            if (onTimeCounter >= (onTime)-1) {  // When timer is reached switch off the relay
              
              changeRelayState();  // Switch of relay
              
            }  // End of counter reached
            
         }  // End of relay state active
      }  // End of relay state changed
     
      lastRelayState = relayState;  // Reset relay state

    Best regards

    Andreas

  10. If you want to sniff all traffic sent from device 1 to device 2, all you need to do is connect that line to the RX pin on the launchpad.  When device 1 transmits a bit, both devices (device 2 and your sniffer) will read it.

    Thanks!!! Got it working now, sweet! That is exactly what i wanted!

     

    I am gonna play with a little more, sure some more questions will pop up :)

     

    Thanks again for your well written reply, truly appriciate it.

     

    Best regards

    Andreas

  11. Hello

     

    My name is Andreas and I am from Sweden, this is my first post here :)

     

    First of all I want to say that I am very new to microcontrollers, please bear with me. I started off by reading "MSP430 Microcontroller Basics" and then bought TI's Launchpad and read "Getting Started with the MSP430 LaunchPad". Since then I have fiddled with the Launchpad a couple of weeks doing some basic projects. Since my C coding knowledge is not very good I have been working in Energia and the "simpler" coding, not sure what it is called.

     

    I am working on a new project where I need the MSP430 to listen to UART traffic between two devices. Basically I just need to listen for a specific string sent from device 1 to device 2.

     

    So far I have just connected the RXD and TXD of the 2 devices I want to listen to and connected them to the Launchpads P1.1 and P1.2. I have the two pins on the launchpad set to "SW UART". The MSP430 2553 is installed on the Launchpad but with no code on it. I then open Energia and open the serial monitor. In the serial monitor I can see the string I want to fetch and the commands sent by BOTH devices. So far so good. But as soon as I put the code "Serial.begin();" (tried all baud rates) in the MSP430 not changing anything else I still can monitor the communication but just the commands sent from device 1 and not the commands sent from device 2. Also the 2 devices don't work as they should because I suppose the commands from device 2 is not reaching device 1. I know for sure that the commands from device 1 reaches device 2 though, that part works.

     

    I can say also that I don't have any specifics on the baud rate used between the two devices but I am almost sure it is 9600. Strangely I get the same results if I set the serial monitor at 9600, 14400, 19200, 28800, 38400, 57600, or 115200. Only if I set it at 4800 the formatting becomes incorrect!

     

    Oh my god, this got complicated for me to describe, sorry. I am new to all this.

     

    Thanks

     

    Best regards

    Andreas

×
×
  • Create New...