Arduino port is working, but only at 9600 baud.
[goodfet] / firmware / lib / atmega168.c
1 //! MSP430F1612/1611 clock and I/O definitions
2
3 #include "platform.h"
4
5 #include <avr/io.h>
6 #include <util/delay.h>
7
8 //! Receive a byte.
9 unsigned char serial0_rx(){
10   while( !(UCSR0A & (1 << RXC0)) );
11   return UDR0;
12 }
13
14 //! Receive a byte.
15 unsigned char serial1_rx(){
16   return 0;
17 }
18
19 //! Transmit a byte.
20 void serial0_tx(unsigned char x){
21   while (!(UCSR0A & (1<<UDRE0)) );
22   UDR0 = x;
23 }
24
25 //! Transmit a byte on the second UART.
26 void serial1_tx(unsigned char x){
27 }
28
29 //! Set the baud rate.
30 void setbaud0(unsigned char rate){
31   //TODO support multiple rates.
32   #define SPEED 9600
33   
34   
35   switch(rate){
36   case 1://9600 baud
37     
38     break;
39   case 2://19200 baud
40     
41     break;
42   case 3://38400 baud
43     
44     break;
45   case 4://57600 baud
46     
47     break;
48   default:
49   case 5://115200 baud
50     
51     break;
52   }
53   
54 #define F_CPU 8000000L
55   //#define BAUD 115200L
56 #define BAUD 9600L
57 #include <util/setbaud.h>
58   UBRR0H = UBRRH_VALUE;
59   UBRR0L = UBRRL_VALUE;
60   
61   UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
62   UCSR0B = _BV(RXEN0) | _BV(TXEN0);
63   return;
64   
65 }
66
67 //! Set the baud rate of the second uart.
68 void setbaud1(unsigned char rate){
69   //http://mspgcc.sourceforge.net/baudrate.html
70   switch(rate){
71   case 1://9600 baud
72     
73     break;
74   case 2://19200 baud
75     
76     break;
77   case 3://38400 baud
78     
79     break;
80   case 4://57600 baud
81     
82     break;
83   default:
84   case 5://115200 baud
85     
86     break;
87   }
88 }
89
90
91 void avr_init_uart0(){
92   PORTD = _BV(PD2);
93   setbaud0(0);
94   _delay_ms(500); //takes a bit to stabilize
95 }
96
97
98 void avr_init_uart1(){
99 }
100
101
102