Hallo zusammen,
Ich habe ein kleines Board mit einem Atmega8, dieses soll über ein
HC12-Funkmodul ein paar Bytes verschicken.
Der UART gibt jedoch nichts raus, bzw der TX-Pin (D1) bleibt '0' / 0V.
Eventuell habe ich ihn falsch konfiguriert oder nutze ihn falsch.
Sehe aber leider kein Problem.
Eventuell habt ihr eine Idee dazu, mit den FUSES scheine ich dass wohl
nicht beeinflussen zu können...
Dazu habe ich folgenden Code:
Zuerst die Konfiguration:
1 | void UART_FT232_Init()
|
2 | {
|
3 | /*
|
4 | UCSRA-Config Atmega8
|
5 | 7654 3210
|
6 | 0010 0000 = Reset-Config
|
7 | |||| |||-MPCM R/W Enable multi processor communication
|
8 | |||| ||--U2X R/W Double the Speed in async Communication
|
9 | |||| |---PE R Parity Error in receive byte detected
|
10 | |||| ----DOR R Data-Overrun received new Start bit bevore old receive buffer byte was read
|
11 | |||- ----FE R Frame error received (See datasheet)
|
12 | ||-- ----UDRE R Transmit buffer ready to receive new data
|
13 | |--- ----TXC R/W All data transmitted, receive buffer is empty
|
14 | ---- ----RXC R New data in receive Buffer / Cleared when data is read
|
15 | --> NO CHANGE NEEDED
|
16 |
|
17 | UCSRB-Config Atmega8
|
18 | 7654 3210
|
19 | 0000 0000 = Reset-Config
|
20 | |||| |||-TXB8 R/W 9th databit to be Transmitted
|
21 | |||| ||--RXB8 R Nineth data bit received
|
22 | |||| |---UCSZ2 R/W Set number of Data-Bits = 0 for 8Bits
|
23 | |||| ----TXEN R/W Enables UART-Transmitter
|
24 | |||- ----RXEN R/W Enables UART-Receiver
|
25 | ||-- ----UDRIE R/W Enables Interrupt on UDRE-Flag on UCSRA
|
26 | |--- ----TXCIE R/W TX-Complete interrupt enable
|
27 | ---- ----RXCIE R/W RX-Complete interrupt enable
|
28 |
|
29 | UCSRB=0xB8 = USED-Config
|
30 | 1011 1000
|
31 | |||| |||-TXB8 R/W 9th databit to be Transmitted
|
32 | |||| ||--RXB8 R Nineth data bit received
|
33 | |||| |---UCSZ2 R/W Set number of Data-Bits = 0 for 8Bits
|
34 | |||| ----TXEN R/W Enables UART-Transmitter
|
35 | |||- ----RXEN R/W Enables UART-Receiver
|
36 | ||-- ----UDRIE R/W Enables Interrupt on UDRE-Flag on UCSRA
|
37 | |--- ----TXCIE R/W TX-Complete interrupt enable
|
38 | ---- ----RXCIE R/W RX-Complete interrupt enable
|
39 |
|
40 | UCSRC-Config Atmega8
|
41 | 7654 3210
|
42 | 1000 0110 = RESET-Config = USED-Config
|
43 | |||| |||-UCPOL R/W Only for Sync-Mode relevant
|
44 | |||| ||--UCSZ0 R/W 1 = 8-Bit Mode
|
45 | |||| |---UCSZ1 R/W 1 = 8-Bit Mode
|
46 | |||| ----USBS R/W 0 = 1-Stop-Bit / 1 = 2-Stop-Bits
|
47 | |||- ----UPM0 R/W 00 = Parity Disabled
|
48 | ||-- ----UPM1 R/W 10 = Even-parity / 11 = Odd-Parity
|
49 | |--- ----UMSEL R/W 0 = Async-Opertaion / 1 = Sync-Operation
|
50 | ---- ----URSEL R/W R/W MUST BE 1 WHEN WRITING TO UCSRC
|
51 | */
|
52 | UCSRB=0xB8; //RX/TX-Enable, IRQ-Enable
|
53 | UCSRC=0x86; //8Bit, Kein Parity, ein Stop
|
54 | UBRRH=0x00;
|
55 | UBRRL=0x33; // Baud-Rate @8MHz = 1200Baud
|
56 | }
|
Hier meine RX/TX-Funktionen welche auf anderen Boards laufen:
1 | void UART_FT232_PutC(char data)
|
2 | {
|
3 | while(TxWrite != TxRead); // Warte bis Platz im Puffer
|
4 | TxBuff[TxWrite++] = data;
|
5 | if(TxWrite >= 255) TxWrite = 0;
|
6 | UCSRB |= (1<<UDRIE); // UDRE Interrupt ein
|
7 | }
|
8 |
|
9 | char* UART_FT232_GetRec(uint16_t *len)
|
10 | {
|
11 | char* pointer; //Rückgabe der Aktuellen Addresse
|
12 | UCSRB &= ~(1<<RXCIE); //Disable RX-IRQ
|
13 | *len = RxLen; //return actual length of readable bytes
|
14 | RxLen=0; //Length of readable Bytes = 0
|
15 | uint8_t RxRead_buff=RxRead; //Get last Read-Addr, wich beginns with 1. Byte, that has not been Read last Time
|
16 | RxRead=RxWrite; //Set actual rx-Addr to wr-Addr --> 0 Bytes in Buffer
|
17 | UCSRB |= (1<<RXCIE); //Enable RX-IRQ
|
18 | return pointer = &RxBuff[RxRead_buff]; //Return Pointer to 1. Readable Byte
|
19 | }
|
20 |
|
21 | ISR(USART_RXC_vect) //Wartet auf ein erstes Zeichen des PC's
|
22 | {
|
23 | UCSRB &= ~(1<<RXCIE);
|
24 | RxBuff[RxWrite++] = UDR;
|
25 | if(RxWrite >= 255 ) RxWrite = 0;
|
26 | RxLen=RxLen + 1;
|
27 | UCSRB |= (1<<RXCIE);
|
28 | }
|
29 |
|
30 | ISR(USART_UDRE_vect)
|
31 | {
|
32 | if(TxRead == TxWrite) UCSRB &= ~(1<<UDRIE); // UDRE Interrupt aus
|
33 | else {
|
34 | UDR = TxBuff[TxRead++]; // nächtes Zeichen aus Puffer senden
|
35 | if(TxRead >= 255) TxRead = 0;
|
36 | }
|
37 | }
|
Dann gibts da noch die Port-Konfig des uc:
1 | void InitUC()
|
2 | {
|
3 | DDRB = 0x00;
|
4 | //Programmier-Interface
|
5 | //DS18B20(PB0)
|
6 | //DS18B20(PB1)
|
7 | //DS18B20(PB2)
|
8 | DDRC = 0x07;
|
9 | //FUNK-SET (PC0-->OUT)
|
10 | //FUNK-PWR (PC1-->OUT)
|
11 | //PUMP-PWR (PC2-->OUT)
|
12 | //DS18B20 (PC3)
|
13 | //I2C (PC4 / PC5)
|
14 | DDRD = 0xFE;
|
15 | //FUNK-RXD(PD0-->IN)
|
16 | //FUNK-TXD(PD1-->OUT)
|
17 | //DISP-D4 (PD2-->OUT)
|
18 | //DISP-D5 (PD3-->OUT)
|
19 | //DIPS-D6 (PD4-->OUT)
|
20 | //DISP-D7 (PD5-->OUT)
|
21 | //DISP-RS (PD6-->OUT)
|
22 | //DISP-E (PD7-->OUT)
|
23 |
|
24 | //DDR --> LOW --> INPUT
|
25 | //DDR --> HIGH--> OUTPUT
|
26 |
|
27 | //PORT--> LOW --> if output --> LOW
|
28 | // if INPUT --> PULLUP-OFF
|
29 | //PORT--> HIGH--> if output --> HIGH
|
30 | // if INPUT --> PULLUP-ON
|
31 | //PULL-UP has 20-50KOHMs
|
32 |
|
33 | PORTB = 0x00; //
|
34 | PORTC = 0x00; //
|
35 | PORTD = 0x00; //
|
36 |
|
37 | sei(); //Global IRQ-Enable
|
38 | }
|
Grüße und Vielen Dank wäre prima wenn jemand das Problem evtl auf die
schnelle sieht...
Matthias