Jump to content
43oh

zeke

Members
  • Content Count

    1,782
  • Joined

  • Last visited

  • Days Won

    102

Reputation Activity

  1. Like
    zeke reacted to bluehash in Does anyone have this book?   
    I had no idea how that happened. In case you don't mind, this is 43oh's MSP430%20State%20Machine%20Programming'>affiliate link. Feel free to use it.
  2. Like
    zeke got a reaction from GeekDoc in printf() function   
    If you need the printf() function and you have enough code space in your device then this routine will be your best bet, in my opinion.
     
    Help! CCS4.0 with MSP430F2252 has Trouble with 32 bit (Long) Data.
     
    For long term storage, this is the message that contains the code:

    Posted by Bin replied on 30 Dec 2009 1:55 PM Verified by Bin Verified Answer Prodigy80 Points Good inspiration. I casted all numbers with (long int) when calling printf() and it works! I think it is acceptable. A warning (is also an explanation) is written into the printf() comment section. See following source code. The printf() is ok to use now. Everyone is free to use and modify the source code below and I assume no responsibility. /*------------------------------------------------------------------- DESCRIPTION: Send one char in TX buffer, if it is not busy. Wait until not busy. INPUTS: One char. OUTPUTS: Send all the char in TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ // Modify this routine so that it points to YOUR UART (zeke) void putChar(unsigned char byte) { while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = byte; // Load Tx register that clear UCA0TXIFG } /*------------------------------------------------------------------- DESCRIPTION: Move numbers of lines up in the HyperTerminal. INPUTS: None. OUTPUTS: Line up to TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ void linesUp(unsigned char lines) { unsigned char i; for (i = 0; i < lines; ++i) { putChar(0x1b); putChar(0x5b); putChar(0x41); } } /*------------------------------------------------------------------- DESCRIPTION: Send out charater strings with defined width, justification and padding. Width = 0 or width < string length means unlimited width. Normal padding is space and left justification, but it can pad '0' or pad to the right side, depending on pad value. pad justification padding char bxxxxxx00 left ' ' bxxxxxx1x right ' ' or '0' bxxxxxxx1 left or right '0' INPUTS: Valid string and special charater in form of "\n" for example refered by pointer *string. Output field width. Justification and padding flag pad. OUTPUTS: Sent formated string to com port output. RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PAD_RIGHT 0x01 #define PAD_ZERO 0x02 int prints(char *string, unsigned char width, unsigned char pad) { int pc = 0; unsigned char padchar = ' '; // The pading char is space normally if (width > 0) // If output width is defined { unsigned char len = 0; char *ptr; for (ptr = string; *ptr; ++ptr) ++len; // Calculate string length and put it in len if (len >= width) width = 0; // If string is longer than width, then width is not applicable define as zero else width -= len; // Else redefine width as padding spaces if (pad & PAD_ZERO) padchar = '0'; // If padding char is zero, then get padchar as zero ready instead of original space } if (!(pad & PAD_RIGHT)) // If not right padding - left justification { for (; width > 0; --width) // If ther is padding width. Output padding char as '0' or ' '. { putChar (padchar); ++pc; } } for (; *string ; ++string) // Output the full string { putChar (*string); ++pc; } for (; width > 0; --width) { // Write padding char to the right if normal left justification putChar (padchar); ++pc; } return pc; // Return the output char number } /*------------------------------------------------------------------- * DESCRIPTION: Print 32 bit signed interger in dec or hex. In specific * width, padding and justification using prints(). Use 12 byte buffer * which is enough for 32 bit int. * INPUTS: Up to 32 byte signed interger i. Counting base: 10 or 16. * Sign flag sg. Output string width. padding and justification flag. * Leter base for number conversion. * OUTPUTS: Sent formated interger as string to com port output. * RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PRINT_BUF_LEN 12 int printi(long int i, unsigned char b, unsigned char sg, unsigned char width, unsigned char pad, unsigned char letbase) { char print_buf[PRINT_BUF_LEN]; // Interger as string array char *s; char neg = 0; unsigned long int t; unsigned long int u = i; int pc = 0; if (i == 0) // If output char is 0, then just output it with padding and width. { print_buf[0] = '0'; print_buf[1] = '\0'; // Always remenber to put string end return prints(print_buf, width, pad); //Print out zero and done. } if (sg && (b == 10) && (i < 0)) // If it is a negative int, then record the '-' and number as positive { neg = 1; u = -i; } s = print_buf + PRINT_BUF_LEN-1; // Point s to the end of the output buffer and put a null there. *s = '\0'; while (u) // Convert the positive int to string with whatever counting base, dec, or hex. { t = u % b; if( t >= 10 ) t += letbase - '0' - 10; *--s = t + '0'; u /= b; } if (neg) { // If it is a negative number if( width && (pad & PAD_ZERO) ) { // If there is width, right justified and pad with zero, output negative sign. putChar ('-'); ++pc; --width; } else *--s = '-'; // Otherwise put the '-' to string buffer. } return pc + prints (s, width, pad); // Output the string buffer and return the output counter. } /*------------------------------------------------------------------- * DESCRIPTION: short form of printf. Print argument strings with mixed * varables (string or interger)inside formated. * INPUTS: Argument string pointer. * OUTPUTS: print out the argument with style using prints() and printi(). * RETURNS: Total of chars sent. * Warning!!! varables and constant numbers even 0, must casted with * (long int)in printf(), if it is going to print out using * format "u", "d", "X" and "x"! Or the complier will assigned * 16-bit for data smaller than 16 bit and the argument pointer * will fetch a wrong 32-bit data and the argument point * increament will be in wrong size. * Limitations: 1) It treats all interger as 32 bit data only. * 2) No floating point data presentation. * 3) Has left/right alignment with 0 padding. * 4) Has format code "s", "d", "X", "x", "u" and "c" only. ---------------------------------------------------------------------*/ int printf(char *format, ...) { int width, pad; int pc = 0; char scr[2]; va_list args; va_start(args, format); for (; *format != 0; ++format) { if (*format == '%') { ++format; width = pad = 0; if (*format == '\0') break; if (*format == '%') goto out; if (*format == '-') { ++format; pad = PAD_RIGHT; } while (*format == '0') { ++format; pad |= PAD_ZERO; } for ( ; *format >= '0' && *format <= '9'; ++format) { width *= 10; width += *format - '0'; } if( *format == 's' ) { char *s = (char *)va_arg( args, int ); pc += prints (s?s:"(null)", width, pad); continue; } if( *format == 'd' ) { pc += printi (va_arg( args, long int ), 10, 1, width, pad, 'a'); continue; } if( *format == 'x' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'a'); continue; } if( *format == 'X' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'A'); continue; } if( *format == 'u' ) { pc += printi (va_arg( args, long int ), 10, 0, width, pad, 'a'); continue; } if( *format == 'c' ) { // char are converted to int then pushed on the stack scr[0] = (char)va_arg( args, int ); scr[1] = '\0'; pc += prints (scr, width, pad); continue; } } else { out: putChar(*format); ++pc; } } va_end( args ); return pc; } /* Test printf() below */ main { char *ptr = "Hello world!"; char *np = 0; long int i = 5; int bs = sizeof(long int)*8; // Bit to shift long int mi = ((long int)1 << (bs-1)) + 1; // Maximum negative number printf("%s\n", ptr); printf("printf test\n"); printf("%s is null pointer\n", np); printf("%d = 5\n", (long int)i); printf("%d = - max int\n", mi); printf("Long int 123456789 print out is %u", (long int)123456789); printf("\nmi in hex is %x\n", (long int)mi); printf("bs in dec is %u\n", (long int)bs); printf("char %c = 'a'\n", 'a'); printf("hex %x = ff\n", (long int)0xff); printf("hex %02x = 00\n", (long int)0); printf("signed %d = unsigned %u = hex %x\n", (long int)-32767, (long int)-32767, (long int)-32767); printf("signed %d = unsigned %u = hex %x\n", (long int)-3, (long int)-3, (long int)-3); printf("%d %s(s)%", (long int)0, "message"); printf("\n"); printf("%d %s(s) with %%\n", (long int)0, "message"); printf("justif: \"%-10s\"\n", "left"); printf("justif: \"%10s\"\n", "right"); printf(" 3: %04d zero padded\n", (long int)3); printf(" 3: %-4d left justif.\n", (long int)3); printf(" 3: %4d right justif.\n", (long int)3); printf("-3: %04d zero padded\n", (long int)-3); printf("-3: %-4d left justif.\n", (long int)-3); printf("-3: %4d right justif.\n\n\n", (long int)-3); } Result: Hello world! printf test (null) is null pointer 5 = 5 -2147483647 = - max int Long int 123456789 print out is 123456789 mi in hex is 80000001 bs in dec is 32 char a = 'a' hex ff = ff hex 00 = 00 signed -32767 = unsigned 4294934529 = hex ffff8001 signed -3 = unsigned 4294967293 = hex fffffffd 0 message(s) 0 message(s) with % justif: "left " justif: " right" 3: 0003 zero padded 3: 3 left justif. 3: 3 right justif. -3: -003 zero padded -3: -3 left justif. -3: -3 right justif.
     
    To use this code, modify the putChar() function so that it points to your UART.
     
    To verify it works, run the sample main() routine and compare the output to what is posted here.
     
    @Bin, wherever you are, Thank you!
  3. Like
    zeke got a reaction from GeekDoc in getting printf() working   
    I just wanted to follow up and say that if you need the printf() function then this routine will be your best bet, in my opinion.
     
    Help! CCS4.0 with MSP430F2252 has Trouble with 32 bit (Long) Data.
     
    For long term storage, I post the message that contains the code here:

    Posted by Bin replied on 30 Dec 2009 1:55 PM Verified by Bin Verified Answer Prodigy80 Points Good inspiration. I casted all numbers with (long int) when calling printf() and it works! I think it is acceptable. A warning (is also an explanation) is written into the printf() comment section. See following source code. The printf() is ok to use now. Everyone is free to use and modify the source code below and I assume no responsibility. /*------------------------------------------------------------------- DESCRIPTION: Send one char in TX buffer, if it is not busy. Wait until not busy. INPUTS: One char. OUTPUTS: Send all the char in TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ // Modify this routine so that it points to YOUR UART (zeke) void putChar(unsigned char byte) { while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = byte; // Load Tx register that clear UCA0TXIFG } /*------------------------------------------------------------------- DESCRIPTION: Move numbers of lines up in the HyperTerminal. INPUTS: None. OUTPUTS: Line up to TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ void linesUp(unsigned char lines) { unsigned char i; for (i = 0; i < lines; ++i) { putChar(0x1b); putChar(0x5b); putChar(0x41); } } /*------------------------------------------------------------------- DESCRIPTION: Send out charater strings with defined width, justification and padding. Width = 0 or width < string length means unlimited width. Normal padding is space and left justification, but it can pad '0' or pad to the right side, depending on pad value. pad justification padding char bxxxxxx00 left ' ' bxxxxxx1x right ' ' or '0' bxxxxxxx1 left or right '0' INPUTS: Valid string and special charater in form of "\n" for example refered by pointer *string. Output field width. Justification and padding flag pad. OUTPUTS: Sent formated string to com port output. RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PAD_RIGHT 0x01 #define PAD_ZERO 0x02 int prints(char *string, unsigned char width, unsigned char pad) { int pc = 0; unsigned char padchar = ' '; // The pading char is space normally if (width > 0) // If output width is defined { unsigned char len = 0; char *ptr; for (ptr = string; *ptr; ++ptr) ++len; // Calculate string length and put it in len if (len >= width) width = 0; // If string is longer than width, then width is not applicable define as zero else width -= len; // Else redefine width as padding spaces if (pad & PAD_ZERO) padchar = '0'; // If padding char is zero, then get padchar as zero ready instead of original space } if (!(pad & PAD_RIGHT)) // If not right padding - left justification { for (; width > 0; --width) // If ther is padding width. Output padding char as '0' or ' '. { putChar (padchar); ++pc; } } for (; *string ; ++string) // Output the full string { putChar (*string); ++pc; } for (; width > 0; --width) { // Write padding char to the right if normal left justification putChar (padchar); ++pc; } return pc; // Return the output char number } /*------------------------------------------------------------------- * DESCRIPTION: Print 32 bit signed interger in dec or hex. In specific * width, padding and justification using prints(). Use 12 byte buffer * which is enough for 32 bit int. * INPUTS: Up to 32 byte signed interger i. Counting base: 10 or 16. * Sign flag sg. Output string width. padding and justification flag. * Leter base for number conversion. * OUTPUTS: Sent formated interger as string to com port output. * RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PRINT_BUF_LEN 12 int printi(long int i, unsigned char b, unsigned char sg, unsigned char width, unsigned char pad, unsigned char letbase) { char print_buf[PRINT_BUF_LEN]; // Interger as string array char *s; char neg = 0; unsigned long int t; unsigned long int u = i; int pc = 0; if (i == 0) // If output char is 0, then just output it with padding and width. { print_buf[0] = '0'; print_buf[1] = '\0'; // Always remenber to put string end return prints(print_buf, width, pad); //Print out zero and done. } if (sg && (b == 10) && (i < 0)) // If it is a negative int, then record the '-' and number as positive { neg = 1; u = -i; } s = print_buf + PRINT_BUF_LEN-1; // Point s to the end of the output buffer and put a null there. *s = '\0'; while (u) // Convert the positive int to string with whatever counting base, dec, or hex. { t = u % b; if( t >= 10 ) t += letbase - '0' - 10; *--s = t + '0'; u /= b; } if (neg) { // If it is a negative number if( width && (pad & PAD_ZERO) ) { // If there is width, right justified and pad with zero, output negative sign. putChar ('-'); ++pc; --width; } else *--s = '-'; // Otherwise put the '-' to string buffer. } return pc + prints (s, width, pad); // Output the string buffer and return the output counter. } /*------------------------------------------------------------------- * DESCRIPTION: short form of printf. Print argument strings with mixed * varables (string or interger)inside formated. * INPUTS: Argument string pointer. * OUTPUTS: print out the argument with style using prints() and printi(). * RETURNS: Total of chars sent. * Warning!!! varables and constant numbers even 0, must casted with * (long int)in printf(), if it is going to print out using * format "u", "d", "X" and "x"! Or the complier will assigned * 16-bit for data smaller than 16 bit and the argument pointer * will fetch a wrong 32-bit data and the argument point * increament will be in wrong size. * Limitations: 1) It treats all interger as 32 bit data only. * 2) No floating point data presentation. * 3) Has left/right alignment with 0 padding. * 4) Has format code "s", "d", "X", "x", "u" and "c" only. ---------------------------------------------------------------------*/ int printf(char *format, ...) { int width, pad; int pc = 0; char scr[2]; va_list args; va_start(args, format); for (; *format != 0; ++format) { if (*format == '%') { ++format; width = pad = 0; if (*format == '\0') break; if (*format == '%') goto out; if (*format == '-') { ++format; pad = PAD_RIGHT; } while (*format == '0') { ++format; pad |= PAD_ZERO; } for ( ; *format >= '0' && *format <= '9'; ++format) { width *= 10; width += *format - '0'; } if( *format == 's' ) { char *s = (char *)va_arg( args, int ); pc += prints (s?s:"(null)", width, pad); continue; } if( *format == 'd' ) { pc += printi (va_arg( args, long int ), 10, 1, width, pad, 'a'); continue; } if( *format == 'x' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'a'); continue; } if( *format == 'X' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'A'); continue; } if( *format == 'u' ) { pc += printi (va_arg( args, long int ), 10, 0, width, pad, 'a'); continue; } if( *format == 'c' ) { // char are converted to int then pushed on the stack scr[0] = (char)va_arg( args, int ); scr[1] = '\0'; pc += prints (scr, width, pad); continue; } } else { out: putChar(*format); ++pc; } } va_end( args ); return pc; } /* Test printf() below */ main { char *ptr = "Hello world!"; char *np = 0; long int i = 5; int bs = sizeof(long int)*8; // Bit to shift long int mi = ((long int)1 << (bs-1)) + 1; // Maximum negative number printf("%s\n", ptr); printf("printf test\n"); printf("%s is null pointer\n", np); printf("%d = 5\n", (long int)i); printf("%d = - max int\n", mi); printf("Long int 123456789 print out is %u", (long int)123456789); printf("\nmi in hex is %x\n", (long int)mi); printf("bs in dec is %u\n", (long int)bs); printf("char %c = 'a'\n", 'a'); printf("hex %x = ff\n", (long int)0xff); printf("hex %02x = 00\n", (long int)0); printf("signed %d = unsigned %u = hex %x\n", (long int)-32767, (long int)-32767, (long int)-32767); printf("signed %d = unsigned %u = hex %x\n", (long int)-3, (long int)-3, (long int)-3); printf("%d %s(s)%", (long int)0, "message"); printf("\n"); printf("%d %s(s) with %%\n", (long int)0, "message"); printf("justif: \"%-10s\"\n", "left"); printf("justif: \"%10s\"\n", "right"); printf(" 3: %04d zero padded\n", (long int)3); printf(" 3: %-4d left justif.\n", (long int)3); printf(" 3: %4d right justif.\n", (long int)3); printf("-3: %04d zero padded\n", (long int)-3); printf("-3: %-4d left justif.\n", (long int)-3); printf("-3: %4d right justif.\n\n\n", (long int)-3); } Result: Hello world! printf test (null) is null pointer 5 = 5 -2147483647 = - max int Long int 123456789 print out is 123456789 mi in hex is 80000001 bs in dec is 32 char a = 'a' hex ff = ff hex 00 = 00 signed -32767 = unsigned 4294934529 = hex ffff8001 signed -3 = unsigned 4294967293 = hex fffffffd 0 message(s) 0 message(s) with % justif: "left " justif: " right" 3: 0003 zero padded 3: 3 left justif. 3: 3 right justif. -3: -003 zero padded -3: -3 left justif. -3: -3 right justif.
     
    To use this code, modify the Putchar() function so that it points to your UART.
    To verify it works, run the sample main() routine and compare the output to what is posted here.
     
    @Bin, wherever you are, Thank you!
  4. Like
    zeke got a reaction from jsolarski in Addiction to buying parts   
    Holy Crap! That place is a GOLDMINE!!!
     
    Check this Traffic Light out.
     
    You might be able to tan yourself with 196 LED's!
     
    Time to whip out the credit card!
     
    I hate you jsolarski.

  5. Like
    zeke reacted to jsolarski in Addiction to buying parts   
    Yes i have an addiction to buying parts i may not ever need.....how do you cure yourself of such an addiction? Buy More Parts!!!
     
     
     
    This order has some real winners, but really what can i do with a 300baud modem lol
    if you are looking for some just odds and ends parts http://www.goldmine-elec.com/
    and if you ever need a 7400/4000 series IC this is the place to go, I think they have most of them for cheap.
    FYI I do not know how much international shipping is, but US ground is pretty cheap.......
     
     
     
     
     
    ---------------------------------------------------------------------------
    ITEM# DESCRIPTION QTY TOTAL
    ---------------------------------------------------------------------------
    G16133 Amazing Wire Glue 1.00 $3.95
    ---------------------------------------------------------------------------
    G16873A PLCC-68 Socket (Through Hole) / Brand: 1.00 $0.97
    ---------------------------------------------------------------------------
    GP28 IC Socket Assortment 1.00 $2.49
    ---------------------------------------------------------------------------
    G9303 3 Lead Piezo Disk (Pkg of 2) 2.00 $2.00
    ---------------------------------------------------------------------------
    G17892 SALE! LCD Display Assortment 1.00 $0.99
    ---------------------------------------------------------------------------
    A10224 MC14543BCP BCD-to-7 Segment Latch/Decod2.00 $1.38
    ---------------------------------------------------------------------------
    A20538 PBL3717A Bipolar Stepper Motor Driver (4.00 $4.36
    ---------------------------------------------------------------------------
    G14197 SALE! Mini Stepper Motor w/ Driver Sche4.00 $3.56
    ---------------------------------------------------------------------------
    A10025 DM7493AN Decade and Binary Counter (Nat2.00 $0.70
    ---------------------------------------------------------------------------
    A10137 74VHC943N 300 Baud Modem w/5V Supply (N2.00 $3.90
    ---------------------------------------------------------------------------
    A20010 74F164PC Serial-In Parallel-Out Shift R2.00 $1.10
    ---------------------------------------------------------------------------
     
    SUB TOTAL : $25.40
    TAX : $0.00
    SHIPPING : $4.95
    ORDER TOTAL : $30.35
  6. Like
    zeke reacted to bluehash in C-Bitmap Question   
    http://en.radzio.dxp.pl/bitmap_converter/
     
    More links:
    http://bitmap2lcd.vosforums.com/other-t ... g-t18.html
  7. Like
    zeke got a reaction from bluehash in MSP430, mspgcc and Linux   
    Did you see the article on HackADay today?
    debugging-msp430-using-eclipse/
     
    It links to Springuin's tutorial on getting Eclipse and mspgcc working on windows.
  8. Like
    zeke got a reaction from jsolarski in getting printf() working   
    In the last couple of days, I have collected some primo information on this topic and I thought I should post links so others could benefit.
     
    1. how to point printf to UART on MSP430F1232
    2. Help! CCS4.0 with MSP430F2252 has Trouble with 32 bit (Long) Data.
    3. IAR AppNote 430-03
    4. Tips for using printf
    5. Printf support in compiler
    6. printf on msp430
     
    Today, I was able to successfully test the solution presented at link 2 but it took a lot of flash space.
    MSP430: Program loaded. Code Size - Text: 3024 bytes Data: 774 bytes
     
    Good thing the F5438 has a lot of flash.
     
     
    There is one more method that I would like to try. It's a combination of link 6 and some ideas my mentor had. Stay tuned.
  9. Like
    zeke reacted to thanhtran in getting printf() working   
    I've tried similar thing (i.e implement put_char()) and enable cut down version printf in CCS, but when I tried to use it, I had problem with not enough memory on the 22F74 (1K RAM). Couldn't figure out how to solve it, but then I was able to find this "tiny printf" which worked well
     
    http://www.sparetimelabs.com/tinyprintf/index.html
     
    -Thanh
  10. Like
    zeke reacted to RobG in C/C++ Formatter   
    After spending more and more time with my LaunchPad and CCS, I started to miss one of the features I use daily in my Eclipse, code formatter. CCS does not come with a built-in one, but there are plug-ins available. The one I found is called Astyleand it works pretty well.
     
    To install it:
    Help -> Software Updates -> Find and Install... -> Search for new features... -> New Remote Site
    Name can be Astyle, URL: http://astyleclipse.sourceforge.net/update
    Finish, agree, install, restart, etc.
    After restart:
    Window -> Preferences... -> C/C++ -> Code Formatter -> Formatters -> Astyle Plugin, Apply and OK.
    In Preferences -> Astyle, you can choose the actual style, kr in my opinion is the best.
    To format, Ctrl-Shift-F
     
    Enjoy nice code! ( doesn't mean bug free )
  11. Like
    zeke got a reaction from NatureTM in success! - Identified 17 devices on 1 Wire Bus   
    Well, the answer is both yes and no.
     
    Yes to how it's being said.
    No to what devices are being queried.
     
    Dallas Semiconductor (now Maxim) created a family of devices that talk 1-wire protocol. Here's a copy/paste from their website:
     
    The 1-Wire and iButton products combine the single-contact 1-Wire serial interface with nonvolatile memory, mixed-signal, and secure authentication functions into products that serve a broad range of applications. 1-Wire products are manufactured in traditional IC packaging. iButton products are available in a unique, robust stainless steel package.
     
    But how would I use these devices?
     
    Well, I have been trying to land a contract with a local company that uses a truck load of ds18b20's in their product. We're talking in the order of 400 to 500 temp sensors in one installation. Every single one of these sensors is on a single 1-wire bus. They monitor the temperature of big piles of stuff to prevent spoilage and whatnot. I'm trying to prove to myself that I can do this and somehow land a job. Wouldn't that be cool to walk into a job interview and do a hands on demo? Scary but cool.
     
    Did I answer your question?
  12. Like
    zeke got a reaction from gatesphere in success! - Identified 17 devices on 1 Wire Bus   
    Today is a good day.
     
    1. I got my 1-wire search algorithm working. I have been able to successfully identify 17 devices on the 1-wire bus.
    2. I discovered that DS1821's cannot be searched for on the 1-wire bus. Their presence kills the search algorithm.
    3. I got my hardware UART baudrate config routines sorted out. I can run between 9600 and 460800 Baud.
    3. I love this Saleae Logic analyzer that I got last Friday. What a life saver!
     
    Here's a screenshot of it showing 10 1-Wire sensors during the search routine.

     
    Here's what the output looks like for 17 sensors:

    PacketId, Time[s], Detail, [data] 0,0,Reset Pulse 0,0.0005115,Presence Pulse 1,0.00097,Reset Pulse 1,0.001481,Presence Pulse 1,0.001944,Search Rom Command, 0xF0 1,0.002529,ROM Family Code, 0x10 1,0.004464,ROM Code, 0x0008022E69B2 1,0.016032,ROM CRC, 0x2C 2,0.01798,Reset Pulse 2,0.01849,Presence Pulse 2,0.0189535,Search Rom Command, 0xF0 2,0.0195385,ROM Family Code, 0x10 2,0.021476,ROM Code, 0x0008022E6C86 2,0.033045,ROM CRC, 0xCF 3,0.0349955,Reset Pulse 3,0.035506,Presence Pulse 3,0.0359695,Search Rom Command, 0xF0 3,0.036554,ROM Family Code, 0x28 3,0.0384905,ROM Code, 0x000002E13980 3,0.0500605,ROM CRC, 0x0A 4,0.0520075,Reset Pulse 4,0.052518,Presence Pulse 4,0.0529815,Search Rom Command, 0xF0 4,0.053566,ROM Family Code, 0x28 4,0.0555025,ROM Code, 0x0000030F101A 4,0.0670725,ROM CRC, 0x88 5,0.06902,Reset Pulse 5,0.0695305,Presence Pulse 5,0.0699935,Search Rom Command, 0xF0 5,0.070579,ROM Family Code, 0x28 5,0.072516,ROM Code, 0x0000030F08EB 5,0.084089,ROM CRC, 0x8F 6,0.086038,Reset Pulse 6,0.086549,Presence Pulse 6,0.0870115,Search Rom Command, 0xF0 6,0.0875965,ROM Family Code, 0x1C 6,0.089529,ROM Code, 0x00000537A27F 6,0.101104,ROM CRC, 0x09 7,0.1030515,Reset Pulse 7,0.103562,Presence Pulse 7,0.1040255,Search Rom Command, 0xF0 7,0.104611,ROM Family Code, 0x1C 7,0.1065445,ROM Code, 0x0000052C4D7F 7,0.1181165,ROM CRC, 0x10 8,0.120063,Reset Pulse 8,0.1205735,Presence Pulse 8,0.121037,Search Rom Command, 0xF0 8,0.1216225,ROM Family Code, 0x22 8,0.123555,ROM Code, 0x0000002A3ACB 8,0.1351255,ROM CRC, 0xA0 9,0.137074,Reset Pulse 9,0.137585,Presence Pulse 9,0.1380485,Search Rom Command, 0xF0 9,0.138634,ROM Family Code, 0x22 9,0.1405665,ROM Code, 0x0000002A702F 9,0.152135,ROM CRC, 0x01 10,0.1540815,Reset Pulse 10,0.1545915,Presence Pulse 10,0.1550545,Search Rom Command, 0xF0 10,0.15564,ROM Family Code, 0x01 10,0.157573,ROM Code, 0x000013B1FBEC 10,0.1691465,ROM CRC, 0x0F 11,0.1710955,Reset Pulse 11,0.1716065,Presence Pulse 11,0.17207,Search Rom Command, 0xF0 11,0.172655,ROM Family Code, 0x01 11,0.174589,ROM Code, 0x000013B22BDC 11,0.1861595,ROM CRC, 0x34 12,0.188107,Reset Pulse 12,0.188617,Presence Pulse 12,0.18908,Search Rom Command, 0xF0 12,0.1896645,ROM Family Code, 0x2D 12,0.1915995,ROM Code, 0x00000209FB06 12,0.203172,ROM CRC, 0x6F 13,0.205121,Reset Pulse 13,0.2056315,Presence Pulse 13,0.2060945,Search Rom Command, 0xF0 13,0.2066795,ROM Family Code, 0x2D 13,0.208614,ROM Code, 0x0000020A0E5F 13,0.220185,ROM CRC, 0x2B 14,0.2221335,Reset Pulse 14,0.2226435,Presence Pulse 14,0.2231065,Search Rom Command, 0xF0 14,0.223692,ROM Family Code, 0x43 14,0.2256255,ROM Code, 0x0000001E305C 14,0.2371975,ROM CRC, 0x7A 15,0.2391465,Reset Pulse 15,0.2396565,Presence Pulse 15,0.24012,Search Rom Command, 0xF0 15,0.2407055,ROM Family Code, 0x43 15,0.2426395,ROM Code, 0x0000001E286B 15,0.2542075,ROM CRC, 0x50 16,0.256154,Reset Pulse 16,0.2566645,Presence Pulse 16,0.2571275,Search Rom Command, 0xF0 16,0.257713,ROM Family Code, 0x23 16,0.259645,ROM Code, 0x000000F0D232 16,0.271214,ROM CRC, 0x87 ,0.273162,Reset Pulse ,0.273673,Presence Pulse ,0.2741355,Search Rom Command, 0xF0 ,0.2747205,ROM Family Code, 0x23 ,0.2766535,ROM Code, 0x000000F0BCC3 ,0.2882255,ROM CRC, 0x71
     
    Today is a good day.

     
    Next on the list is the dreaded printf().
  13. Like
    zeke got a reaction from jsolarski in success! - Identified 17 devices on 1 Wire Bus   
    Today is a good day.
     
    1. I got my 1-wire search algorithm working. I have been able to successfully identify 17 devices on the 1-wire bus.
    2. I discovered that DS1821's cannot be searched for on the 1-wire bus. Their presence kills the search algorithm.
    3. I got my hardware UART baudrate config routines sorted out. I can run between 9600 and 460800 Baud.
    3. I love this Saleae Logic analyzer that I got last Friday. What a life saver!
     
    Here's a screenshot of it showing 10 1-Wire sensors during the search routine.

     
    Here's what the output looks like for 17 sensors:

    PacketId, Time[s], Detail, [data] 0,0,Reset Pulse 0,0.0005115,Presence Pulse 1,0.00097,Reset Pulse 1,0.001481,Presence Pulse 1,0.001944,Search Rom Command, 0xF0 1,0.002529,ROM Family Code, 0x10 1,0.004464,ROM Code, 0x0008022E69B2 1,0.016032,ROM CRC, 0x2C 2,0.01798,Reset Pulse 2,0.01849,Presence Pulse 2,0.0189535,Search Rom Command, 0xF0 2,0.0195385,ROM Family Code, 0x10 2,0.021476,ROM Code, 0x0008022E6C86 2,0.033045,ROM CRC, 0xCF 3,0.0349955,Reset Pulse 3,0.035506,Presence Pulse 3,0.0359695,Search Rom Command, 0xF0 3,0.036554,ROM Family Code, 0x28 3,0.0384905,ROM Code, 0x000002E13980 3,0.0500605,ROM CRC, 0x0A 4,0.0520075,Reset Pulse 4,0.052518,Presence Pulse 4,0.0529815,Search Rom Command, 0xF0 4,0.053566,ROM Family Code, 0x28 4,0.0555025,ROM Code, 0x0000030F101A 4,0.0670725,ROM CRC, 0x88 5,0.06902,Reset Pulse 5,0.0695305,Presence Pulse 5,0.0699935,Search Rom Command, 0xF0 5,0.070579,ROM Family Code, 0x28 5,0.072516,ROM Code, 0x0000030F08EB 5,0.084089,ROM CRC, 0x8F 6,0.086038,Reset Pulse 6,0.086549,Presence Pulse 6,0.0870115,Search Rom Command, 0xF0 6,0.0875965,ROM Family Code, 0x1C 6,0.089529,ROM Code, 0x00000537A27F 6,0.101104,ROM CRC, 0x09 7,0.1030515,Reset Pulse 7,0.103562,Presence Pulse 7,0.1040255,Search Rom Command, 0xF0 7,0.104611,ROM Family Code, 0x1C 7,0.1065445,ROM Code, 0x0000052C4D7F 7,0.1181165,ROM CRC, 0x10 8,0.120063,Reset Pulse 8,0.1205735,Presence Pulse 8,0.121037,Search Rom Command, 0xF0 8,0.1216225,ROM Family Code, 0x22 8,0.123555,ROM Code, 0x0000002A3ACB 8,0.1351255,ROM CRC, 0xA0 9,0.137074,Reset Pulse 9,0.137585,Presence Pulse 9,0.1380485,Search Rom Command, 0xF0 9,0.138634,ROM Family Code, 0x22 9,0.1405665,ROM Code, 0x0000002A702F 9,0.152135,ROM CRC, 0x01 10,0.1540815,Reset Pulse 10,0.1545915,Presence Pulse 10,0.1550545,Search Rom Command, 0xF0 10,0.15564,ROM Family Code, 0x01 10,0.157573,ROM Code, 0x000013B1FBEC 10,0.1691465,ROM CRC, 0x0F 11,0.1710955,Reset Pulse 11,0.1716065,Presence Pulse 11,0.17207,Search Rom Command, 0xF0 11,0.172655,ROM Family Code, 0x01 11,0.174589,ROM Code, 0x000013B22BDC 11,0.1861595,ROM CRC, 0x34 12,0.188107,Reset Pulse 12,0.188617,Presence Pulse 12,0.18908,Search Rom Command, 0xF0 12,0.1896645,ROM Family Code, 0x2D 12,0.1915995,ROM Code, 0x00000209FB06 12,0.203172,ROM CRC, 0x6F 13,0.205121,Reset Pulse 13,0.2056315,Presence Pulse 13,0.2060945,Search Rom Command, 0xF0 13,0.2066795,ROM Family Code, 0x2D 13,0.208614,ROM Code, 0x0000020A0E5F 13,0.220185,ROM CRC, 0x2B 14,0.2221335,Reset Pulse 14,0.2226435,Presence Pulse 14,0.2231065,Search Rom Command, 0xF0 14,0.223692,ROM Family Code, 0x43 14,0.2256255,ROM Code, 0x0000001E305C 14,0.2371975,ROM CRC, 0x7A 15,0.2391465,Reset Pulse 15,0.2396565,Presence Pulse 15,0.24012,Search Rom Command, 0xF0 15,0.2407055,ROM Family Code, 0x43 15,0.2426395,ROM Code, 0x0000001E286B 15,0.2542075,ROM CRC, 0x50 16,0.256154,Reset Pulse 16,0.2566645,Presence Pulse 16,0.2571275,Search Rom Command, 0xF0 16,0.257713,ROM Family Code, 0x23 16,0.259645,ROM Code, 0x000000F0D232 16,0.271214,ROM CRC, 0x87 ,0.273162,Reset Pulse ,0.273673,Presence Pulse ,0.2741355,Search Rom Command, 0xF0 ,0.2747205,ROM Family Code, 0x23 ,0.2766535,ROM Code, 0x000000F0BCC3 ,0.2882255,ROM CRC, 0x71
     
    Today is a good day.

     
    Next on the list is the dreaded printf().
  14. Like
    zeke reacted to RobG in Using 3 wires to control parallel LCD display   
    Here's the code to read the keypad and then display 2 characters. Each key represents a bit, 1 is bit0, A bit4, D bit15, and by pressing multiple keys, you can display appropriate characters.
    More to come, maybe RPN calculator? Programmable power supply (I still have 3 inputs to measure voltage and current and I didn't get to ADC yet.)
     



    #include "msp430g2231.h" #define sendData(data) send(data, 1) #define sendInstruction(data) send(data, 0) #define initDisplay() sendInstruction(0x3C); sendInstruction(0x0C); clearDisplay(); sendInstruction(0x06) #define clearDisplay() sendInstruction(0x01); _delay_cycles(2000) #define DATAPIN BIT6 #define CLOCKPIN BIT5 #define ENABLEPIN BIT4 #define BIT0_3 0x0F void send(char data, char registerSelect); void sendDataArray(char data[], char length); char charIndex = 0; char bitCounter = 0; char charsToSend[2] = {0,0}; int keypadPrevState = 0; int keypadCurrState = 0; int keypadPress = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; _delay_cycles(100000); P1OUT &= ~(CLOCKPIN + DATAPIN); P1OUT |= ENABLEPIN; P1DIR |= ENABLEPIN + CLOCKPIN + DATAPIN; initDisplay(); P1REN |= BIT0_3; P1OUT |= BIT0_3; CCTL0 = CCIE; CCR0 = 6250; TACTL = TASSEL_2 + MC_1 + ID_3; _bis_SR_register(LPM0_bits + GIE); } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { keypadCurrState = 0; bitCounter = 0; P1OUT |= DATAPIN; while(bitCounter < 4) { P1OUT |= CLOCKPIN; P1OUT &= ~CLOCKPIN; bitCounter++; } bitCounter = 0; while(bitCounter < 4) { (bitCounter == 0) ? (P1OUT &= ~DATAPIN) : (P1OUT |= DATAPIN); P1OUT |= CLOCKPIN; P1OUT &= ~CLOCKPIN; bitCounter++; keypadCurrState <<= 4; keypadCurrState |= (0x000F & P1IN); } if(keypadCurrState != keypadPrevState) { clearDisplay(); charsToSend[0] = keypadCurrState & 0x00FF; charsToSend[1] = (keypadCurrState >> 8) & 0x00FF; sendDataArray(charsToSend, 2); } keypadPrevState = keypadCurrState; } void sendDataArray(char data[], char length) { charIndex = 0; while(charIndex < length) { sendData(data[charIndex]); charIndex++; } } void send(char data, char registerSelect) { //TODO may need to disable interrupt bitCounter = 0; while(bitCounter < 8) { (data & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN); data <<= 1; P1OUT |= CLOCKPIN; P1OUT &= ~CLOCKPIN; bitCounter++; } registerSelect ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN); P1OUT &= ~ENABLEPIN; P1OUT |= ENABLEPIN; //TODO may need to enable interrupt }
  15. Like
    zeke got a reaction from gatesphere in Using 3 wires to control parallel LCD display   
    Sorry for hijacking the topic...
     
    Mac, you're going to have to do a screencast of you making a drawing.
     
    I have to see this with my own eyes.
  16. Like
    zeke reacted to RobG in Using 3 wires to control parallel LCD display   
    I have seen this done other ways, but I didn't want to deal with 7 pins, or 4 bits, etc., so I did it my way.
    You send 8 bits to shift register, then set data out to whatever RS should be, and finally pulse E, that simple.
    I will add my code later, once I clean it up.
    BTW, if you are interested, the display is LMB162 and was purchased from ebay for $7.99 with free S/H to US of A (it took a week to get to NC.)
    It requires 3.3V Vcc with 5V BL, that's why I like it (well, I don't like the fact that I need separate power for BL.)
     


     

     
    My next step is to reduce number of required pins to 2 by adding missing pulse detector (555 I think will do well here.)

  17. Like
    zeke got a reaction from jsolarski in I stand in want to buy such a cat.   
    Holy CRAP! :shock:
     
    Is this post ever OFF topic!
     
    I propose that this user be punted for being so completely off topic that it's bewilderingly obvious that they are a spammer.
     
    Be gone with ye, Lover of Russian Blue Felines!
     
    This is the only cat we like around here:

  18. Like
    zeke got a reaction from Rei Vilo in Best information for those new to the MSP430?   
    If you are new to the MSP430 then you're probably drowning in information right now.

    It's true that there are a zillion configurations to make before the 430 will do what you want it do do.

    So I'm betting that you are asking yourself "Where do I start?"

    I humbly suggest the following TI application notes and books that will get you going in the right direction:

    1. slaa294: MSP430 Software Coding Techniques

    This application report covers software techniques and topics of interest to all MSP430
    programmers. The first part of the document discusses the MSP430 standard
    interrupt-based code flow model, recommended for the vast majority of applications.
    The next part discusses a handful of techniques that should be considered by any
    developer that sets out to develop an MSP430 application. Using these methods can
    greatly reduce debug time and/or provide additional robustness in the field. They
    include initialization procedures, validation of supply rails before performing
    voltage-sensitive operations, and use of special functions. Code examples are
    provided.

    2. : MSP430 32-kHz Crystal Oscillators

    Selection of the right crystal, correct load circuit, and proper board layout are important
    for a stable crystal oscillator. This application report summarizes crystal oscillator
    function and explains the parameters to select the correct crystal for MSP430
    ultralow-power operation. In addition, hints and examples for correct board layout are
    given. The document also contains detailed information on the possible oscillator tests
    to ensure stable oscillator operation in mass production.

    3. MSP430 Microcontroller Basics by John H. Davies

    The best thing I can say about this book at this time is that it describes well how to make use of the clocking system of the MSP430. This book should be in your personal library or at least on your wishlist.

    Once you digest the information above then you will be in good shape for success in working with the msp430.

    Have something to add?
    Then post up your valuable sources of knowledge.
  19. Like
    zeke reacted to bluehash in fatal error   
    It would help if you posted your code.
  20. Like
    zeke reacted to PhirePhly in [ ENDED ] April 2011 - 43oh Project of the Month Contest   
    Well someone's gotta be first:
     
    A basic battery-powered LCD clock. Tells time in 24 hour format through a 4 digit seven segment LCD. Two buttons for setting hour and minute. Running current is below 12uA, which means this thing is looking forward to a good 2.5 years running off a CR2032 coincell, like it is. With just the 100uF capacitor and no battery, it can run for more than 15 seconds, so even battery replacements can be done without loss of time, if you're fast enough.
     
    The display is wired to display full hexadecimal, so it can really be used for any project that needs a 4 digit LOW power display. A 20DIP MSP430 would probably help the power budget to a degree, removing the need for the shift register between the MSP430 and LCD driver. If only I had waited another month to build this one...


    Source code
     
    Full writeup with video and parts list
    LCDClock.c
  21. Like
    zeke got a reaction from GeekDoc in LCD-I2C For HD44780 LCDs and PCF8574 Expanders   
    It's obvious now.
     
    Change your board preferences back to "prosilver" and the thumbs will show up.
     
    @BlueHash: You should probably remove the choice of "Bl@ck" as a theme option.
     
    We should probably prune these theme questions off of this thread and put them into the non-existent "board issues" forum.
  22. Like
    zeke reacted to cde in Interface 3v MSP430 to 5v Circuits!   
    I know this was mentioned back in the day in the Parallex Sensor thread we had, but I'd figure this is a really useful document (That I just refound and was surprised by) that should be highlighted as this is one of the most common issues.
     
    TI's guide to Interfacing the 3v MSP430 to 5v Circuits.
    Document slaa148
    http://focus.ti.com/lit/an/slaa148/slaa148.pdf
     
    Covers both input and output, and dual direction communication of intervoltage circuits/ics.
     
    A bit dated (Oct 2002) so it doesn't include things like (active or passive) i2c or spi voltage translators but covers most of the useful steps/ideas in a beginner accessible way.
  23. Like
    zeke got a reaction from jsolarski in Are MSP430 wake up times clock source dependent?   
    If you do happen to use a 32kHz crystal, check out TI's App Note slaa322b.
     
    It goes into detail about how a crystal works, what will make it fail and how to design your circuit for optimal operation.
     
    It's a good one to bookmark.
  24. Like
    zeke got a reaction from vicvelcro in Best information for those new to the MSP430?   
    If you are new to the MSP430 then you're probably drowning in information right now.

    It's true that there are a zillion configurations to make before the 430 will do what you want it do do.

    So I'm betting that you are asking yourself "Where do I start?"

    I humbly suggest the following TI application notes and books that will get you going in the right direction:

    1. slaa294: MSP430 Software Coding Techniques

    This application report covers software techniques and topics of interest to all MSP430
    programmers. The first part of the document discusses the MSP430 standard
    interrupt-based code flow model, recommended for the vast majority of applications.
    The next part discusses a handful of techniques that should be considered by any
    developer that sets out to develop an MSP430 application. Using these methods can
    greatly reduce debug time and/or provide additional robustness in the field. They
    include initialization procedures, validation of supply rails before performing
    voltage-sensitive operations, and use of special functions. Code examples are
    provided.

    2. : MSP430 32-kHz Crystal Oscillators

    Selection of the right crystal, correct load circuit, and proper board layout are important
    for a stable crystal oscillator. This application report summarizes crystal oscillator
    function and explains the parameters to select the correct crystal for MSP430
    ultralow-power operation. In addition, hints and examples for correct board layout are
    given. The document also contains detailed information on the possible oscillator tests
    to ensure stable oscillator operation in mass production.

    3. MSP430 Microcontroller Basics by John H. Davies

    The best thing I can say about this book at this time is that it describes well how to make use of the clocking system of the MSP430. This book should be in your personal library or at least on your wishlist.

    Once you digest the information above then you will be in good shape for success in working with the msp430.

    Have something to add?
    Then post up your valuable sources of knowledge.
  25. Like
    zeke got a reaction from touch in Reading the ds18b20 temperature sensor   
    Since you have a ds18s20, the math for the temperature conversion is different.
     
    It's different because the bit resolution is 0.5'C per bit (9 bit mode). The ds18b20 is 0.125'C per bit (12 bit mode).
     
    If we adjust the conversion math then you'll get the correct results.
     
    First, add these to the top of your file:

    #define DS18B20 0x28 #define DS18S20 0x10
     
    Then adjust the temperature conversions procedure to this instead:

    if( ROMCode[7] == DS18B20 ) { Tc_100 = ( 6 * TReading ) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 } else if ( ROMCode[7] == DS18S20 ) { Tc_100 = ( 5 * TReading ); // multiply by (100 * 0.05) or 5 }
     
    It's not the best code since I assume it's one or the other sensor (not wise).
     
    The family code is derived from the LSByte of the ROM Code. In the case of my code, ROMCode[7].
     
    You could also do this:

    switch ( ROMCode[7] ) { case DS18B20: Tc_100 = ( 6 * TReading ) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 break; case DS18S20: Tc_100 = ( 5 * TReading ); // multiply by (100 * 0.05) or 5 break; default: Tc_100 = 0; break; }
     
    That will take care of the condition when you pull out your temp sensor while the unit is still running.
     
    What do you get now?
×
×
  • Create New...