cde 334 Posted October 29, 2010 Share Posted October 29, 2010 So I tested out my i2c explorer with proper wires, and another part (Eeprom, can read, and can write the page address, but can't write to the eeprom. It's either write protected, or I fried it from a voltage/soldering issue. Hmm.) Works great on the i2c pcf8574a port expander. Been using it to get a hd44780/ks900su lcd working (it does!), and plan on releasing a msp430-i2c lcd backpack. Problem is that the MSP430G2231 has only 2k of usable code space. The i2c explorer clocks in at 1940bytes, so I can't add more to it (IAR is giving me issues writing more than 1950 bytes btw.). So, I was thinking of ways to cut down on code, and the only thing I can think of is turning the UART into a RX only one. Except I can't figure out how to chop up NJC's code in half. If we can, then we would have TX only, RX only, and TX&RX uarts, a complete set for any project! Any help? Quote Link to post Share on other sites
jsolarski 94 Posted November 1, 2010 Share Posted November 1, 2010 It should be possible to split the RX and TX, i wanted to do that for awhile since i only need one or the other for most of my projects . but shouldnt be too hard to do, but then again i havent looked at NJC's code for quite a bit Quote Link to post Share on other sites
JMLB 24 Posted November 15, 2010 Share Posted November 15, 2010 Try some thing like this #include "msp430g2231.h" #define RXD BIT2 // TXD on P1.1 #define Bitime 104 //9600 Baud, SMCLK=1MHz (1MHz/9600)=104 #define Bitime_5 (Bitime/2) unsigned char BitCnt; // Bit count, used when transmitting byte unsigned int RXTXData; // Value sent over UART when Transmit() is called void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT unsigned int uartUpdateTimer = 10; // Loops until byte is sent unsigned int i = 0; // Transmit value counter BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz P1SEL |= RXD; // __bis_SR_register(GIE); // interrupts enabled\ /* Main Application Loop */ while(1) { BitCnt = 0x8; // Load Bit counter CCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Cap _BIS_SR(LPM3_bits + GIE); //wait for byte you can remove LPM3_bits if you don't want it to sleep } } // Timer A0 interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { if( CCTL0 & CAP ) // Capture mode = start bit edge { CCTL0 &= ~ CAP; // Switch from capture to compare mode CCR0 += Bitime_5; } else { RXTXData = RXTXData >> 1; if (CCTL0 & SCCI) // Get bit waiting in receive latch RXTXData |= 0x80; BitCnt --; // All bits RXed? if ( BitCnt == 0) //>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< { CCTL0 &= ~ CCIE; // All bits RXed, disable interrupt _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) } //>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< } } This was based off the TI example and the example provided here http://www.msp430launchpad.com/2010/07/ ... -open.html I didn't test this but I will tomorrow if you like Quote Link to post Share on other sites
bluehash 1,581 Posted November 15, 2010 Share Posted November 15, 2010 Did you try cutting out on parsing code? Also, are there alot of printfs? Try creating your own printf rather than using the built in one. Quote Link to post Share on other sites
OCY 19 Posted November 19, 2010 Share Posted November 19, 2010 I wrote 4 little procedures. You can cut them down easily. For example, you may not need "set_baud" nor "auto_baud". And you may only need "getchar" or "putchar". /******************************************************************************* * Sub-Standard I/O for LaunchPad Board * * OCY Nov 2010 * *******************************************************************************/ #include #define RXD BIT2 #define TXD BIT1 int baud_divider = 104; /* default for 9600 b/s @ SMCLK = 1 MHz */ //============================================================================== int set_baud ( int i ) { baud_divider = i; return (i); } //============================================================================== int auto_baud ( void ) { __no_init int zero; P1SEL |= RXD; TACCTL0 = 0; TACCTL1 = CM_2 | SCS | CAP; TACTL = TASSEL_2 | MC_2 | TACLR; while ((TACCTL1 & CCIFG) == 0) {/* wait */} zero = TACCR1; TACCTL1 = CM_1 | SCS | CAP; while ((TACCTL1 & CCIFG) == 0) {/* wait */} P1SEL &= ~RXD; TACTL = 0; return (baud_divider = TACCR1 - zero); } //============================================================================== int putchar ( int i ) { TACCR0 = 0; TACCTL0 = OUT; TACCTL1 = 0; P1SEL |= TXD; P1DIR |= TXD; TACTL = TASSEL_2 | MC_2 | TACLR; i = (i + 0x100) << 1; do { TACCR0 += baud_divider; if (i & 1) TACCTL0 = OUTMOD_1; else TACCTL0 = OUTMOD_5; while ((TACCTL0 & CCIFG) == 0) {/* wait */} } while ((i = (i >> 1)) != 0); P1DIR &= ~TXD; P1SEL &= ~TXD; TACTL = 0; return 1; }//============================================================================= int getchar ( void ) { int byte = 0; P1SEL |= RXD; TACCTL0 = 0; TACCTL1 = CM_2 | SCS | CAP; TACTL = TASSEL_2 | MC_2 | TACLR; while ((TACCTL1 & CCIFG) == 0) {/* wait */} TACCR1 += baud_divider >> 1; for (int bit = 8; bit > 0; bit--) { TACCR1 += baud_divider; TACCTL1 = 0; while ((TACCTL1 & CCIFG) == 0) {/* wait */} if (TACCTL1 & CCI) byte |= 0x100; byte = byte >> 1; } P1SEL &= ~RXD; TACTL = 0; return (byte); } //============================================================================== bluehash and gatesphere 2 Quote Link to post Share on other sites
simpleavr 399 Posted November 19, 2010 Share Posted November 19, 2010 make sense, who needs all those interrupt handlers (from the ti example, etc) when u still have to wait for it to complete one byte. i've got to try this and see how much program space i can save. thanks. Quote Link to post Share on other sites
NJC 17 Posted December 6, 2010 Share Posted December 6, 2010 Sorry I missed out on the thread. Just wanted to make sure you got everything figured out. If not I can cut out the transmit part of the code for you. Let me know. 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.