Jump to content
43oh

Taggsladder

Members
  • Content Count

    41
  • Joined

  • Last visited

Posts posted by Taggsladder

  1. 22 hours ago, enl said:

    "if (bar[0]==NULL)" won't look at the pointer value, but instead the memory the pointer references, so that is right out, unless you want to know if the parameter is an empty string (only the null terminator)

    "if (bar == NULL)" should work, in particular if you explicitly pass NULL in since you are comparing a value to itself, as should "if (!bar)", since NULL should be 0.

    I just checked both (using gcc on a windoze machine) and they work as expected, so I can offer no insight as to why you would have a problem. I would suspect that you are seeing a symptom of some other issue than pointer comparison.

     

    Thank you for your input. I think you are right, I looked at some other of my projects and found that I use similar code there that works. I need to dig into it :)

     

  2. Hello

    I don't know if this is quite the right place to post this or if my title is describing this correct and maybe this is more of a general C questions, but I hope its OK to post it here. It is on a MSP430 Launchpad anyway.

    The code is simplified, there is more parameters passed to the function etc.

    // I have a function like this.
    void foo (char* bar) {
      
      if (!bar) Serial.print("bar is NULL"); // I want to check when NULL is passed on but this doesn't work?
      // Also tried (bar == NULL) and (bar[0] == NULL)...
      else Serial.print("bar is not NULL");
    }
    
    // Usually I call it like this.
    foo("Normally text passed here");
    
    // But I would like to call it like this also.
    foo(NULL);

    Looking forward to any reply.

    Best regards

  3. [sOLVED] > QUICK AND DIRTY

     

     

    I got it working now. Not the best way but it does the job. Just a personal project so no worries.

     

    Running the initializing function two times with a delay did the trick for me.

    // Include LCD library.
    #include "LCD_5110.h"
    LCD_5110 myScreen;
    
    void setup() {
            
    	myScreen.begin();  // Start LCD communication.
    
            delay(1000);
            
            myScreen.begin();  // Start LCD communication.
    
    	myScreen.clear();  // Clear LCD.
    
    	myScreen.setFont(0);  // Set "small" font.
    	myScreen.text(4, 2, "TEST");  // Display on LCD.
            
    }
    
    void loop() {
    
    }
    

    Have a nice day!

     

  4. Major bump :)

     

     

    I have the same problem. It works perfect except I need to reset the mcu after every powercycle or else the lcd stays completly blank. I could live with it but its just bugs the h*** out of me.

     

    Just basic sketch. In the code below I used a IO pin for powering the LCD but also tried powering from VCC with no luck.

    // Include LCD library.
    #include "LCD_5110.h"
    LCD_5110 myScreen;
    
    const int lcdVdd = P1_4;
    
    void setup() {
      
            pinMode(lcdVdd, OUTPUT);
            digitalWrite(lcdVdd, HIGH);
            
    	myScreen.begin();  // Start LCD communication.
    
    	myScreen.clear();  // Clear LCD.
    
    	myScreen.setFont(0);  // Set "small" font.
    	myScreen.text(4, 2, "TEST");  // Display on LCD.
    }
    
    void loop() {
    
    }
    

    Tried it with the

     

    Maybe using a R/C reset circuit on the screen would help. When I read the datasheet of this screen, the part saying you can damage it if not reset correctly freaked me out and I didn't bother trying to do it in software.

    I used a 4.7K resistor and a 100nF capacitor (I had them on hand), 47K/10nF will work too.

     

    attachicon.gif5110reset.jpg

     

    Tried with and with out this. No difference.

     

     

     

     

    this is what im using

    void init(void){
    P1OUT &= ~SCLK+DIN+DC+CE+RST;
    __delay_cycles(50000);
    P1OUT |= RST;
    P1OUT &= ~CE;
    shift(instruction, 0x21);
    shift(instruction, 0xC5);
    shift(instruction, 0x12);
    shift(instruction, 0x20);
    shift(instruction, 0x09);
    shift(instruction, 0x0C);
    P1OUT |= CE;
    }
    

    i even removed the delay and it works ok. 

     

     

     

    Tried the library as is and tried changing the myScreen.begin(); function to something similiar:

    void LCD_5110::begin() {  pinMode(_pinChipSelect, OUTPUT);  pinMode(_pinReset, OUTPUT);  pinMode(_pinDataCommand, OUTPUT);  pinMode(_pinSerialData, OUTPUT);  pinMode(_pinSerialClock, OUTPUT);  pinMode(_pinBacklight, OUTPUT);  pinMode(_pinPushButton, INPUT_PULLUP);    delay(500);  digitalWrite(_pinReset, HIGH);  digitalWrite(_pinDataCommand, LOW);  write(_commandLCD, 0x21); // chip is active, horizontal addressing, use extended instruction set  write(_commandLCD, 0xc8); // write VOP to register: 0xC8 for 3V 
  5. Depending on the application, you might try a latching relay instead.

     

    In a low power ap, you can't beat them, but there are a few drawbacks, such as they do not drop out on power loss like a standard relay. Even in a non-low power ap, not needing to power the coil continuously is a nice feature. If you haven't seen a latching relay, among other places you see them is in electronic thermostats.

     

    Great id

  6. Thanks for the reply @@enl!

     

    Ok, I understand. The reverse breakdown of D5 is 200V.

     

    D5

    http://www.farnell.com/datasheets/162697.pdf

     

    Though I think that I will go with the original plan of just using a DPDT signal relay switched by a transistor, find it is easier when you know exactly whats gonna be switched. Would have been neat to use them magic FET's but clearly I have some learning todo :)

     

    This forum is such a great place, thanks again!

     

    Kind regards,

    Andreas

  7. Hello

     

    I am working on a curcuit that need to switch two loads max 200mA. One load gets feed ground and the other load gets feed positive. VCC will be in a span of 6-30VDC. The curciut works as intended when VCC is 6VDC, but at the max span VCC 30VDC all (Q1, Q2, Q4) transistors and the FET breaks when the pin from the MCU goes HIGH. This will happen even if the connector is unconnected.

     

    post-36838-0-19328600-1443614451_thumb.jpg

     

    Q1, Q2

    http://www.farnell.com/datasheets/699988.pdf

     

    post-36838-0-36281300-1443614445_thumb.png

     

     

     

     

    Q4

    http://www.farnell.com/datasheets/1885683.pdf

     

    post-36838-0-55051100-1443614448_thumb.png

     

     

    From what stupid me can read from the datasheet Q1 and Q2 should be able to handle 45V between collector-emitter. But I think that I can understand why Q4 fails becouse it can handle 20V max between gate-source. Am I right? :ph34r:

     

    Thanks

     

    Best regards,

    Andreas

  8. Thanks for the reply! TBT, just the word opamp scares me a little, hehe.

     

    How comes the zener is used in the link and the title is "Accurate Voltage Measurement". Is there a way to calculate this offset in software or would it be to messy? I am not looking for a accurate reading, +- 0.5V in a 10-25V span would do fine.

     

    Best regards

  9. Hello

     

    I want to measure the battery voltage (ballpark measurement) in a car so I thought I do that with a voltage divider connected to a msp430 ADC pin, but I wanted to add overvoltage protection with a zener as in the schematics in the link below. I am using 100k / 10k in the voltage divider and a BZX79C2V7 zener. If I leave the zener disconnected I get the divider to work as expected in a linear fashion, but when I connect the zener I get the correct reading when the input voltage is 10V but if for example I double the input voltage to 20V I get a lower reading compared to when the zener is disconnected and the voltage divider is no longer linear.

     

    Measurements without zener:

     

    10V in, 0.9V to mcu pin

    15V in, 1.35V to mcu pin

    20V in, 1.78V to mcu pin

     

     

    Measurements with zener:

    10V in, 0.9V to mcu pin

    15V in, 1.25V to mcu pin

    20V in, 1.46V to mcu pin

     

     

    Why is this so? B)

     

     

    http://www.re-innovation.co.uk/web12/index.php/en/information/electronics-information/accurate-voltage-measurement

     

     

    Thanks :)

     

    Kind regards

    Andreas

  10. Hello

     

    Cannot get the Nokia 5110 LCD to work with my launchpad and the G2553. First thing I noticed is that when the library example sketch (LCD_5110_main.ino) is uploaded and the LCD is disconnected the backlight pin is floating. Also there is nothing happening when pushing the Launchpad push button 2 that should enable/disable the backlight.

     

    I am using this library:

    https://github.com/energia/Energia/tree/master/examples/07.Display/LCD_5110

     

    As I said with the example sketch uploaded the backlight pin (P2.1) is floating with the line below either true or false. No errors or similiar in Energia when uploading the sketch. Also tried just to put the pin high or low with other code and no problem so it is not a hardware issue i believe.

     

    "boolean backlight = false;"

     

    What am I missing here? :)

     

    Kind regards,

    Andreas

     

     

  11. Hello guys and gals

     

    Another newbie question :)

     

    I have a device that I want to communicate with over UART using the good old MSP430G2553.

     

    The device will have a supply voltage of about 4V and has an absolute max voltage rating of 3.1V on any input pin including the UART, typical 2.8V. Min. 2.4V for HIGH.

     

    First of all, from what I can read from the datasheet the MSP430 will have a UART logic high of Vcc - 0.3V and I am thinking that since the MSP430 supply voltage range is 1.8-3.6V, would it be "good practice" just to power the MSP430 with let's say 2.8V and thus have compatible UART levels with the other device or should I opt for a logic level converter? Pros cons?

     

    Also in the MSP430 datasheet I noted that there is a relation between supply voltage and system frequency. So will the mcu not run at full speed if I power it at 2.8V? It looks like it would be around 12MHz at that voltage.

     

    Thanks

     

    Kind regards

    Andreas

  12. Hello friends

     

    Hope you are all doing great!

     

    I need advice on an external temperature sensor for a MSP430G2553 project. I just need to read the "outside" temperature like a span of -30 to +80 celcius. I "just" ([emoji16]) want to know what the best/easiest/most common sensor would be. Of course I am a quite a newbie to this.

     

    I have looked at some sensor like the lm35 but I read somewhere that it couldn't run at mcu voltage. Also looked at DS18B20 but its just a jungle for me and I don't know what to look for.

     

    Requirements (not any particular order):

    Low price

    Can run at mcu voltage

    Under 1 celcius accuracy

    Nice to have some Energia examples to look at

    The fewer pins the better, but not that important. I have loads of free pins.

     

    Conclusion: A newbie friendly sensor to start out with :)

     

    Sorry if the English is a little off, I have troubles sometimes finding the right words.

     

    Best regards,

    Andreas

  13. In CCS and the like, you can configure your compiler to output a static usage map. This means the space stated there is already in use before entering your main/setup function.

    In addition to that, every nested function call adds 4 bytes plus the size if the function scope variables to that. When I say nested, it means, when function A calls function B, which calls function C, and after that function A calls function D, then the deepest stack would be 3*4+variables in A,B and C, or it would be 2*4+variables in A and D, depending on which is larger.

     

    In your case, your static RAM usage would be 7 * sizeof(int) + 3 * sizeof(long) + 250 * sizeof(char).

    sizeof(char) is 1, sizeof(int) is I think 2, but could be 4, sizeof(long) is probably 4.

    So your RAM usage is already 14+12+250=278 bytes of the 512 bytes available to you. Which leaves only 234 bytes for all other functioncalls and stack variables.

    Then the MspFlash object takes 10 bytes I think, and the call to MspFlash.write takes another 6 bytes (stack), so you're down to 218 bytes.

    Depending on the rest of your application, this is plenty to work with. Do you use malloc, new or anything the like in your application?

     

    Thanks for your reply!

     

    I looked at the map file and I was overwhelmed with data, didn't get much of that :)

     

    I have quite a lot of nested function calls but not deeper than function A calling function B.

     

    Do I understand it right that all the global vars is allocated in the RAM from the beginning and the local vars is allocated when calling the function and reset when the function exits? So the remaing 218 bytes you estimated needs to be allocated by one function bigger that 218B to run out of RAM?

     

    I don't use any malloc or new. The most of the code is just very basic code, IF statements, loops etc.

     

    I did look at this thread:

    http://forum.43oh.com/topic/3682-flash-and-estimated-ram-usage/

     

    This gave me the following:

       text    data     bss     dec     hex
      12842       4     448   13294    33ee
    

    So this would mean I am using 452B (data+bss) out of 512B RAM? Feels dangerously close :/ How accurate is this?

     

    Kind regards

    Andreas

  14. Hello again

     

    Sorry for the delay in replying. I truly appreciate the help you guys give :)

     

    I have tried a bunch of things and I got it working now but I kept the original code and change the other part of the code a little that was giving me crashes. I download Ti's CCS and tried to debug with it but I didn't work it out how to do it. It did give me about 50 compile warnings (nothing major) that Energia didn't say anything about though. They are all fixed now.

     

    The code now works as intended and I have really tested it hard without any issues but it would be interesting to know what coused the crash since if I change some part of the code that was by itself working but caused errors on a remote random part of the code made me also suspect some kind of lack of memory issue maybe.

     

    Since I am a noob please bear with me. I always thought that Energia or whatever compiler/uploader would tell me if I have reached some kind of space/RAM limit in MCU. But that isn't true?

     

    I have about 1500 lines of code.

    The globals vars are as follows:

    7 int

    3 long

    About 250 chars

     

    And a hell of alot of local vars. Also I use the MspFlash.h to write some data to the flash memory.

     

    How can I calculate if I need a bigger MCU?

     

    Best regards

    Andreas

  15. Hello friends

     

    I see that this thread has spiraled out of what I could ever learn by the stretch of the imagination :)

     

    But I still have the problems when I convert char to integer.

     

    This part of the code works as intended and the original problem is solved by increasing the arraysize, but now the MCU crashes and reboots on a remote part of the code not even touching this side of the code!

     

    This is the actual code

                // Put on onftime hours/minutes in a array + terminating NULL byte.
                char onfTimerH[3] = {data[9], data[10]};
                char onfTimerM[3] = {data[12], data[13]};
                
                // Convert onftime hours/minutes to a integer.
                int i_onfTimerH = (int) atoi(onfTimerH);
                int i_onfTimerM = (int) atoi(onfTimerM);
    
                i_onfTimerMin = (i_onfTimerH*60) + i_onfTimerM;  // Calculate onftime in minutes.

    As soon as I remove one of the char to int conversionlines like below everything is working!

                // Put on onftime hours/minutes in a array + terminating NULL byte.
                char onfTimerH[3] = {data[9], data[10]};
                char onfTimerM[3] = {data[12], data[13]};
                
                // Convert onftime hours/minutes to a integer.
                int i_onfTimerH = (int) atoi(onfTimerH);
                //int i_onfTimerM = (int) atoi(onfTimerM);
    
                i_onfTimerMin = (i_onfTimerH*60);  // Calculate onftime in minutes.
    

    What am I doing wrong?

     

    BTW the reason that I need two char-to-int lines is couse I need to convert hours and minutes to total minutes.

     

    For example the data could hold:

    data[9] and data[10] is the hours, lets say 09 hours

    data[12] and data[13] is the minutes, lets say 99 minutes

     

    At the moment I convert both chars to int like the above code and then add them ((i_onfTimerH*60) + i_onfTimerM), but if someone can tell me a better way of converting theese chars to total minutes it removes the need for the two char-to-int lines. Please note that the hours and minutes both can range from 01-99.

     

    Looking forward to any replies.

     

    Best regards

    Andreas

  16. Hello

     

    First of all I am a newbie :)

     

    And I am working on a project and I was wondering if it is possible to combine a string with a variable to clean up the code a little, something like this:

    char phoneNumber[ ] = "123456789";
    
    Serial.print("AT+CMGS=\"" + phoneNumber + "\"");
    

    This gives an error on compiling.

     

    Looking forward to any replies, thanks!

     

    Best regards

    Andreas

×
×
  • Create New...