Changeset e5dd493 in avrstuff


Ignore:
Timestamp:
Sep 8, 2019, 9:09:42 AM (5 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
c956fd4
Parents:
6f22754
Message:

usart: some cleanups.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libs/usart/usart.c

    r6f22754 re5dd493  
    88#endif
    99
    10 #ifdef __AVR_ATmega128__
    1110// FIXME there are two USARTs in this case and we should be able to drive either
    12 #define UBRRH UBRR0H
    13 #define UBRRL UBRR0L
    14 #define UCSRA UCSR0A
    15 #define UCSRC UCSR0C
    16 #define UCSRB UCSR0B
    17 #define UDR   UDR0
     11
     12// Compatibility for devices with single USART only
     13#ifdef __AVR_ATmega8__
     14#define UBRR0H UBRRH
     15#define UBRR0L UBRRL
     16#define UCSR0A UCSRA
     17#define UCSR0C UCSRC
     18#define UCSR0B UCSRB
     19#define UDR0   UDR
     20#define UDRE0  UDRE
     21#define RXC0   RXC
    1822#endif
    1923
    20 //This function is used to initialize the USART
    2124void USARTInit()
    2225{
     
    5154
    5255
    53 //This fuction writes the given "data" to
    54 //the USART which then transmit it via TX line
    5556void USARTWriteChar(char data)
    5657{
     
    6768
    6869
    69 //This function is used to read the available data
    70 //from USART. This function will wait untill data is
    71 //available.
    7270char USARTReadChar()
    7371{
  • libs/usart/usart.h

    r6f22754 re5dd493  
    11/* USART i/o library
    2  * Copyright 2010-2014, Adrien Destugues <pulkomandy@pulkomandy.tk>
     2 * Copyright 2010-2019, Adrien Destugues <pulkomandy@pulkomandy.tk>
    33 * Distributed under the terms of the MIT Licence */
    44
    5 #include <stdint.h>
     5/** Initialize the USART.
     6 *
     7 * Baudrate is set according to the BAUD define.
     8 * Currently the USART is set to 8N1, except on ATmega128 where it's set to 7E1
     9 * (don't ask why, I don't remember). This should be made configurable.
     10 *
     11 * On ATmega128, this always uses the first USART.
     12 */
     13void USARTInit();
    614
    7 void USARTInit();
     15/** Write a byte to the USART.
     16 *
     17 * This function blocks if the USART is not ready to accept any data. There is
     18 * no IO buffering.
     19 */
    820void USARTWriteChar(char data);
     21
     22/** Write an 8bit integer as hex to the USART.
     23 */
    924void USARTWriteHex(unsigned char i);
     25
     26/** This function is used to read the available data from USART.
     27 *
     28 * It waits untill data is available.
     29 */
     30char USARTReadChar();
  • test_uart/Makefile

    r6f22754 re5dd493  
     1MCU=atmega8
     2BAUD=57600
     3FCPU=16000000
     4PROG=avr109 -P /dev/ports/usb0 -b $(BAUD) -u
     5
    16testusart.hex: testusart.bin
    27        avr-objcopy -j .text -j .data -O ihex testusart.bin testusart.hex
    38
    49testusart.bin: usart.o main.o
    5         avr-gcc usart.o main.o -o testusart.bin -mmcu=atmega8 -Os
     10        avr-gcc usart.o main.o -o testusart.bin -mmcu=$(MCU) -Os
    611
    712main.o: testuart.c ../libs/usart/usart.h
    8         avr-gcc -c testuart.c -mmcu=atmega8 -Os -o main.o -mmcu=atmega8 -Os
     13        avr-gcc -c testuart.c -mmcu=$(MCU) -Os -o main.o
    914
    1015usart.o: ../libs/usart/usart.c ../libs/usart/usart.h
    11         avr-gcc -c ../libs/usart/usart.c -o usart.o -mmcu=atmega8 -Os
     16        avr-gcc -c ../libs/usart/usart.c -o usart.o -mmcu=$(MCU) -DBAUD=$(BAUD) -DF_CPU=$(FCPU) -Os
     17
     18flash: testusart.hex
     19        avrdude -c $(PROG) -p $(MCU) -Uflash:w:testusart.hex
     20
     21clean:
     22        rm *.bin *.o *.hex
  • test_uart/testuart.c

    r6f22754 re5dd493  
    33void main(void)
    44{
    5         USARTInit(51);
     5        USARTInit();
    66        USARTWriteChar('Z');
    77        while(1);
  • test_uart/testusart.hex

    r6f22754 re5dd493  
    22:1000100012C011C010C00FC00EC00DC00CC00BC06C
    33:100020000AC009C008C011241FBECFE5D4E0DEBF5E
    4 :10003000CDBF26D02BC0E4CF89B990BD86E880BD66
    5 :1000400088E18AB908955D9BFECF8CB908955F9BC6
    6 :10005000FECF8CB10895982F92959F709A3010F42E
    7 :10006000905D01C0995C5D9BFECF9CB98F708A301A
    8 :1000700010F4805D01C0895C5D9BFECF8CB9089552
    9 :1000800083E390E0D9DF8AE5DEDFFFCFF894FFCF8E
     4:10003000CDBF26D029C0E4CF10BC82E289B9599A3D
     5:1000400086E880BD88E18AB908955D9BFECF8CB9B2
     6:1000500008955F9BFECF8CB10895CF93C82F8295F2
     7:100060008F708A3048F4805DF0DF8C2F8F708A307B
     8:1000700028F4805DCF91E9CF895CF6CF895CFACF17
     9:0C008000DBDF8AE5E2DFFFCFF894FFCF62
    1010:00000001FF
Note: See TracChangeset for help on using the changeset viewer.