Hallo zusammen,
ich bin gerade dabei einen Software-UART auf einem ATTiny13 zu
implementieren. Das ist mein Code dazu:
1 |
|
2 | #ifndef F_CPU
|
3 | #define F_CPU 9600000
|
4 | #endif
|
5 |
|
6 | #include <avr/io.h>
|
7 | #include <util/delay.h>
|
8 | #include <string.h>
|
9 |
|
10 | void uart_send(uint8_t * bit_folge, uint8_t * anz) //Das geht nicht
|
11 | {
|
12 | uint8_t j;
|
13 |
|
14 | for(j=0; j<(*anz); j++)
|
15 | {
|
16 | if (bit_folge[j] == 1)
|
17 | {
|
18 | PORTB |= (1 << PB0);
|
19 | }
|
20 | else
|
21 | {
|
22 | PORTB &= ~(1 << PB0);
|
23 | }
|
24 | _delay_us(104);
|
25 | }
|
26 | }
|
27 |
|
28 | void prepare_data(char * text, uint8_t * bit_folge, uint8_t * anz)
|
29 | {
|
30 | uint8_t i = 0;
|
31 | uint8_t j;
|
32 | uint8_t send;
|
33 |
|
34 |
|
35 | while (text[i] != 0)
|
36 | {
|
37 | bit_folge[(*anz)] = 0; //Start-Bit
|
38 |
|
39 | for (j = 0; j < 8; j++)
|
40 | {
|
41 | (*anz)++;
|
42 | send = text[i];
|
43 | send &= (1 << j);
|
44 |
|
45 | if (send != 0) bit_folge[(*anz)] = 1; //Daten-Bits
|
46 | else bit_folge[(*anz)] = 0;
|
47 |
|
48 | }
|
49 |
|
50 | (*anz)++;
|
51 | bit_folge[(*anz)] = 1; //Stop-Bit
|
52 | (*anz)++;
|
53 | i++;
|
54 | }
|
55 | }
|
56 |
|
57 | int main (void)
|
58 | {
|
59 | char text[250];
|
60 | uint8_t bit_folge[250];
|
61 | uint8_t anz = 0;
|
62 | //uint8_t j;
|
63 |
|
64 | DDRB |= (1<<PB0);
|
65 | PORTB |= (1 << PB0);
|
66 |
|
67 | strcpy(text, "AA");
|
68 | prepare_data(text, bit_folge, &anz);
|
69 |
|
70 | /* ****** Das geht ******
|
71 | for(j=0; j<anz; j++)
|
72 | {
|
73 | if (bit_folge[j] == 1)
|
74 | {
|
75 | PORTB |= (1 << PB0);
|
76 | }
|
77 | else
|
78 | {
|
79 | PORTB &= ~(1 << PB0);
|
80 | }
|
81 | _delay_us(104);
|
82 | }*/
|
83 |
|
84 | uart_send(bit_folge, &anz); //Das geht nicht
|
85 | while(1)
|
86 | {
|
87 |
|
88 | }
|
89 |
|
90 |
|
91 | return 0;
|
92 | }
|
Das Problem ist nun wenn ich die Bits in der Main rausschicke
funktioniert alles wunderbar (auskommentiert), sende ich die Bits
allerdings über die Funktion "uart_send" werden nur 7 Bits versendet.
Ich kann mir leider keinen Reim darauf machen, warum das Senden über die
Funktion nicht funktioniert. Über Tipps würde ich mich sehr freuen, ich
bin am verzweifeln.
Danke schonmal, Grüße
Andy