Hallo Zusammen,
Ich bin dabei, den ATmega328p µC mittels Atmel Studio zu programmieren,
verwende dabei das Arduino Uno Board.
Mit der Arduino IDE funktioniert alles einwandfrei -> LED geht an/aus je
nach empfangenem Zeichen
In Atmel Studio 6.0 leider nicht. Nachdem das Programm auf den µC
rübergespielt wird, wird das Bluetooth Modul vom Smartphone gefunden,
jedoch gibt die LED keine Reaktion.
Einfache Programme wie Blinky oder Taster funktionieren jedoch, hängt
also an der seriellen Kommunikation?
SoftwareSerial.cpp wurde über den Solution Explorer hinzugefügt und
unter Toolchain > AVR/GNU C++ Compiler > Directories den SoftwareSerial
Ordner hinzugefügt zu den Libraries.
Wo kann also das Problem liegen?
LG
1 | #include <Arduino.h>
|
2 | #include <avr/delay.h>
|
3 | #include <SoftwareSerial.h> //Software Serial Port
|
4 |
|
5 | #define FOSC 16000000 // 16MHz
|
6 | #define BAUD 9600 // Baudrate 9600
|
7 | #define BRC FOSC/16/BAUD-1 // Prescaler
|
8 |
|
9 | #define DEBUG_ENABLED 1
|
10 |
|
11 | SoftwareSerial blueToothSerial(PORTD6,PORTD7);
|
12 |
|
13 | void setupBlueToothConnection()
|
14 | {
|
15 | blueToothSerial.begin(38400); // Set BluetoothBee BaudRate to default baud rate 38400
|
16 | blueToothSerial.print("\r\n+STWMOD=0\r\n"); // set the bluetooth work in slave mode
|
17 | blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); // set the bluetooth name as "SeeedBTSlave"
|
18 | blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
|
19 | blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
|
20 | delay(2000); // This delay is required.
|
21 | blueToothSerial.print("\r\n+INQ=1\r\n"); // make the slave bluetooth inquirable
|
22 | Serial.println("The slave bluetooth is inquirable!");
|
23 | delay(2000); // This delay is required.
|
24 | blueToothSerial.flush();
|
25 | }
|
26 | void setup() // setup uart communication & IN/OUT pins
|
27 | {
|
28 | UBRR0H = (BRC>>8); // set baudrate
|
29 | UBRR0L = BRC;
|
30 |
|
31 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1<<RXCIE0); // Enable receive-enable and transmit-enable and receive-interrupt-enable
|
32 | UCSR0A = (1 << UDRE0); //richtiger Empfang ansonsten nur mit BAUD 19200 bei Terminal möglich
|
33 | UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // Set frame: 8 bit data
|
34 |
|
35 | DDRB |= (1 << PORTB0);
|
36 | DDRD |= (1 << PORTD7);
|
37 | DDRD &= ~(1 << PORTD6);
|
38 |
|
39 | setupBlueToothConnection();
|
40 | }
|
41 | void loop()
|
42 | {
|
43 | char c;
|
44 |
|
45 | while(1)
|
46 | {
|
47 | if(blueToothSerial.available())
|
48 | {
|
49 | c = blueToothSerial.read();
|
50 | Serial.print(c);
|
51 |
|
52 | if(c == '1')
|
53 | {
|
54 | //LEDON();
|
55 | PORTB |= (1<<PORTB0);
|
56 | }
|
57 | else if(c == '0')
|
58 | {
|
59 | //LEDOFF();
|
60 | PORTB &= ~(1<<PORTB0);
|
61 | }
|
62 | }
|
63 | }
|
64 | }
|