Compare commits
No commits in common. "200dd58c4405661684c242e7ac9ce4fc49c35046" and "8d4fee5c7e7ac030cc2cced0e929bebe072e2f5b" have entirely different histories.
200dd58c44
...
8d4fee5c7e
2 changed files with 20 additions and 17 deletions
|
@ -4,6 +4,10 @@
|
|||
* 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"
|
||||
|
||||
|
||||
|
@ -21,8 +25,8 @@ int demo() {
|
|||
|
||||
//enable interrupts
|
||||
sei();
|
||||
char data[8] = "AT+BAUD3";
|
||||
char data_cmd[2] = "AT";
|
||||
unsigned char data[8] = "AT+BAUD3";
|
||||
unsigned char data_cmd[2] = "AT";
|
||||
uint8_t data_len = 8;
|
||||
uint8_t data_cmd_len = 2;
|
||||
|
||||
|
@ -82,7 +86,7 @@ void init_usart0(void) {
|
|||
* Output: None
|
||||
* Description: Sends a char over usart0
|
||||
*/
|
||||
void tx_usart0(char data) {
|
||||
void tx_usart0(unsigned char data) {
|
||||
//first wait for the transmit buffer to be empty
|
||||
while(!(UCSR0A & (1<<UDRE0))) {
|
||||
;//Equiv of continue
|
||||
|
@ -99,7 +103,7 @@ void tx_usart0(char data) {
|
|||
* Output: a 8bit char
|
||||
* Description: Recvs a char over usart0
|
||||
*/
|
||||
char rx_usart0(void) {
|
||||
unsigned char rx_usart0(void) {
|
||||
//first wait for the data to be received.
|
||||
while( !(UCSR0A & (1<<RXC0)) ) {
|
||||
;//Equiv of continue
|
||||
|
@ -132,7 +136,7 @@ void serial0_enable_timeouts(uint8_t ms) {
|
|||
* Output: None
|
||||
* Description:
|
||||
*/
|
||||
void serial0_write(char* buffer, uint8_t write_length) {
|
||||
void serial0_write(unsigned char* buffer, uint8_t write_length) {
|
||||
for(uint8_t i = 0; i < write_length; i++) {
|
||||
tx_usart0(buffer[i]);
|
||||
}
|
||||
|
@ -195,7 +199,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(char* buffer, uint8_t buf_length) {
|
||||
void serial0_read(unsigned char* buffer, uint8_t buf_length) {
|
||||
//clear buffer out?
|
||||
//buffer = 0;
|
||||
for(uint8_t i = 0; i < buf_length; i++) {
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
//#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
|
||||
|
@ -27,6 +24,10 @@
|
|||
#define F_CPU 14745600UL
|
||||
#endif
|
||||
|
||||
#ifndef BUAD
|
||||
#define BAUD 4800
|
||||
#endif
|
||||
|
||||
#define F_UBRR ((F_CPU)/(BAUD*16UL)-1)
|
||||
|
||||
#define TX_PIN PIND1
|
||||
|
@ -47,10 +48,8 @@
|
|||
//#############################
|
||||
|
||||
#define USE_U2X 0
|
||||
//#define CARRIAGE_RETURN 1
|
||||
//#define LINE_FEED 1
|
||||
|
||||
#define DEBUG 1
|
||||
#define CARRIAGE_RETURN 1
|
||||
#define LINE_FEED 1
|
||||
|
||||
#if DEBUG == 1
|
||||
#define debug(data, data_len) serial0_write(data, data_len)
|
||||
|
@ -62,11 +61,11 @@
|
|||
//FUNCTION PROTOTYPES
|
||||
//#############################
|
||||
void init_usart0(void);
|
||||
void tx_usart0( char data);
|
||||
char rx_usart0(void);
|
||||
void tx_usart0(unsigned char data);
|
||||
unsigned char rx_usart0(void);
|
||||
|
||||
void serial0_write( char* buffer, uint8_t write_length);
|
||||
void serial0_read( char* buffer, uint8_t buf_length);
|
||||
void serial0_write(unsigned char* buffer, uint8_t write_length);
|
||||
void serial0_read(unsigned 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue