The msp430f2013 does not have UART ports. So I found that a software UART can be created and I followed the code from J H Davies book. As I have mentioned in the question, i am basically trying to interface a GSM modem to the MSP. My question are'
- Is it possible to do this on a software UART?
- Once I have compiled the software UART program, how do I check it? Can I do this on Hyperterminal or putty?
I have read the various discussions on this forum about software UART but my doubt is not cleared.
The code i used for software UART is below.
#include // Header file for this device #include // Integers of defined sizes #include "uartlib.h" // Library for software UART #define LED P1OUT_bit.P1OUT_0 // Output pin for LED (active high) uint8_t RXBUF; // Buffer for received byte uint8_t TXBUF; // Buffer for byte to transmit#define BITTIME ((1000000 +
4800)/9600) // Cycles of TACLK per bit , 1MHz#define HALFTIME (BITTIME/2) // Cycles for half a bit void UARTSetUp ( void ) { TACTL = TASSEL_2 | MC_2; // TACLK = SMCLK = 1MHz TACCTL0 = OUT | OUTMOD_0 | CCIFG; TACCTL1 = CM_2 | CCIS_1 | SCS | CAP | OUTMOD_0 | CCIE; RXIFG = 0; // Buffer empty , no byte received TXIFG = 1; // Buffer empty , ready to accept TX } //---------------------------------------------------------------------- // Write byte to TXBUF; clears flag , starts transmitter if necessary //---------------------------------------------------------------------- void WriteTXBUF ( const uint8_t TXData) { TXBUF = TXData; // Transfer data to buffer TXIFG = 0; // Clear interrupt flag TACCTL0_bit. CCIE = 1; // Enable interrupts if inactive , } // no effect if already running //---------------------------------------------------------------------- // Read byte from RXBUF; clears flag //---------------------------------------------------------------------- uint8_t ReadRXBUF ( void ) { RXIFG = 0; // Clear interrupt flag return RXBUF; // Read data from buffer } //---------------------------------------------------------------------- // ISR for Timer_A2 , channel 0: transmission //---------------------------------------------------------------------- #pragma vector = TIMERA0_VECTOR _ _interrupt void TIMERA0_ISR ( void ) // Acknowledged automatically { static uint8_t TXBitCount = 0; // Count bits transmitted static uint16_t TXShiftReg; // Shift register for transmission LED = 1; // Show start of activity if (TXBitCount == 0) { // Ready to start new byte if (TXIFG == 0) { // Byte available to transmit TXShiftReg = TXBUF; // Load data from buffer TXShiftReg |= BIT8; // Add stop bit after msb TXIFG = 1; // Show that buffer is available TXBitCount = 9; // Number of bits including stop bit TACCR0 = TAR + BITTIME; // Delay until start of start bit TACCTL0 = OUTMOD_5 | CCIE; // Clr output on compare for ST } else { // No data available , shut down TACCTL0 = OUT | OUTMOD_0 | CCIFG; // Idle: output high , } // disable interrupt , set flag for int 'pt when reenabled } else { // Send next bit if (TXShiftReg & BIT0) { // Send 1 next TACCTL0 = OUTMOD_1 | CCIE; // Set output on compare } else { // Send 0 next TACCTL0 = OUTMOD_5 | CCIE; // Clear output on compare } TACCR0 += BITTIME; // Delay until next bit TXShiftReg >>= 1; // Shift right , remove lsb
--TXBitCount; // Update bit counter } LED = 0; // Show end of activity } //---------------------------------------------------------------------- // ISR for Timer_A2 , channel 1 and timer core ( inactive): reception //---------------------------------------------------------------------- #pragma vector = TIMERA1_VECTOR _ _interrupt void TIMERA1_ISR ( void ) // NOT acknowledged automatically { static uint8_t RXBitCount = 0; // Count bits received static uint8_t RXShiftReg; // Shift register for reception LED = 1; // Show start of activity TACCTL1_bit. CCIFG = 0; // Acknowledge interrupt , clear flag if (TACCTL1_bit.CAP) { // Capture mode , start bit detected TACCTL1_bit.CAP = 0; // Switch to sampling (compare ) mode TACCR1 += HALFTIME; // Wait for half a bit time RXBitCount = 9; // Bits to receive including ST, SP } else { switch (RXBitCount) { case 9: // Start bit if (TACCTL1_bit. SCCI) { // Error: start bit should be low TACCTL1_bit.CAP = 1; // Abandon reception } else { // Correct: proceed to receive data TACCR1 += BITTIME; // Wait for complete bit time
--RXBitCount; // Update bit counter } break ; case 0: // Stop bit if (TACCTL1_bit. SCCI) { // Correct: stop bit should be high RXBUF = RXShiftReg; // Store data into buffer RXIFG = 1; // Raise flag to show new data } // (discard byte if stop bit low) TACCTL1_bit.CAP = 1; // Return to capture mode break ; default : // Data bit (lsb first), cases 1-8 RXShiftReg >>= 1; // Shift data , clear msb for new bit if (TACCTL1_bit. SCCI) { RXShiftReg |= BIT7; // Set received bit if high } TACCR1 += BITTIME; // Wait for complete bit time
--RXBitCount; // Update bit counter break ; } } LED = 0; // Show end of activity }
--------------------------------------- Posted through