Hallo zusammen,
ich beschäftige mich zur Zeit mit der tinyAVR 1-Serie und scheitere am
UART. Wenn ich mir mein Projekt in Atmel Start zusammenstelle
funktioniert der UART, aber wenn ich folgendes Programm verwende geht
dieser nicht:
1 | #define F_CPU 3333333
|
2 | #define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
|
3 |
|
4 | #include <avr/io.h>
|
5 | #include <util/delay.h>
|
6 | #include <stdio.h>
|
7 |
|
8 | static void USART0_sendChar(char c)
|
9 | {
|
10 | while (!(USART0.STATUS & USART_DREIF_bm))
|
11 | {
|
12 | ;
|
13 | }
|
14 | USART0.TXDATAL = c;
|
15 | }
|
16 |
|
17 | static int USART0_printChar(char c, FILE *stream)
|
18 | {
|
19 | USART0_sendChar(c);
|
20 | return 0;
|
21 | }
|
22 |
|
23 | static FILE USART_stream = FDEV_SETUP_STREAM(USART0_printChar, NULL, _FDEV_SETUP_WRITE);
|
24 |
|
25 | static void USART0_init(void)
|
26 | {
|
27 | PORTA.DIR |= PIN1_bm;
|
28 | USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);
|
29 | USART0.CTRLB |= USART_TXEN_bm;
|
30 | stdout = &USART_stream;
|
31 | }
|
32 |
|
33 | int main(void)
|
34 | {
|
35 | uint8_t count = 0;
|
36 | USART0_init();
|
37 | PORTB.DIR |= PIN5_bm;
|
38 |
|
39 | while (1)
|
40 | {
|
41 | printf("Counter value is: %d\n\r", count++);
|
42 | _delay_ms(250);
|
43 | PORTB.OUTTGL = PIN5_bm;
|
44 | }
|
45 | }
|
Diesen Code habe ich aus der Getting Started von Microchip und habe den
Pin für den TX angepasst. Getestet wird der Code auf dem ATtiny416-XNANO
Board. Vielleicht kann mir jemand helfen.
Viele Dank.