copy uart from atmega16 project

wont compile right now!
master
Eggert Jung 6 years ago
parent d1bbac33f9
commit 1c08382936

@ -1,13 +1,13 @@
#ifndef _UART_H
#define _UART_H
#ifndef _UART_H_
#define _UART_H_
#include <stdio.h>
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
#define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)
void USART_Init(unsigned int ubrr);
void USART_Transmit(unsigned char data );
void uart_puts( char* string);
int putchar(int c);
void search_i2c_devices(void);
void uart_init (void);
void read_sync(char buffer[], uint8_t buffersize, uint8_t * bufferindex);
#endif

@ -1,6 +1,6 @@
MCU = atmega1284
TARGET = main
AVRDUDE_PROGRAMMER = usbasp-clone
AVRDUDE_PROGRAMMER = atmelice_isp
FCPU=16000000L
BUILDDIR=build
@ -45,7 +45,7 @@ CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = ./avrdude
AVRDUDE = avrdude
REMOVE = rm -f

@ -17,8 +17,8 @@
*/
volatile int counter = 0;
char text[22] = {'F','R','o','h','e',' ',' ','W','e','i','h','n','a','c','h','t','e', 'n', ' ',' ', ' ', ' '};
//char text[18] = {'1','2','3','4','5','6','7','8','9','t','s','c','a','f','e',' ', ' ', ' '};
//char text[22] = {'F','R','o','h','e',' ',' ','W','e','i','h','n','a','c','h','t','e', 'n', ' ',' ', ' ', ' '};
char text[18] = {'1','2','3','4','5','6','7','8','9','t','s','c','a','f','e',' ', ' ', ' '};
int offset = 0;
int animationtimer = 0;
int stringlength = 22;
@ -34,8 +34,8 @@ int main(void){
setup();
while(1){
//putchar('c');
//_delay_ms(50);
putchar('c');
_delay_ms(50);
check_dip_switches();
check_buttons();

@ -1,87 +1,45 @@
#include <avr/io.h>
#include "uart.h"
static int uart_putchar(char c, FILE *stream);
FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
void USART_Init(unsigned int ubrr)
void uart_init ()
{
/*Set baud rate */
UBRR0H = ubrr>>8;
UBRR0L = ubrr;
/*Enable receiver and transmitter */
UCSR0B = (1<<TXEN0);
//| (1<<RXEN0)
//|(1<<RXCIE0);
/* Set frame format: 8data, 1 stop bit */
UCSR0C = (1<<UCSZ00) | (1 << UCSZ01);
}
UBRRH = (BAUDRATE>>8); // shift the register right by 8 bits
UBRRL = BAUDRATE; // set baud rate
UCSRB|= (1<<TXEN)|(1<<RXEN)|(1<<RXCIE); // enable receiver and transmitter
UCSRC|= (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); // 8bit data format
void USART_Transmit(unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) )
;
/* Put data into buffer, sends the data */
UDR0 = data;
stdout = &uart_output;
}
void uart_puts(char * str) {
while (*str) {
putchar(*str++);
static int uart_putchar(char c, FILE *stream) {
if (c == '\n') {
uart_putchar('\r', stream);
}
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
}
int putchar(int c){
USART_Transmit((char) c);
//while ( !( UCSR0A & (1<<UDRE0)) )
//UDR0 = c;
return 0;
}
/*
void search_i2c_devices(){
char error, address;
int nDevices;
uart_puts("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ )
{
uart_puts("\n");
uart_puts("Scanning...");
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
i2c_start_wait(address);
error = i2c_readNak();
if (error == 0)
{
uart_puts("I2C device found at address 0x");
if (address < 16)
uart_puts("0");
uart_puts(address);
uart_puts(" !");
nDevices++;
void read_sync(char buffer[], uint8_t buffersize, uint8_t * bufferindex){
for(int i=0; i < buffersize; i++){
buffer[i]=0;
}
else if (error == 4)
{
uart_puts("Unknown error at address 0x");
if (address < 16)
uart_puts("0");
uart_puts(address);
}
}
if (nDevices == 0)
uart_puts("No I2C devices found\n");
else
uart_puts("done\n");
// delay(); // wait 5 seconds for next scan
*bufferindex=0;
char input;
do{
while ((UCSRA & (1 << RXC)) == 0);
input = UDR;
putchar(input); //echo
buffer[*bufferindex]=input;
*bufferindex=*bufferindex+1;
}while(!(input == '\n' || input == '\r'));
buffer[*bufferindex]=0;
putchar('\n');
}
*/

Loading…
Cancel
Save