Jump to content
43oh

Receive only uart?


Recommended Posts

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?

Link to post
Share on other sites
  • 2 weeks later...

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

Link to post
Share on other sites

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);
}
//==============================================================================

Link to post
Share on other sites
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...