Compare commits
2 Commits
8d4fee5c7e
...
200dd58c44
Author | SHA1 | Date |
---|---|---|
Jake Goodwin | 200dd58c44 | |
Jake Goodwin | a702c52327 |
|
@ -4,10 +4,6 @@
|
||||||
* Description: Small library to handle Serial communication on AVR micros
|
* 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"
|
#include "avr_usart.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +21,8 @@ int demo() {
|
||||||
|
|
||||||
//enable interrupts
|
//enable interrupts
|
||||||
sei();
|
sei();
|
||||||
unsigned char data[8] = "AT+BAUD3";
|
char data[8] = "AT+BAUD3";
|
||||||
unsigned char data_cmd[2] = "AT";
|
char data_cmd[2] = "AT";
|
||||||
uint8_t data_len = 8;
|
uint8_t data_len = 8;
|
||||||
uint8_t data_cmd_len = 2;
|
uint8_t data_cmd_len = 2;
|
||||||
|
|
||||||
|
@ -86,7 +82,7 @@ void init_usart0(void) {
|
||||||
* Output: None
|
* Output: None
|
||||||
* Description: Sends a char over usart0
|
* 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
|
//first wait for the transmit buffer to be empty
|
||||||
while(!(UCSR0A & (1<<UDRE0))) {
|
while(!(UCSR0A & (1<<UDRE0))) {
|
||||||
;//Equiv of continue
|
;//Equiv of continue
|
||||||
|
@ -103,7 +99,7 @@ void tx_usart0(unsigned char data) {
|
||||||
* Output: a 8bit char
|
* Output: a 8bit char
|
||||||
* Description: Recvs a char over usart0
|
* Description: Recvs a char over usart0
|
||||||
*/
|
*/
|
||||||
unsigned char rx_usart0(void) {
|
char rx_usart0(void) {
|
||||||
//first wait for the data to be received.
|
//first wait for the data to be received.
|
||||||
while( !(UCSR0A & (1<<RXC0)) ) {
|
while( !(UCSR0A & (1<<RXC0)) ) {
|
||||||
;//Equiv of continue
|
;//Equiv of continue
|
||||||
|
@ -136,7 +132,7 @@ void serial0_enable_timeouts(uint8_t ms) {
|
||||||
* Output: None
|
* Output: None
|
||||||
* Description:
|
* 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++) {
|
for(uint8_t i = 0; i < write_length; i++) {
|
||||||
tx_usart0(buffer[i]);
|
tx_usart0(buffer[i]);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +195,7 @@ void serial0_set_stop_bits(uint8_t number) {
|
||||||
* Output: None
|
* Output: None
|
||||||
* Description: Reads the serial data into a buffer of x length.
|
* 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?
|
//clear buffer out?
|
||||||
//buffer = 0;
|
//buffer = 0;
|
||||||
for(uint8_t i = 0; i < buf_length; i++) {
|
for(uint8_t i = 0; i < buf_length; i++) {
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
//#define __AVR_ATmega328P__
|
//#define __AVR_ATmega328P__
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
//#############################
|
//#############################
|
||||||
//PIN DEFINES AND CONSTS
|
//PIN DEFINES AND CONSTS
|
||||||
|
@ -24,10 +27,6 @@
|
||||||
#define F_CPU 14745600UL
|
#define F_CPU 14745600UL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BUAD
|
|
||||||
#define BAUD 4800
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define F_UBRR ((F_CPU)/(BAUD*16UL)-1)
|
#define F_UBRR ((F_CPU)/(BAUD*16UL)-1)
|
||||||
|
|
||||||
#define TX_PIN PIND1
|
#define TX_PIN PIND1
|
||||||
|
@ -48,8 +47,10 @@
|
||||||
//#############################
|
//#############################
|
||||||
|
|
||||||
#define USE_U2X 0
|
#define USE_U2X 0
|
||||||
#define CARRIAGE_RETURN 1
|
//#define CARRIAGE_RETURN 1
|
||||||
#define LINE_FEED 1
|
//#define LINE_FEED 1
|
||||||
|
|
||||||
|
#define DEBUG 1
|
||||||
|
|
||||||
#if DEBUG == 1
|
#if DEBUG == 1
|
||||||
#define debug(data, data_len) serial0_write(data, data_len)
|
#define debug(data, data_len) serial0_write(data, data_len)
|
||||||
|
@ -61,11 +62,11 @@
|
||||||
//FUNCTION PROTOTYPES
|
//FUNCTION PROTOTYPES
|
||||||
//#############################
|
//#############################
|
||||||
void init_usart0(void);
|
void init_usart0(void);
|
||||||
void tx_usart0(unsigned char data);
|
void tx_usart0( char data);
|
||||||
unsigned char rx_usart0(void);
|
char rx_usart0(void);
|
||||||
|
|
||||||
void serial0_write(unsigned char* buffer, uint8_t write_length);
|
void serial0_write( char* buffer, uint8_t write_length);
|
||||||
void serial0_read(unsigned char* buffer, uint8_t buf_length);
|
void serial0_read( char* buffer, uint8_t buf_length);
|
||||||
void serial0_set_baud(uint8_t baud);
|
void serial0_set_baud(uint8_t baud);
|
||||||
void seiral0_enable_timeouts(uint8_t ms);
|
void seiral0_enable_timeouts(uint8_t ms);
|
||||||
void serial0_flush_rxbuf(void);
|
void serial0_flush_rxbuf(void);
|
||||||
|
|
Loading…
Reference in New Issue