projects
/
goodfet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Arduino port is working, but only at 9600 baud.
[goodfet]
/
firmware
/
lib
/
atmega168.c
diff --git
a/firmware/lib/atmega168.c
b/firmware/lib/atmega168.c
index
36795fa
..
d8705ba
100644
(file)
--- a/
firmware/lib/atmega168.c
+++ b/
firmware/lib/atmega168.c
@@
-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;
}
+
+#define F_CPU 8000000L
+ //#define BAUD 115200L
+#define BAUD 9600L
+#include <util/setbaud.h>
+ UBRR0H = UBRRH_VALUE;
+ UBRR0L = UBRRL_VALUE;
+
+ UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
+ return;
+
}
//! Set the baud rate of the second uart.
}
//! Set the baud rate of the second uart.
@@
-68,22
+88,15
@@
void setbaud1(unsigned char rate){
}
}
-void msp430_init_uart0(){
+void avr_init_uart0(){
+ PORTD = _BV(PD2);
+ setbaud0(0);
+ _delay_ms(500); //takes a bit to stabilize
}
}
-void
msp430
_init_uart1(){
+void
avr
_init_uart1(){
}
}
-//! Initialization is correct.
-void msp430_init_dco_done(){
- //Nothing to do for the 1612.
-}
-
-
-void msp430_init_dco() {
-
-}
-