AVR UARTs; not quite ready.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 17 Apr 2011 21:58:59 +0000 (21:58 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 17 Apr 2011 21:58:59 +0000 (21:58 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@997 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/include/msp430.h
firmware/lib/arduino.c
firmware/lib/atmega168.c

index 746ae51..d8d7c4d 100644 (file)
@@ -1,3 +1,4 @@
 
 
+
 void msp430_init();
 
 void msp430_init();
 
index 870f46e..503492c 100644 (file)
 void arduino_init(){
   /* set PORTB for output*/
   DDRB = 0xFF;
 void arduino_init(){
   /* set PORTB for output*/
   DDRB = 0xFF;
-
+  
+  /*
   while (1)
     {
   while (1)
     {
-      /* set PORTB.6 high */
+    //LED on
       PORTB = 0x20;
 
       _delay_ms(1000);
 
       PORTB = 0x20;
 
       _delay_ms(1000);
 
-      /* set PORTB.6 low */
+      //LED off
       PORTB = 0x00;
 
       _delay_ms(1000);
     }
       PORTB = 0x00;
 
       _delay_ms(1000);
     }
+*/
 }
 
 #endif
 }
 
 #endif
index 36795fa..1ed8840 100644 (file)
@@ -2,9 +2,13 @@
 
 #include "platform.h"
 
 
 #include "platform.h"
 
+#include <avr/io.h>
+#include <util/delay.h>
+
 //! Receive a byte.
 unsigned char serial0_rx(){
 //! Receive a byte.
 unsigned char serial0_rx(){
-  return 0;
+  while( !(UCSR0A & (1 << RXC0)) );
+  return UDR0;
 }
 
 //! Receive a byte.
 }
 
 //! Receive a byte.
@@ -14,6 +18,8 @@ unsigned char serial1_rx(){
 
 //! Transmit a byte.
 void serial0_tx(unsigned char x){
 
 //! Transmit a byte.
 void serial0_tx(unsigned char x){
+  while (!(UCSR0A & (1<<UDRE0)) );
+  UDR0 = x;
 }
 
 //! Transmit a byte on the second UART.
 }
 
 //! Transmit a byte on the second UART.
@@ -22,8 +28,10 @@ void serial1_tx(unsigned char x){
 
 //! Set the baud rate.
 void setbaud0(unsigned char rate){
 
 //! Set the baud rate.
 void setbaud0(unsigned char rate){
+  //TODO support multiple rates.
+  #define SPEED 9600
+  
   
   
-  //http://mspgcc.sourceforge.net/baudrate.html
   switch(rate){
   case 1://9600 baud
     
   switch(rate){
   case 1://9600 baud
     
@@ -42,6 +50,18 @@ void setbaud0(unsigned char rate){
     
     break;
   }
     
     break;
   }
+  
+  uint16_t bittimer=( F_CPU / SPEED / 16 ) - 1;
+  UBRR0H = (unsigned char) (bittimer >> 8);
+  UBRR0L = (unsigned char) bittimer;
+  
+  
+  /* set the framing to 8N1 */
+  UCSR0C = (3 << UCSZ00);
+  /* Engage! */
+  UCSR0B = (1 << RXEN0) | (1 << TXEN0);
+  return;
+  
 }
 
 //! Set the baud rate of the second uart.
 }
 
 //! Set the baud rate of the second uart.
@@ -79,11 +99,11 @@ void msp430_init_uart1(){
 
 //! Initialization is correct.
 void msp430_init_dco_done(){
 
 //! Initialization is correct.
 void msp430_init_dco_done(){
-  //Nothing to do for the 1612.
+  //Nothing to do for the AVR w/ xtal.
 }
 
 
 void msp430_init_dco() {
 }
 
 
 void msp430_init_dco() {
-
+  //
 }
 
 }