Guten Tag, ich versuche mir einen eigene Libary zu erstellen aus einer .h Datei und einer .c Datei allerdings wenn ich diese ins Hauptprogramm einbinden will bekomme ich nach dem Compilieren eine Reihe von Fehlermeldungen. Könnte mir Bitte jemand sagen was ich hier verkehrt gemacht habe ? und Bitte nachsicht mit mir das ist meine erste Header Datei Nachfolgend .h Datei .c Datei -Hauptprogramm (einbinden) -Fehlerliste .h Datei
1 | #ifndef I2C_H
|
2 | #define I2C_H
|
3 | |
4 | #define START 0x08 // A START condition has been transmitted
|
5 | #define R_START 0x10 // A REPEATED START condition has been transmitted
|
6 | #define SLA_W 0xC0 // Slave Address & Write 1100 0000 A0 ist auf GND gelegt
|
7 | #define SLA_R 0xC1 // Slave Address & Read 1100 0001
|
8 | #define MT_SLA_ACK 0x18 // Master Transmit SLA + W has been transmitted & ACK has been received
|
9 | #define MT_DATA_ACK 0x0000 // Master Transmit Data byte has been transmitted & ACK has been received
|
10 | #define MR_SLA_ACK 0x40 // Master Receive SLA + R has been transmitted & ACK has been received
|
11 | #define MR_SLA_NACK 0x48 // Master Receive SLA + R has been transmitted & ACK has been received
|
12 | #define MR_DATA_ACK 0x50 // Master Receive Data byte has been transmitted & ACK has been returned
|
13 | #define MR_DATA_NACK 0x58 // Master Receive Data byte has been transmitted & NACK has been returned
|
14 | #define BIT_RATE 56 // Set value for the bit rate register TWBR
|
15 | |
16 | void ERROR(void); // Prototyping of function "ERROR" |
17 | |
18 | /*** Function to send a START Condition ***/
|
19 | void TWI_START(void); |
20 | |
21 | /*** Function to send the Slave Address with ACK in Master Transmit Mode ***/
|
22 | void TWI_MT_SLA_ACK(void); |
23 | |
24 | /*** Function to send 8Bit of data with ACK in Master Transmit Mode **/
|
25 | void TWI_MT_DATA_ACK(uint8_t data); |
26 | |
27 | /*** Function to send a REPEATED START condition **/
|
28 | void TWI_R_START(void); |
29 | |
30 | /*** Function to send the Slave Address in Master Receive Mode with Acknowledge **/
|
31 | void TWI_MR_SLA_ACK(void); |
32 | |
33 | /*** Function to send the Slave Address in Master Receive Mode without Acknowledge **/
|
34 | void TWI_MR_SLA_NACK(void); |
35 | |
36 | /*** Function to read one Databyte in Master Receive Mode and send NACK ***/
|
37 | uint8_t TWI_READ_DATABYTE_NACK(void); |
38 | |
39 | /*** Function to read one Databyte in Master Receive Mode and send ACK ***/
|
40 | uint8_t TWI_READ_DATABYTE_ACK(void); |
41 | |
42 | /*** function to send a STOP condition ***/
|
43 | void TWI_STOP(void); |
44 | |
45 | /*** function to show a bus error ***/
|
46 | void ERROR(void); |
47 | |
48 | #endif
|
.c Datei
1 | #include "I2C.h" |
2 | |
3 | |
4 | /*** Function to send a START Condition ***/
|
5 | void TWI_START(void) |
6 | {
|
7 | // Send a START condition
|
8 | TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); |
9 | // Wait for TWINT Flag set. This indicates that the START condition has been transmitted
|
10 | while (!(TWCR & (1<<TWINT))); |
11 | // Check value of TWI statusregister. Mask prescaler bits. If status different from START go to ERROR if ((TWSR & 0xF8) != START)
|
12 | ERROR(); |
13 | }
|
14 | |
15 | /*** Function to send the Slave Address with ACK in Master Transmit Mode ***/
|
16 | void TWI_MT_SLA_ACK(void) |
17 | {
|
18 | // Load Slave Address + Write into TWDR Register
|
19 | TWDR = SLA_W; |
20 | // Clear TWINT bit in TWCR to start transmission
|
21 | TWCR = (1<<TWINT) | (1<<TWEN); |
22 | // Wait for TWINT Flag set. This indicates that the SLA+W has been transmitted, and ACK/NACK has been received.
|
23 | while (!(TWCR & (1<<TWINT))); |
24 | // Check value of TWI status register. Mask prescaler bits. If status different from MT_SLA_ACK go to ERROR
|
25 | if ((TWSR & 0xF8) != MT_SLA_ACK) |
26 | ERROR(); |
27 | }
|
28 | |
29 | /*** Function to send 8Bit of data with ACK in Master Transmit Mode **/
|
30 | void TWI_MT_DATA_ACK(uint8_t data) |
31 | {
|
32 | // Load DATA into TWDR register
|
33 | TWDR = data; |
34 | // Clear TWINT bit in TWCR to start transmission
|
35 | TWCR = (1<<TWINT) | (1<<TWEN); |
36 | // Wait for TWINT flag set. This indicates that the DATA has been transmitted, and ACK/NACK has been received.
|
37 | while (!(TWCR & (1<<TWINT))); |
38 | // Check value of TWI status register. Mask prescaler bits. If status different from MT_DATA_ACK go to ERROR
|
39 | if ((TWSR & 0xF8) != MT_DATA_ACK) |
40 | ERROR(); |
41 | }
|
42 | |
43 | /*** Function to send a REPEATED START condition **/
|
44 | void TWI_R_START(void) |
45 | {
|
46 | // Send a START condition
|
47 | TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); |
48 | // Wait for TWINT Flag set. This indicates that the START condition has been transmitted
|
49 | while (!(TWCR & (1<<TWINT))); |
50 | // Check value of TWI statusregister. Mask prescaler bits. If status different from R_START go to ER-ROR
|
51 | if ((TWSR & 0xF8) != R_START) |
52 | ERROR(); |
53 | }
|
54 | |
55 | *** Function to send the Slave Address in Master Receive Mode with Acknowledge **/ |
56 | void TWI_MR_SLA_ACK(void) |
57 | {
|
58 | // Load Slave Address + Read into TWDR Register
|
59 | TWDR = SLA_R; |
60 | // Clear TWINT bit in TWCR to start transmission
|
61 | TWCR = (1<<TWINT) | (1<<TWEA) | (1<<TWEN); |
62 | // Wait for TWINT Flag set. This indicates that the SLA+W has been transmitted, and ACK/NACK has been received.
|
63 | while (!(TWCR & (1<<TWINT))); |
64 | // Check value of TWI status register. Mask prescaler bits. If status different from MR_SLA_ACK go to ERROR
|
65 | if ((TWSR & 0xF8) != MR_SLA_ACK) |
66 | ERROR(); |
67 | }
|
68 | |
69 | /*** Function to send the Slave Address in Master Receive Mode without Acknowledge **/
|
70 | void TWI_MR_SLA_NACK(void) |
71 | {
|
72 | // Load Slave Address + Read into TWDR Register
|
73 | TWDR = SLA_R; |
74 | // Clear TWINT bit in TWCR to start transmission
|
75 | TWCR = (1<<TWINT) | (1<<TWEN); |
76 | // Wait for TWINT Flag set. This indicates that the SLA+W has been transmitted, and ACK/NACK has been received.
|
77 | while (!(TWCR & (1<<TWINT))); |
78 | // Check value of TWI status register. Mask prescaler bits. If status different from MR_SLA_NACK go to ERROR
|
79 | if ((TWSR & 0xF8) != MR_SLA_NACK) |
80 | ERROR(); |
81 | }
|
82 | |
83 | /*** Function to read one Databyte in Master Receive Mode and send NACK ***/
|
84 | uint8_t TWI_READ_DATABYTE_NACK(void) |
85 | {
|
86 | // Clear TWINT bit in TWCR to start transmission with NACK
|
87 | TWCR = (1<<TWINT) | (1<<TWEN); |
88 | // Wait for TWINT flag set. This indicates that the DATA has been received
|
89 | while (!(TWCR & (1<<TWINT))); |
90 | // Check value of TWI status register. Mask prescaler bits. If status different from MR_SLA_NACK go to ERROR
|
91 | if ((TWSR & 0xF8) != MR_DATA_NACK) |
92 | ERROR(); |
93 | return TWDR; // Return the value of data register |
94 | }
|
95 | |
96 | /*** Function to read one Databyte in Master Receive Mode and send ACK ***/
|
97 | uint8_t TWI_READ_DATABYTE_ACK(void) |
98 | {
|
99 | // Clear TWINT bit in TWCR to start transmission with ACK
|
100 | TWCR = (1<<TWINT) | (1<<TWEA) | (1<<TWEN); |
101 | // Wait for TWINT flag set. This indicates that the DATA has been received
|
102 | while (!(TWCR & (1<<TWINT))); |
103 | // Check value of TWI status register. Mask prescaler bits. If status different from MR_SLA_ACK go to ERROR
|
104 | if ((TWSR & 0xF8) != MR_DATA_ACK) |
105 | ERROR(); |
106 | return TWDR; // Return the value of data register |
107 | }
|
108 | |
109 | /*** function to send a STOP condition ***/
|
110 | void TWI_STOP(void) |
111 | {
|
112 | TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO); // Transmit STOP condition |
113 | }
|
114 | |
115 | /*** function to show a bus error ***/
|
116 | void ERROR(void) |
117 | {
|
118 | PORTB |= (1<<PB1); // ERROR LED ON |
119 | }
|
Hauptprogramm
1 | /*
|
2 | * Header_Test.c
|
3 | *
|
4 | * Created: 01.03.2019 09:27:29
|
5 | * Author : USER
|
6 | */
|
7 | |
8 | #include <avr/io.h> |
9 | #include "I2C.h" |
10 | |
11 | |
12 | int main(void) |
13 | {
|
14 | /* Replace with your application code */
|
15 | while (1) |
16 | {
|
17 | }
|
18 | }
|
Fehlerliste
1 | Severity Code Description Project File Line |
2 | Error 'PB1' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 118 |
3 | Error 'PORTB' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 118 |
4 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 8 |
5 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 21 |
6 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 47 |
7 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 75 |
8 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 87 |
9 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 100 |
10 | Error 'TWCR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 112 |
11 | Error 'TWDR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 19 |
12 | Error 'TWDR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 73 |
13 | Error 'TWDR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 93 |
14 | Error 'TWDR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 106 |
15 | Error 'TWEA' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 100 |
16 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 8 |
17 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 21 |
18 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 47 |
19 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 75 |
20 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 87 |
21 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 100 |
22 | Error 'TWEN' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 112 |
23 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 8 |
24 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 21 |
25 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 47 |
26 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 75 |
27 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 87 |
28 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 100 |
29 | Error 'TWINT' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 112 |
30 | Error 'TWSR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 25 |
31 | Error 'TWSR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 51 |
32 | Error 'TWSR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 79 |
33 | Error 'TWSR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 91 |
34 | Error 'TWSR' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 104 |
35 | Error 'TWSTA' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 8 |
36 | Error 'TWSTA' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 47 |
37 | Error 'TWSTO' undeclared (first use in this function) Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 112 |
38 | Warning control reaches end of non-void function [-Wreturn-type] Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 94 |
39 | Warning control reaches end of non-void function [-Wreturn-type] Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 107 |
40 | Message each undeclared identifier is reported only once for each function it appears in Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 8 |
41 | Error expected '=', ',', ';', 'asm' or '__attribute__' before 'to' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 55 |
42 | Error recipe for target 'I2C.o' failed Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\Debug\Makefile 86 |
43 | Error unknown type name 'to' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 55 |
44 | Error unknown type name 'uint8_t' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 30 |
45 | Error unknown type name 'uint8_t' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 84 |
46 | Error unknown type name 'uint8_t' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.c 97 |
47 | Error unknown type name 'uint8_t' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.h 25 |
48 | Error unknown type name 'uint8_t' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.h 37 |
49 | Error unknown type name 'uint8_t' Header_Test c:\users\user\Documents\Atmel Studio\7.0\Header_Test\Header_Test\I2C.h 40 |
