copy uart from atmega16 project
wont compile right now!
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
#ifndef _UART_H
|
#ifndef _UART_H_
|
||||||
#define _UART_H
|
#define _UART_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define BAUD 9600
|
#define BAUD 9600
|
||||||
#define MYUBRR F_CPU/16/BAUD-1
|
#define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)
|
||||||
|
|
||||||
void USART_Init(unsigned int ubrr);
|
void uart_init (void);
|
||||||
void USART_Transmit(unsigned char data );
|
void read_sync(char buffer[], uint8_t buffersize, uint8_t * bufferindex);
|
||||||
void uart_puts( char* string);
|
|
||||||
int putchar(int c);
|
|
||||||
void search_i2c_devices(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
MCU = atmega1284
|
MCU = atmega1284
|
||||||
TARGET = main
|
TARGET = main
|
||||||
AVRDUDE_PROGRAMMER = usbasp-clone
|
AVRDUDE_PROGRAMMER = atmelice_isp
|
||||||
FCPU=16000000L
|
FCPU=16000000L
|
||||||
|
|
||||||
BUILDDIR=build
|
BUILDDIR=build
|
||||||
@@ -45,7 +45,7 @@ CC = avr-gcc
|
|||||||
OBJCOPY = avr-objcopy
|
OBJCOPY = avr-objcopy
|
||||||
OBJDUMP = avr-objdump
|
OBJDUMP = avr-objdump
|
||||||
SIZE = avr-size
|
SIZE = avr-size
|
||||||
AVRDUDE = ./avrdude
|
AVRDUDE = avrdude
|
||||||
|
|
||||||
|
|
||||||
REMOVE = rm -f
|
REMOVE = rm -f
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
volatile int counter = 0;
|
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[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[18] = {'1','2','3','4','5','6','7','8','9','t','s','c','a','f','e',' ', ' ', ' '};
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int animationtimer = 0;
|
int animationtimer = 0;
|
||||||
int stringlength = 22;
|
int stringlength = 22;
|
||||||
@@ -34,8 +34,8 @@ int main(void){
|
|||||||
setup();
|
setup();
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
//putchar('c');
|
putchar('c');
|
||||||
//_delay_ms(50);
|
_delay_ms(50);
|
||||||
|
|
||||||
check_dip_switches();
|
check_dip_switches();
|
||||||
check_buttons();
|
check_buttons();
|
||||||
|
|||||||
100
code/src/uart.c
100
code/src/uart.c
@@ -1,87 +1,45 @@
|
|||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include "uart.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 */
|
UBRRH = (BAUDRATE>>8); // shift the register right by 8 bits
|
||||||
UBRR0H = ubrr>>8;
|
UBRRL = BAUDRATE; // set baud rate
|
||||||
UBRR0L = ubrr;
|
UCSRB|= (1<<TXEN)|(1<<RXEN)|(1<<RXCIE); // enable receiver and transmitter
|
||||||
/*Enable receiver and transmitter */
|
UCSRC|= (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); // 8bit data format
|
||||||
UCSR0B = (1<<TXEN0);
|
|
||||||
//| (1<<RXEN0)
|
stdout = &uart_output;
|
||||||
//|(1<<RXCIE0);
|
|
||||||
/* Set frame format: 8data, 1 stop bit */
|
|
||||||
UCSR0C = (1<<UCSZ00) | (1 << UCSZ01);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART_Transmit(unsigned char data )
|
static int uart_putchar(char c, FILE *stream) {
|
||||||
{
|
if (c == '\n') {
|
||||||
/* Wait for empty transmit buffer */
|
uart_putchar('\r', stream);
|
||||||
while ( !( UCSR0A & (1<<UDRE0)) )
|
|
||||||
;
|
|
||||||
/* Put data into buffer, sends the data */
|
|
||||||
UDR0 = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void uart_puts(char * str) {
|
|
||||||
while (*str) {
|
|
||||||
putchar(*str++);
|
|
||||||
}
|
}
|
||||||
}
|
loop_until_bit_is_set(UCSRA, UDRE);
|
||||||
|
UDR = c;
|
||||||
|
|
||||||
int putchar(int c){
|
|
||||||
USART_Transmit((char) c);
|
|
||||||
//while ( !( UCSR0A & (1<<UDRE0)) )
|
|
||||||
//UDR0 = c;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void read_sync(char buffer[], uint8_t buffersize, uint8_t * bufferindex){
|
||||||
void search_i2c_devices(){
|
for(int i=0; i < buffersize; i++){
|
||||||
char error, address;
|
buffer[i]=0;
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
else if (error == 4)
|
*bufferindex=0;
|
||||||
{
|
|
||||||
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
|
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');
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user