Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Created September 30, 2011 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/1254043 to your computer and use it in GitHub Desktop.
Save RickKimball/1254043 to your computer and use it in GitHub Desktop.
AAAReadme.txt
I came across this article a while back but hadn't had a chance to play with it.
http://www.msp430launchpad.com/2010/08/using-usi-as-uart.html
Armed with a Sparkfun FTDI FT232R breakout board, linux, msp430-gcc and an msp430g2452
I put the code below on it and was able to use putty connected @ 2000000 bps to send
data to my linux box. The bit duration is a blazing 500ns wow!
Hmm .. interesting
//******************************************************************************
//
// Description: Continuously sends a counter value over the USI in SPI which
// acting as if it were a UART. The sample circuit connects an
// FTDI breakout board to the transmit line and reads. The baud
// rate is determined by the USI speed, which in this case is
// 2000000 baud (DCO = 16MHz).
//
// Nicholas J. Conn
// 08-04-2010
// Built with CCS Version: 4.1.3
// 09-15-2011 Rick Kimball changed to 2MBit and msp430g2452
//
//******************************************************************************
#include "msp430.h"
// Function Definitions
void transmit(unsigned int);
int main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
/* use precalibrated 16MHz value */
DCOCTL = 0;
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
//****************************
// Set up USI - LSB first
//****************************
USICTL0 |= USIPE6 + USIMST + USILSB + USIOE; // Enable Output, SPI master, LSB first
USICTL1 |= USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_3 | USISSEL_3; // Use SMCLK/8
USICTL0 &= ~USISWRST; // USI released for operation
//*******************************************************
// Set initial program varibles and start peripherals
//*******************************************************
unsigned int i = 0;
unsigned int TXData;
const char *buffer = "Hello world 2000k baud\r\n";
while(1)
{
for(i=0; buffer[i] ; i++ ) {
// transmit(0x55);
transmit(buffer[i]);
}
}
}
// Transmits one byte (TXData) using the USI as a UART
void transmit( unsigned int TXData )
{
//**********************************************
// Send a byte on the USI as if it were UART
//**********************************************
TXData = TXData << 1; // Add start bit
TXData |= 0xFE00; // Add stop bit
while (!(USIIFG & USICTL1)); // Wait if USI is busy
USISR = TXData; // Sets word to be sent
USICNT = USI16B + 10; // 16 bit mode, sends 10 bits
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment