Forum: Mikrocontroller und Digitale Elektronik Problem mit PIC und Bluetoothmodul


von Manusi (Gast)


Lesenswert?

Hallo!!

Seit Wochen versuch ich mich an einer eigenen Schaltung.
Ich arbeite mit einem PIC18F45K20 und einem BlueMod  Modul von Stollman.
(Das ganze programmier ich mit MPLAB und dem C18.Compiler)
Ziel ist es dass ich über den PIC eine Zeichenkette abschicke und die 
dann über Bluetooth empfangen werden kann (das ganze kann ich über ein 
Terminal beobachten)
Leider funktioniert GAR NICHTS.
Der BlueMod nimmt nichteinmal meine Befehle auf. Zwar kann ich den 
BlueMod auf dem PC sehen und mich mit ihm verbinden, doch funktioniert 
das rein zufällig. Alle Befehle den ich an ihn schicke werden gar nicht 
aufgenommen.
Ich hab schon mir alles erdenkliche ausprobiert.
Anbei schick ich meinen Code.

Als erstes hab ich es über I2C versucht:
1
/** C O N F I G U R A T I O N   B I T S ******************************/
2
3
#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF                      // CONFIG1H
4
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30                       // CONFIG2L
5
#pragma config WDTEN = OFF, WDTPS = 32768                                   // CONFIG2H
6
#pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC      // CONFIG3H
7
#pragma config STVREN = ON, LVP = OFF, XINST = OFF                          // CONFIG4L
8
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF                   // CONFIG5L
9
#pragma config CPB = OFF, CPD = OFF                                         // CONFIG5H#pragma config EBTRB = OFF                                                  // CONFIG7H
10
11
12
#include <p18f45k20.h>
13
#include <sw_i2c.h>
14
#include <delays.h>
15
#include <stdio.h>
16
#include <sw_uart.h>
17
#include <usart.h>
18
19
#define  DATA_LOW   TRISCbits.TRISC4 = 0; // define macro for data pin output
20
#define  DATA_HI    TRISCbits.TRISC4 = 1; // define macro for data pin input
21
#define  DATA_LAT   LATCbits.LATC4        // define macro for data pin latch
22
#define  DATA_PIN   PORTCbits.RC4         // define macro for data pin
23
24
#define  CLOCK_LOW  TRISCbits.TRISC3 = 0; // define macro for clock pin output
25
#define  CLOCK_HI   TRISCbits.TRISC3 = 1; // define macro for clock pin input
26
#define  SCLK_LAT   LATCbits.LATC3        // define macro for clock pin latch
27
#define  SCLK_PIN   PORTCbits.RC3         // define macro for clock pin0
28
29
30
unsigned char result;
31
32
33
#pragma code
34
void main(void)
35
{
36
37
//get current address
38
SWStartI2C();
39
SWPutcI2C( 0xA1 );
40
SWAckI2C();
41
printf("" + SWAckI2C());
42
SWGetcI2C();
43
SWStopI2C();
44
45
  //make BlueMod visible + settings
46
SWStartI2C();
47
SWPutcI2C("ATS301=BlueMod+B20");  //Anzeigenahme = BlueMod+B20
48
SWRestartI2C();
49
SWPutcI2C("ATS350=SPP");      //Local Service Name for SPP: SPP
50
SWRestartI2C();
51
SWPutcI2C("ATS323=9600");      //Set baud rate to 9600 bps
52
SWRestartI2C();
53
SWPutcI2C("ATS324=8");        //Use 8 data bits
54
SWRestartI2C();
55
SWPutcI2C("ATS325=1");        //One stop bit
56
SWRestartI2C();
57
SWPutcI2C("ATS326=0");        //No parity
58
SWRestartI2C();
59
SWPutcI2C("ATS316=3");        //Page scan and inquiry scan are enabled; the BlueMod+B2x is connectable and discoverable
60
SWStopI2C();
61
62
63
  //Connection-Profil
64
  SWStartI2C();
65
  SWPutcI2C("ATA");        //Accept incomming call
66
  SWRestartI2C();
67
  SWPutcI2C("AT&C0");        //DCD always on
68
  SWRestartI2C();
69
  SWPutcI2C("ATS319=1");      //Authentication for Incoming Connections
70
  SWStopI2C();
71
72
  //send string "Hallo"
73
  SWStartI2C();
74
SWPutcI2C("Hallo");
75
  SWStopI2C();
76
77
}






Und dann auch über UART:

1
/** C O N F I G U R A T I O N   B I T S ******************************/
2
3
#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF                      // CONFIG1H
4
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30                       // CONFIG2L
5
#pragma config WDTEN = OFF, WDTPS = 32768                                   // CONFIG2H
6
#pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC      // CONFIG3H
7
#pragma config STVREN = ON, LVP = OFF, XINST = OFF                          // CONFIG4L
8
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF                   // CONFIG5L
9
#pragma config CPB = OFF, CPD = OFF                                         // CONFIG5H#pragma config EBTRB = OFF                                                  // CONFIG7H
10
11
12
#include <p18f45k20.h>
13
#include <sw_i2c.h>
14
#include <delays.h>
15
#include <stdio.h>
16
#include <sw_uart.h>
17
#include <usart.h>
18
19
20
#define SWTXD PORTC
21
#define SWTXDpin 6
22
#define TRIS_SWTXD TRISC
23
24
#define SWRXD PORTC
25
#define SWRXDpin 7
26
#define TRIS_SWRXD TRISC
27
28
#pragma code
29
void main(void)
30
{
31
32
OpenUART();
33
34
  //make BlueMod visible + settings
35
putcUART("ATS301=BlueMod+++");    //Local Device Name = BlueMod+B20
36
putcUART("ATS350=SPP_1");        //Local Service Name for SPP: SPP
37
putcUART("ATS323=9600");      //Set baud rate to 9600 bps
38
putcUART("ATS324=8");        //Use 8 data bits
39
putcUART("ATS325=1");        //One stop bit
40
putcUART("ATS326=0");        //No parity
41
putcUART("ATS316=3");        //Page scan and inquiry scan are enabled; the BlueMod+B2x is connectable and discoverable
42
43
  //Connection-Profil
44
  putcUART("ATA");        //Accept incomming call
45
  putcUART("AT&C0");        //DCD always on
46
  putcUART("ATS319=1");      //Authentication for Incoming Connections
47
48
49
putsUART("Test");
50
51
52
}
53
54
55
56
// The following delays are for use by the software UART routines
57
void DelayTXBitUART()
58
{
59
// delay for: ((((2*FOSC/(4*baud))+1) / 2) - 12 cycles
60
// = ((((2*16000000 / (4*4800)) + 1) / 2) - 12
61
// = 821 cycles @ 16mhz, 4800 baud
62
Delay10TCYx(82);
63
}
64
65
void DelayRXHalfBitUART()
66
{
67
// delay for: ((((2*FOSC/(8*baud))+1) / 2) - 9 cycles
68
// = ((((2*16000000 / (8*4800)) + 1) / 2) - 9
69
// = 408 cycles @ 16mhz, 4800 baud
70
Delay10TCYx(40);
71
}
72
73
void DelayRXBitUART()
74
{
75
// delay for: ((((2*FOSC/(4*baud))+1) / 2) - 14 cycles
76
// = ((((2*16000000 / (4*4800)) + 1) / 2) - 14
77
// = 819 cycles @ 16mhz, 4800 baud
78
Delay10TCYx(82);
79
}


Ich weiss wirklich nicht mehr weiter, das ganze ist für ein Praktikum 
und mein Betreuer kann mir leider auch nicht mehr weiter helfen.
Hoffe hier sieht jemand den Fehler =/
Vielen Dank schonmal im Voraus!!

von Dirk (Gast)


Lesenswert?

Um den Fehler einzugrenzen würde ich dir raten das BT-Modul erst einmal 
via RS232 über einen PC (z.B. via Hyperterminal) anzusteuern, 
Pegelwandler natürlich nicht vergessen. Damit kannst du überprüfen, ob 
die einzelnen Kommandosequenzen vom Modul überhaupt akzeptiert werden. 
Übrigens, müssten die einzelnen Kommandos nicht jeweils mit <CR> beendet 
werden?

von Harald (Gast)


Lesenswert?

Das sehe ich auch so. Das fehlende Enter (und evtl. auch Linefeed, siehe 
Datenblatt) pro Kommando dürfte das Hauptproblem sein.

von Manusi (Gast)


Lesenswert?

Super, danke für die schnellen Antworten!!
das <CR> hatte ich am Anfang auch drinnen, habs zum Test auch mal 
rausgenommen und dann so gelassen da es keine Änderungen gab... daran 
liegt es leider also nicht :(

von Dirk (Gast)


Lesenswert?

Bitte richte dich unbedingt nach dem Datenblatt des Moduls. Wenn dort 
ein <CR> verlangt wird, dann musst du es auch mitschicken. Bei solchen 
komplexeren Projekten ist es völlig normal, daß man am Anfang mehrere 
Fehler gleichzeitig eingebaut hat. Du kannst dann einen Fehler beheben 
und es geht immer noch nichts, daraus zu schliessen das die Änderung 
deswegen aber keinen Einfluß hat ist dann aber auch verkehrt. Ein 
planloses rumprobieren führt garantiert nicht zum Ziel.

von Andreas G. (beastyk)


Lesenswert?

Moin Leute,

ich kenn mich jetzt nicht mit dem Modul usw. aus aber sollte nicht der 
ATA Befehl der letzte in der Befehlsfolge sein?
Im Handbuch steht dazu folgender Absatz:

AT syntax: ATA
This command accepts an incoming call if automatic call acceptance is 
not set
(Register S0=0). An incoming call is always signaled with the 
unsolicited response
“RING“ or code “2“, even if automatic call acceptance is selected.

Note: Must be the last command in an AT command line.

Es gibt auch mehrere Module bei Stollman, welches ist es denn genau?

Kann man die Delay-Zeiten etwas großzügiger gestalten (ich weiß nicht ob 
man das einfach so darf, hier sind erfahrene Leute gefragt!)

Gruß
Andi

von Mutlos (Gast)


Lesenswert?

ich denke mal es handelt sich um das BlueMod B20.
Habe ähnliche Erfahrungen mit dem Modul gemacht..

von Mutlos (Gast)


Lesenswert?

übrigens:

"Note: Must be the last command in an AT command line."

bezieht sich nicht auf das ATA Kommando sondern auf das ATZ Kommando

von Mutlos (Gast)


Lesenswert?

hier mein bisheriger Erfolg, der bei mir funktioniert:
1
delay_ms(1300, clocks.cpu_f); // ~1,3s warten bis Gerät nach einschalten reagiert (Datenblatt)
2
3
usart_write_line(BLUETOOTH, "ATS301=Bluemodder\r");  // Gerätename setzen
4
usart_write_line(BLUETOOTH, "AT&W\r");  // Speichern
5
usart_write_line(BLUETOOTH, "ATZ\r");   // Konfiguration laden
6
delay_ms(400, clocks.cpu_f);         // warten
7
usart_write_line(BLUETOOTH, "ATS318=1250\r");  // Neue Pin setzen
8
usart_write_line(BLUETOOTH, "AT&W\r");
9
usart_write_line(BLUETOOTH, "ATZ\r");
10
delay_ms(400, clocks.cpu_f);
11
usart_write_line(BLUETOOTH, "ATS350=Serialport\r");  // Serialportname setzen
12
usart_write_line(BLUETOOTH, "AT&W\r");
13
usart_write_line(BLUETOOTH, "ATZ\r");

von Manusi (Gast)


Lesenswert?

Genau, es handelt sich um den BlueMod B20.

@Mutlos:
Was für einen Compiler benutzt du?? Bei mir sind die Befehle 
"usart_write_line...." gar nicht aufgeführt :S
Ich versuchs dann mal mit so einem ähnlichen Aufbau bei meinem Programm!

von Mutlos (Gast)


Lesenswert?

ist normal gcc

usart_write_line macht bei mir nichts anderes als ein putchar

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.