Hallo HaWe,
ich habe mich gleich ans Werk gemacht und den Code gekürzt das verhalten ist noch 1:1 das gleiche.
Schon mal vielen Dank, dass du dir den Quellcode an siehst und mir hilfst.
Wenn ich wüsste was hier bei der Lib an BAUD steht, könnte ich die ganze Lib auch noch ausbauenCode:#define MCU atmega8 #define F_CPU 2000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <inttypes.h> #include <stdlib.h> #include <stdio.h> #include "USART_RS232_H_file.h" /* include USART library */ #define BT_EN_REGISTER DDRC #define BT_EN_PORT PORTC #define BT_EN_PIN PC0 #define LED_REGISTER DDRC #define LED_PORT PORTC #define LED_RED_PIN PC5 #define LED_GREEN_PIN PC4 #define LED_BLUE_PIN PC3 //Data from App long pl_valid_time_sec = 0; uint8_t uart_getc(void){ while (!(UCSRA & (1<<RXC))){} // warten bis Zeichen verfuegbar return UDR; // Zeichen aus UDR an Aufrufer zurueckgeben } void uart_gets( char* Buffer, uint32_t MaxLen){ uint8_t NextChar; uint32_t StringLen = 0; NextChar = uart_getc(); // Warte auf und empfange das nächste Zeichen while( NextChar != '\n' && StringLen < MaxLen - 1 ) { // Sammle solange Zeichen, bis: entweder das String Ende Zeichen kam oder das aufnehmende Array voll ist *Buffer++ = NextChar; StringLen++; NextChar = uart_getc(); } *Buffer = '\0'; // Noch ein '\0' anhängen um einen Standard C-String daraus zu machen } void get_BTData(char mode){ char uart_buffer[512]; for(int i=0; i<4; i++){ LED_PORT ^= (1 << LED_BLUE_PIN); _delay_ms(500); } USART_Init(9600); /* initialize USART with 9600 baud rate */ LED_PORT |= (1<<LED_BLUE_PIN); uart_gets(uart_buffer,512); char spl_buffer[512]; spl_buffer[0] = '1'; spl_buffer[1] = '2'; spl_buffer[1] = '\0'; pl_valid_time_sec = atol(spl_buffer); _delay_ms(5000); LED_PORT &= ~(1<<LED_BLUE_PIN); } int main(void){ // Direction Registers DDRB = 0x00; // B as input DDRC = 0x00; // D as Input DDRD = 0x00; // D as Input // Set Output Registers BT_EN_REGISTER |= (1 << BT_EN_PIN); // Bluetooth PWR Controll LED_REGISTER |= (1 << LED_RED_PIN); // LED as output LED_REGISTER |= (1 << LED_GREEN_PIN); // LED as output LED_REGISTER |= (1 << LED_BLUE_PIN); // LED as output // Ports to LOW (GND no Pullup) PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; for (int i=0; i < 4; i++){ LED_PORT ^= (1 << LED_GREEN_PIN); _delay_ms(500); } get_BTData('I'); // INIT MODE while(1){ LED_PORT ^= (1 << LED_RED_PIN); _delay_ms(500); } }
Der ATMEGA läuft bei 2Mhz
Code:void USART_Init(unsigned long BAUDRATE) /* USART initialize function */ { UCSRB |= (1 << RXEN) | (1 << TXEN); /* Enable USART transmitter and receiver */ UCSRC |= (1 << URSEL)| (1 << UCSZ0) | (1 << UCSZ1); /* Write USCRC for 8 bit data and 1 stop bit */ UBRRL = BAUD_PRESCALE; /* Load UBRRL with lower 8 bit of prescale value */ UBRRH = (BAUD_PRESCALE >> 8); /* Load UBRRH with upper 8 bit of prescale value */ }







Zitieren

Lesezeichen