Hallo ihr Experten! Ich hab ein Problem mit der Übergabe eines Pointers:
1 | void TWI_Start_Transceiver_With_Data( unsigned char *msg, unsigned char msgSize) |
2 | {
|
3 | |
4 | /*Write address and data */
|
5 | do
|
6 | {
|
7 | /* Write a byte */
|
8 | PORTB &=~(1<<SCL); // Pull SCL low |
9 | USIDR = *(msg++); // Setup data |
10 | TWI_Master_Transfer(tempUSISR_8bit); // Send 8 bits on bus |
11 | |
12 | /* Clock and verify (N)ACK from slave */
|
13 | DDRB &=~(1<<SDA); // Enable SDA as input |
14 | if(TWI_Master_Transfer(tempUSISR_1bit) & 0x01) |
15 | {
|
16 | // NACK
|
17 | }
|
18 | }while( --msgSize); |
19 | }
|
... wird aufgerufen von...
1 | #include <avr/io.h> |
2 | #include <avr/interrupt.h> |
3 | #include <stdint.h> |
4 | #include "TWI_Master.h" |
5 | |
6 | volatile uint8_t newuartdata; |
7 | volatile unsigned char uartin; |
8 | |
9 | ////////////////////////////////////////////////////////////////////////////////////////
|
10 | // Hauptprogramm
|
11 | ////////////////////////////////////////////////////////////////////////////////////////
|
12 | |
13 | int main (void) |
14 | {
|
15 | cli(); |
16 | // Initialisierungen
|
17 | Ports_Init(); |
18 | Uart_Init(); |
19 | TWI_Master_Init(); |
20 | |
21 | sei(); |
22 | // Hauptschleife
|
23 | while(1){ |
24 | if(newuartdata){ |
25 | newuartdata = 0; |
26 | TWI_Start_Transceiver_With_Data((unsigned char)uartin,1); |
27 | }
|
28 | }
|
29 | return 0; |
30 | }
|
31 | |
32 | ////////////////////////////////////////////////////////////////////////////////////////
|
33 | // Interrupt Service Routinen
|
34 | ////////////////////////////////////////////////////////////////////////////////////////
|
35 | |
36 | ISR(USART_RX_vect){ |
37 | uartin = UDR; |
38 | newuartdata = 1; |
39 | }
|
Nun das Problem: wenn ich "uartin" mit einem Inhalt von zB 0x02 übergebe ist der Inhalt von "USIDR" dann immernoch der alte. Wo liegt der Fehler? MfG Marc