Compare commits

...

2 Commits

2 changed files with 17 additions and 20 deletions

View File

@ -4,10 +4,6 @@
* Description: Small library to handle Serial communication on AVR micros
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include "avr_usart.h"
@ -25,8 +21,8 @@ int demo() {
//enable interrupts
sei();
unsigned char data[8] = "AT+BAUD3";
unsigned char data_cmd[2] = "AT";
char data[8] = "AT+BAUD3";
char data_cmd[2] = "AT";
uint8_t data_len = 8;
uint8_t data_cmd_len = 2;
@ -86,7 +82,7 @@ void init_usart0(void) {
* Output: None
* Description: Sends a char over usart0
*/
void tx_usart0(unsigned char data) {
void tx_usart0(char data) {
//first wait for the transmit buffer to be empty
while(!(UCSR0A & (1<<UDRE0))) {
;//Equiv of continue
@ -103,7 +99,7 @@ void tx_usart0(unsigned char data) {
* Output: a 8bit char
* Description: Recvs a char over usart0
*/
unsigned char rx_usart0(void) {
char rx_usart0(void) {
//first wait for the data to be received.
while( !(UCSR0A & (1<<RXC0)) ) {
;//Equiv of continue
@ -136,7 +132,7 @@ void serial0_enable_timeouts(uint8_t ms) {
* Output: None
* Description:
*/
void serial0_write(unsigned char* buffer, uint8_t write_length) {
void serial0_write(char* buffer, uint8_t write_length) {
for(uint8_t i = 0; i < write_length; i++) {
tx_usart0(buffer[i]);
}
@ -199,7 +195,7 @@ void serial0_set_stop_bits(uint8_t number) {
* Output: None
* Description: Reads the serial data into a buffer of x length.
*/
void serial0_read(unsigned char* buffer, uint8_t buf_length) {
void serial0_read(char* buffer, uint8_t buf_length) {
//clear buffer out?
//buffer = 0;
for(uint8_t i = 0; i < buf_length; i++) {

View File

@ -7,6 +7,9 @@
//#define __AVR_ATmega328P__
#include <inttypes.h>
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
//#############################
//PIN DEFINES AND CONSTS
@ -24,10 +27,6 @@
#define F_CPU 14745600UL
#endif
#ifndef BUAD
#define BAUD 4800
#endif
#define F_UBRR ((F_CPU)/(BAUD*16UL)-1)
#define TX_PIN PIND1
@ -48,8 +47,10 @@
//#############################
#define USE_U2X 0
#define CARRIAGE_RETURN 1
#define LINE_FEED 1
//#define CARRIAGE_RETURN 1
//#define LINE_FEED 1
#define DEBUG 1
#if DEBUG == 1
#define debug(data, data_len) serial0_write(data, data_len)
@ -61,11 +62,11 @@
//FUNCTION PROTOTYPES
//#############################
void init_usart0(void);
void tx_usart0(unsigned char data);
unsigned char rx_usart0(void);
void tx_usart0( char data);
char rx_usart0(void);
void serial0_write(unsigned char* buffer, uint8_t write_length);
void serial0_read(unsigned char* buffer, uint8_t buf_length);
void serial0_write( char* buffer, uint8_t write_length);
void serial0_read( char* buffer, uint8_t buf_length);
void serial0_set_baud(uint8_t baud);
void seiral0_enable_timeouts(uint8_t ms);
void serial0_flush_rxbuf(void);