Changeset 109


Ignore:
Timestamp:
29/07/2014 22:37:15 (4 years ago)
Author:
pulkomandy
Message:

Make libusart aware of attiny2313.

Location:
libs/usart
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libs/usart/usart.c

    r1 r109  
    44#include <inttypes.h>
    55
     6#ifndef BAUD
     7        #error You must define BAUD to use libuart.
     8#endif
    69
    710//This function is used to initialize the USART
    8 //at a given UBRR value
    9 void USARTInit(uint16_t ubrr_value)
     11void USARTInit()
    1012{
     13        //Set Baud rate
     14        #include <util/setbaud.h>
     15        UBRRH = UBRRH_VALUE;
     16        UBRRL = UBRRL_VALUE;
     17        #if USE_2X
     18                UCSRA |= (1 << U2X);
     19        #else
     20                UCSRA &= ~(1 << U2X);
     21        #endif
    1122
    12    //Set Baud rate
    13    UBRRL = ubrr_value;
    14    UBRRH = (ubrr_value>>8);
     23        /*Set Frame Format
     24          >> Asynchronous mode
     25          >> No Parity
     26          >> 1 StopBit
     27          >> char size 8
     28          */
     29#ifdef __AVR_ATtiny2313__
     30        UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
     31#else
     32        UCSRC = (1 << URSEL) | (3 << UCSZ0);
     33#endif
    1534
    16    /*Set Frame Format
    17 
    18 
    19    >> Asynchronous mode
    20    >> No Parity
    21    >> 1 StopBit
    22    >> char size 8
    23 
    24    */
    25 
    26    UCSRC=(1<<URSEL)|(3<<UCSZ0);
    27 
    28    //Enable The receiver and transmitter
    29    UCSRB=(1<<RXEN)|(1<<TXEN);
     35        //Enable The receiver and transmitter
     36        UCSRB = (1 << RXEN) | (1 << TXEN);
    3037}
    3138
  • libs/usart/usart.h

    r8 r109  
    11/* USART i/o library
    2  * Copyright 2010, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
     2 * Copyright 2010-2014, Adrien Destugues <pulkomandy@pulkomandy.tk>
    33 * Distributed under the terms of the MIT Licence */
    44
    55#include <stdint.h>
    66
    7 void USARTInit(uint16_t ubrr_value);
     7void USARTInit();
    88void USARTWriteChar(char data);
    99void USARTWriteHex(unsigned char i);
Note: See TracChangeset for help on using the changeset viewer.